Skip to content

Commit 90864c0

Browse files
authored
Merge pull request #8 from dsp-testing/henrymercer/handle-merge-conflicts-in-releases
Henrymercer/handle merge conflicts in releases
2 parents 7a12645 + 074853a commit 90864c0

File tree

8 files changed

+69
-31
lines changed

8 files changed

+69
-31
lines changed

.github/update-release-branch.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
ORIGIN = 'origin'
2424

2525
# Runs git with the given args and returns the stdout.
26-
# Raises an error if git does not exit successfully.
27-
def run_git(*args):
26+
# Raises an error if git does not exit successfully (unless passed
27+
# allow_non_zero_exit_code=True).
28+
def run_git(*args, allow_non_zero_exit_code=False):
2829
cmd = ['git', *args]
2930
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
30-
if (p.returncode != 0):
31+
if not allow_non_zero_exit_code and p.returncode != 0:
3132
raise Exception('Call to ' + ' '.join(cmd) + ' exited with code ' + str(p.returncode) + ' stderr:' + p.stderr.decode('ascii'))
3233
return p.stdout.decode('ascii')
3334

@@ -36,7 +37,9 @@ def branch_exists_on_remote(branch_name):
3637
return run_git('ls-remote', '--heads', ORIGIN, branch_name).strip() != ''
3738

3839
# Opens a PR from the given branch to the target branch
39-
def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_branch, target_branch, conductor, is_v2_release, labels):
40+
def open_pr(
41+
repo, all_commits, source_branch_short_sha, new_branch_name, source_branch, target_branch,
42+
conductor, is_v2_release, labels, conflicted_files):
4043
# Sort the commits into the pull requests that introduced them,
4144
# and any commits that don't have a pull request
4245
pull_requests = []
@@ -81,6 +84,12 @@ def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_
8184

8285
body.append('')
8386
body.append('Please review the following:')
87+
if len(conflicted_files) > 0:
88+
body.append(' - [ ] You have added commits to this branch that resolve the merge conflicts ' +
89+
'in the following files:')
90+
body.extend([f' - [ ] `{file}`' for file in conflicted_files])
91+
body.append(' - [ ] Another maintainer has reviewed the additional commits you added to this ' +
92+
'branch to resolve the merge conflicts.')
8493
body.append(' - [ ] The CHANGELOG displays the correct version and date.')
8594
body.append(' - [ ] The CHANGELOG includes all relevant, user-facing changes since the last release.')
8695
body.append(' - [ ] There are no unexpected commits being merged into the ' + target_branch + ' branch.')
@@ -246,6 +255,11 @@ def main():
246255
# Create the new branch and push it to the remote
247256
print('Creating branch ' + new_branch_name)
248257

258+
# The process of creating the v1 release can run into merge conflicts. We commit the unresolved
259+
# conflicts so a maintainer can easily resolve them (vs erroring and requiring maintainers to
260+
# reconstruct the release manually)
261+
conflicted_files = []
262+
249263
if args.mode == V1_MODE:
250264
# If we're performing a backport, start from the v1 branch
251265
print(f'Creating {new_branch_name} from the {ORIGIN}/v1 branch')
@@ -274,7 +288,12 @@ def main():
274288
print(' Nothing to revert.')
275289

276290
print(f'Merging {ORIGIN}/{source_branch} into the release prep branch')
277-
run_git('merge', f'{ORIGIN}/{source_branch}', '--no-edit')
291+
# Commit any conflicts (see the comment for `conflicted_files`)
292+
run_git('merge', f'{ORIGIN}/{source_branch}', allow_non_zero_exit_code=True)
293+
conflicted_files = run_git('diff', '--name-only', '--diff-filter', 'U').splitlines()
294+
if len(conflicted_files) > 0:
295+
run_git('add', '.')
296+
run_git('commit', '--no-edit')
278297

279298
# Migrate the package version number from a v2 version number to a v1 version number
280299
print(f'Setting version number to {version}')
@@ -317,6 +336,7 @@ def main():
317336
conductor=args.conductor,
318337
is_v2_release=args.mode == V2_MODE,
319338
labels=['Update dependencies'] if args.mode == V1_MODE else [],
339+
conflicted_files=conflicted_files
320340
)
321341

322342
if __name__ == '__main__':
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Checks for any conflict markers created by git. This check is primarily intended to validate that
2+
# any merge conflicts in the v2 -> v1 backport PR are fixed before the PR is merged.
3+
name: Check for conflicts
4+
5+
on:
6+
pull_request:
7+
branches: [main, v1, v2]
8+
# Run checks on reopened draft PRs to support triggering PR checks on draft PRs that were opened
9+
# by other workflows.
10+
types: [opened, synchronize, reopened, ready_for_review]
11+
12+
jobs:
13+
check-for-conflicts:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Check for conflicts
19+
run: |
20+
# Use `|| true` since grep returns exit code 1 if there are no matches, and we don't want
21+
# this to fail the workflow.
22+
FILES_WITH_CONFLICTS=$(grep --extended-regexp --ignore-case --line-number --recursive \
23+
'^(<<<<<<<|>>>>>>>)' . || true)
24+
if [[ "${FILES_WITH_CONFLICTS}" ]]; then
25+
echo "Fail: Found merge conflict markers in the following files:"
26+
echo ""
27+
echo "${FILES_WITH_CONFLICTS}"
28+
exit 1
29+
else
30+
echo "Success: Found no merge conflict markers."
31+
fi

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [UNRELEASED]
44

55
- Add `working-directory` input to the `autobuild` action. [#1024](https://github.com/github/codeql-action/pull/1024)
6+
- The `analyze` and `upload-sarif` actions will now wait up to 2 minutes for processing to complete after they have uploaded the results so they can report any processing errors that occurred. This behavior can be disabled by setting the `wait-for-processing` action input to `"false"`. [#1007](https://github.com/github/codeql-action/pull/1007)
67

78
## 2.1.8 - 08 Apr 2022
89

analyze/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inputs:
6161
wait-for-processing:
6262
description: If true, the Action will wait for the uploaded SARIF to be processed before completing.
6363
required: true
64-
default: "false"
64+
default: "true"
6565
token:
6666
default: ${{ github.token }}
6767
matrix:

lib/upload-lib.js

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,23 +485,17 @@ export async function waitForProcessing(
485485
logger.info(`Analysis upload status is ${status}.`);
486486
if (status === "complete") {
487487
break;
488+
} else if (status === "pending") {
489+
logger.debug("Analysis processing is still pending...");
488490
} else if (status === "failed") {
489491
throw new Error(
490492
`Code Scanning could not process the submitted SARIF file:\n${response.data.errors}`
491493
);
492494
}
493495
} catch (e) {
494-
if (util.isHTTPError(e)) {
495-
switch (e.status) {
496-
case 404:
497-
logger.debug("Analysis is not found yet...");
498-
break; // Note this breaks from the case statement, not the outer loop.
499-
default:
500-
throw e;
501-
}
502-
} else {
503-
throw e;
504-
}
496+
logger.warning(
497+
`An error occurred checking the status of the delivery. ${e} It should still be processed in the background, but errors that occur during processing may not be reported.`
498+
);
505499
}
506500
await util.delay(STATUS_CHECK_FREQUENCY_MILLISECONDS);
507501
}

upload-sarif/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ inputs:
2929
wait-for-processing:
3030
description: If true, the Action will wait for the uploaded SARIF to be processed before completing.
3131
required: true
32-
default: "false"
32+
default: "true"
3333
outputs:
3434
sarif-id:
3535
description: The ID of the uploaded SARIF file.

0 commit comments

Comments
 (0)