|
9 | 9 | rebuild: |
10 | 10 | name: Rebuild Action |
11 | 11 | runs-on: ubuntu-latest |
12 | | - if: github.event.label.name == 'Rebuild' |
| 12 | + if: github.event.label.name == 'Rebuild' || github.event_name == 'workflow_dispatch' |
13 | 13 |
|
14 | 14 | permissions: |
15 | 15 | contents: write # needed to push rebuilt commit |
@@ -18,31 +18,47 @@ jobs: |
18 | 18 | - name: Checkout |
19 | 19 | uses: actions/checkout@v4 |
20 | 20 | with: |
21 | | - ref: ${{ github.event.pull_request.head.ref }} |
| 21 | + fetch-depth: 0 |
| 22 | + ref: ${{ github.event.pull_request.head.ref || github.event.ref }} |
22 | 23 |
|
23 | 24 | - name: Remove label |
| 25 | + if: github.event_name == 'pull_request' |
24 | 26 | env: |
25 | 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
26 | 28 | PR_NUMBER: ${{ github.event.pull_request.number }} |
27 | 29 | run: | |
28 | 30 | gh pr edit --repo github/codeql-action "$PR_NUMBER" \ |
29 | 31 | --remove-label "Rebuild" |
30 | 32 |
|
| 33 | + - name: Configure git |
| 34 | + run: | |
| 35 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 36 | + git config --global user.name "github-actions[bot]" |
| 37 | +
|
31 | 38 | - name: Merge in changes from base branch |
| 39 | + id: merge |
32 | 40 | env: |
33 | | - BASE_BRANCH: ${{ github.event.pull_request.base.ref }} |
| 41 | + BASE_BRANCH: ${{ github.event.pull_request.base.ref || 'main' }} |
34 | 42 | run: | |
35 | 43 | git fetch origin "$BASE_BRANCH" |
36 | 44 |
|
37 | 45 | # Allow merge conflicts in `lib`, since rebuilding should resolve them. |
38 | | - git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected" |
39 | | -
|
40 | | - # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check |
41 | | - # since `node_modules/@types/semver/README.md` fails it. |
42 | | - if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then |
43 | | - echo "Merge conflicts detected outside of lib/ directory. Please resolve them manually." |
44 | | - git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true |
45 | | - exit 1 |
| 46 | + git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing." |
| 47 | + MERGE_RESULT=$? |
| 48 | +
|
| 49 | + if [ "$MERGE_RESULT" -ne 0 ]; then |
| 50 | + echo "merge-in-progress=true" >> $GITHUB_OUTPUT |
| 51 | +
|
| 52 | + # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check |
| 53 | + # since `node_modules/@types/semver/README.md` fails it. |
| 54 | + if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then |
| 55 | + echo "Merge conflicts were detected outside of the lib directory. Please resolve them manually." |
| 56 | + git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "No merge conflicts found outside the lib directory. We should be able to resolve all of" \ |
| 61 | + "these by rebuilding the Action." |
46 | 62 | fi |
47 | 63 |
|
48 | 64 | - name: Compile TypeScript |
@@ -63,20 +79,49 @@ jobs: |
63 | 79 | pip install ruamel.yaml==0.17.31 |
64 | 80 | python3 sync.py |
65 | 81 |
|
66 | | - - name: Check for changes and push |
67 | | - env: |
68 | | - BRANCH: ${{ github.event.pull_request.head.ref }} |
69 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
70 | | - PR_NUMBER: ${{ github.event.pull_request.number }} |
| 82 | + - name: "Merge in progress: Finish merge and push" |
| 83 | + if: steps.merge.outputs.merge-in-progress == 'true' |
| 84 | + run: | |
| 85 | + echo "Finishing merge and pushing changes." |
| 86 | + git add --all |
| 87 | + git commit --no-edit |
| 88 | + git push |
| 89 | +
|
| 90 | + - name: "No merge in progress: Check for changes and push" |
| 91 | + if: steps.merge.outputs.merge-in-progress != 'true' |
| 92 | + id: push |
71 | 93 | run: | |
72 | 94 | if [ ! -z "$(git status --porcelain)" ]; then |
73 | | - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
74 | | - git config --global user.name "github-actions[bot]" |
| 95 | + echo "Changes detected, committing and pushing." |
75 | 96 | git add --all |
76 | | - git commit -m "Rebuild" |
77 | | - git push origin "HEAD:$BRANCH" |
78 | | - echo "Pushed a commit to rebuild the Action." \ |
79 | | - "Please mark the PR as ready for review to trigger PR checks." | |
80 | | - gh pr comment --body-file - --repo github/codeql-action "$PR_NUMBER" |
81 | | - gh pr ready --undo --repo github/codeql-action "$PR_NUMBER" |
| 97 | + # If the merge originally had conflicts, finish the merge. |
| 98 | + # Otherwise, just commit the changes. |
| 99 | + if git rev-parse --verify MERGE_HEAD >/dev/null 2>&1; then |
| 100 | + echo "In progress merge detected, finishing it up." |
| 101 | + git merge --continue |
| 102 | + else |
| 103 | + echo "No in-progress merge detected, committing changes." |
| 104 | + git commit -m "Rebuild" |
| 105 | + fi |
| 106 | + echo "Pushing changes" |
| 107 | + git push |
| 108 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 109 | + else |
| 110 | + echo "No changes detected, nothing to commit." |
82 | 111 | fi |
| 112 | +
|
| 113 | + - name: Notify about rebuild |
| 114 | + if: >- |
| 115 | + github.event_name == 'pull_request' && |
| 116 | + ( |
| 117 | + steps.merge.outputs.merge-in-progress == 'true' || |
| 118 | + steps.push.outputs.changes == 'true' |
| 119 | + ) |
| 120 | + env: |
| 121 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 123 | + run: | |
| 124 | + echo "Pushed a commit to rebuild the Action." \ |
| 125 | + "Please mark the PR as ready for review to trigger PR checks." | |
| 126 | + gh pr comment --body-file - --repo github/codeql-action "$PR_NUMBER" |
| 127 | + gh pr ready --undo --repo github/codeql-action "$PR_NUMBER" |