Merge branch 'main' into remove-uploadFromActions-params

This commit is contained in:
Sam Partington 2021-02-02 11:34:02 +00:00 committed by GitHub
commit 10a2f1b1aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 84 deletions

View file

@ -35,7 +35,7 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):
commits_without_pull_requests = []
for commit in all_commits:
pr = get_pr_for_commit(repo, commit)
if pr is None:
commits_without_pull_requests.append(commit)
elif not any(p for p in pull_requests if p.number == pr.number):
@ -47,7 +47,7 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):
# Sort PRs and commits by age
pull_requests = sorted(pull_requests, key=lambda pr: pr.number)
commits_without_pull_requests = sorted(commits_without_pull_requests, key=lambda c: c.commit.author.date)
# Start constructing the body text
body = 'Merging ' + short_main_sha + ' into ' + LATEST_RELEASE_BRANCH
@ -62,7 +62,7 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):
body += '\n- #' + str(pr.number)
body += ' - ' + pr.title
body += ' (@' + merger + ')'
# List all commits not part of a PR
if len(commits_without_pull_requests) > 0:
body += '\n\nContains the following commits not from a pull request:'
@ -86,7 +86,7 @@ def get_conductor(repo, pull_requests, other_commits):
# If there are any PRs then use whoever merged the last one
if len(pull_requests) > 0:
return get_merger_of_pr(repo, pull_requests[-1])
# Otherwise take the author of the latest commit
return other_commits[-1].author.login
@ -95,7 +95,7 @@ def get_conductor(repo, pull_requests, other_commits):
# This will not include any commits that exist on the release branch
# that aren't on main.
def get_commit_difference(repo):
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '...' + MAIN_BRANCH).strip().split('\n')
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '..' + MAIN_BRANCH).strip().split('\n')
# Convert to full-fledged commit objects
commits = [repo.get_commit(c) for c in commits]
@ -119,7 +119,7 @@ def get_truncated_commit_message(commit):
# Returns the PR object, or None if no PR could be found.
def get_pr_for_commit(repo, commit):
prs = commit.get_pulls()
if prs.totalCount > 0:
# In the case that there are multiple PRs, return the earliest one
prs = list(prs)
@ -165,7 +165,7 @@ def main():
if branch_exists_on_remote(new_branch_name):
print('Branch ' + new_branch_name + ' already exists. Nothing to do.')
return
# Create the new branch and push it to the remote
print('Creating branch ' + new_branch_name)
run_git('checkout', '-b', new_branch_name, MAIN_BRANCH)

35
lib/actions-util.js generated
View file

@ -141,12 +141,6 @@ function branchesToArray(branches) {
}
return "**";
}
var MissingTriggers;
(function (MissingTriggers) {
MissingTriggers[MissingTriggers["None"] = 0] = "None";
MissingTriggers[MissingTriggers["Push"] = 1] = "Push";
MissingTriggers[MissingTriggers["PullRequest"] = 2] = "PullRequest";
})(MissingTriggers || (MissingTriggers = {}));
function toCodedErrors(errors) {
return Object.entries(errors).reduce((acc, [key, value]) => {
acc[key] = { message: value, code: key };
@ -157,8 +151,6 @@ function toCodedErrors(errors) {
// message to add as a warning annotation to the run
exports.WorkflowErrors = toCodedErrors({
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingHooks: `Please specify on.push and on.pull_request hooks so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingPullRequestHook: `Please specify an on.pull_request hook so that Code Scanning is explicitly run against pull requests. This will be required to see results on pull requests from January 31 2021.`,
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
@ -185,27 +177,27 @@ function getWorkflowErrors(doc) {
}
}
}
let missing = MissingTriggers.None;
let missingPush = false;
if (doc.on === undefined) {
// this is not a valid config
}
else if (typeof doc.on === "string") {
if (doc.on === "pull_request") {
missing = MissingTriggers.Push;
missingPush = true;
}
}
else if (Array.isArray(doc.on)) {
const hasPush = doc.on.includes("push");
const hasPullRequest = doc.on.includes("pull_request");
if (hasPullRequest && !hasPush) {
missing = missing | MissingTriggers.Push;
missingPush = true;
}
}
else if (isObject(doc.on)) {
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
const hasPullRequest = Object.prototype.hasOwnProperty.call(doc.on, "pull_request");
if (!hasPush && hasPullRequest) {
missing = missing | MissingTriggers.Push;
missingPush = true;
}
if (hasPush && hasPullRequest) {
const paths = (_e = doc.on.push) === null || _e === void 0 ? void 0 : _e.paths;
@ -243,21 +235,8 @@ function getWorkflowErrors(doc) {
}
}
}
else {
// on is not a known type
// this workflow is likely malformed
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
}
switch (missing) {
case MissingTriggers.PullRequest | MissingTriggers.Push:
errors.push(exports.WorkflowErrors.MissingHooks);
break;
case MissingTriggers.PullRequest:
errors.push(exports.WorkflowErrors.MissingPullRequestHook);
break;
case MissingTriggers.Push:
errors.push(exports.WorkflowErrors.MissingPushHook);
break;
if (missingPush) {
errors.push(exports.WorkflowErrors.MissingPushHook);
}
return errors;
}
@ -287,7 +266,7 @@ async function validateWorkflow() {
}
core.warning(message);
}
return `warning: ${formatWorkflowCause(workflowErrors)}`;
return formatWorkflowCause(workflowErrors);
}
exports.validateWorkflow = validateWorkflow;
function formatWorkflowErrors(errors) {

File diff suppressed because one or more lines are too long

View file

@ -167,39 +167,39 @@ ava_1.default("getWorkflowErrors() for a range of malformed workflows", (t) => {
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: 1,
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: [1],
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { 1: 1 },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { test: 1 },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { test: [1] },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { test: { steps: 1 } },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: 1,
jobs: { test: [undefined] },
}), [actionsutil.WorkflowErrors.MissingHooks]));
}), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors(1), []));
t.deepEqual(...errorCodes(actionsutil.getWorkflowErrors({
on: {
@ -261,6 +261,10 @@ ava_1.default("formatWorkflowErrors() when there are multiple errors", (t) => {
]);
t.true(message.startsWith("2 issues were detected with this workflow:"));
});
ava_1.default("formatWorkflowCause() with no errors", (t) => {
const message = actionsutil.formatWorkflowCause([]);
t.deepEqual(message, undefined);
});
ava_1.default("formatWorkflowCause()", (t) => {
const message = actionsutil.formatWorkflowCause([
actionsutil.WorkflowErrors.CheckoutWrongHead,

File diff suppressed because one or more lines are too long

View file

@ -31,7 +31,7 @@ python3 -m pip install --user pipenv
if command -v python2 &> /dev/null; then
# Setup Python 2 dependency installation tools.
# The Ubuntu 20.04 GHA environment does not come with a Python 2 pip
curl --location --fail https://bootstrap.pypa.io/get-pip.py | python2
curl --location --fail https://bootstrap.pypa.io/2.7/get-pip.py | python2
python2 -m pip install --user --upgrade pip setuptools wheel

View file

@ -232,7 +232,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
actionsutil.getWorkflowErrors({
on: 1,
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -242,7 +242,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: 1,
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -252,7 +252,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: [1],
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -262,7 +262,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { 1: 1 },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -272,7 +272,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { test: 1 },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -282,7 +282,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { test: [1] },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -292,7 +292,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { test: { steps: 1 } },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -302,7 +302,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -312,7 +312,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
on: 1,
jobs: { test: [undefined] },
} as any),
[actionsutil.WorkflowErrors.MissingHooks]
[]
)
);
@ -403,6 +403,12 @@ test("formatWorkflowErrors() when there are multiple errors", (t) => {
t.true(message.startsWith("2 issues were detected with this workflow:"));
});
test("formatWorkflowCause() with no errors", (t) => {
const message = actionsutil.formatWorkflowCause([]);
t.deepEqual(message, undefined);
});
test("formatWorkflowCause()", (t) => {
const message = actionsutil.formatWorkflowCause([
actionsutil.WorkflowErrors.CheckoutWrongHead,

View file

@ -177,17 +177,11 @@ function branchesToArray(branches?: string | null | string[]): string[] | "**" {
}
return "**";
}
enum MissingTriggers {
None = 0,
Push = 1,
PullRequest = 2,
}
export interface CodedError {
message: string;
code: string;
}
function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
return Object.entries(errors).reduce((acc, [key, value]) => {
acc[key] = { message: value, code: key };
@ -199,8 +193,6 @@ function toCodedErrors<T>(errors: T): Record<keyof T, CodedError> {
// message to add as a warning annotation to the run
export const WorkflowErrors = toCodedErrors({
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingHooks: `Please specify on.push and on.pull_request hooks so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingPullRequestHook: `Please specify an on.pull_request hook so that Code Scanning is explicitly run against pull requests. This will be required to see results on pull requests from January 31 2021.`,
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
@ -232,19 +224,19 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
}
}
let missing = MissingTriggers.None;
let missingPush = false;
if (doc.on === undefined) {
// this is not a valid config
} else if (typeof doc.on === "string") {
if (doc.on === "pull_request") {
missing = MissingTriggers.Push;
missingPush = true;
}
} else if (Array.isArray(doc.on)) {
const hasPush = doc.on.includes("push");
const hasPullRequest = doc.on.includes("pull_request");
if (hasPullRequest && !hasPush) {
missing = missing | MissingTriggers.Push;
missingPush = true;
}
} else if (isObject(doc.on)) {
const hasPush = Object.prototype.hasOwnProperty.call(doc.on, "push");
@ -254,7 +246,7 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
);
if (!hasPush && hasPullRequest) {
missing = missing | MissingTriggers.Push;
missingPush = true;
}
if (hasPush && hasPullRequest) {
const paths = doc.on.push?.paths;
@ -295,22 +287,10 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
}
}
}
} else {
// on is not a known type
// this workflow is likely malformed
missing = MissingTriggers.Push | MissingTriggers.PullRequest;
}
switch (missing) {
case MissingTriggers.PullRequest | MissingTriggers.Push:
errors.push(WorkflowErrors.MissingHooks);
break;
case MissingTriggers.PullRequest:
errors.push(WorkflowErrors.MissingPullRequestHook);
break;
case MissingTriggers.Push:
errors.push(WorkflowErrors.MissingPushHook);
break;
if (missingPush) {
errors.push(WorkflowErrors.MissingPushHook);
}
return errors;
@ -340,7 +320,7 @@ export async function validateWorkflow(): Promise<undefined | string> {
core.warning(message);
}
return `warning: ${formatWorkflowCause(workflowErrors)}`;
return formatWorkflowCause(workflowErrors);
}
export function formatWorkflowErrors(errors: CodedError[]): string {