|
18 | 18 | - name: Checkout |
19 | 19 | uses: actions/checkout@v4 |
20 | 20 | with: |
| 21 | + fetch-depth: 0 |
21 | 22 | ref: ${{ github.event.pull_request.head.ref || github.event.ref }} |
22 | 23 |
|
23 | 24 | - name: Remove label |
@@ -29,25 +30,36 @@ jobs: |
29 | 30 | gh pr edit --repo github/codeql-action "$PR_NUMBER" \ |
30 | 31 | --remove-label "Rebuild" |
31 | 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 | +
|
32 | 38 | - name: Merge in changes from base branch |
| 39 | + id: merge |
33 | 40 | env: |
34 | 41 | BASE_BRANCH: ${{ github.event.pull_request.base.ref || 'main' }} |
35 | 42 | run: | |
36 | 43 | git fetch origin "$BASE_BRANCH" |
37 | 44 |
|
38 | 45 | # Allow merge conflicts in `lib`, since rebuilding should resolve them. |
39 | | - git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing..." |
40 | | -
|
41 | | - # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check |
42 | | - # since `node_modules/@types/semver/README.md` fails it. |
43 | | - if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then |
44 | | - echo "Merge conflicts were detected outside of the lib directory. Please resolve them manually." |
45 | | - git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true |
46 | | - exit 1 |
47 | | - fi |
| 46 | + git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing." |
| 47 | + MERGE_RESULT=$? |
48 | 48 |
|
49 | | - echo "No merge conflicts found outside the lib directory. We should be able to resolve all of" \ |
50 | | - "these by rebuilding the Action." |
| 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." |
| 62 | + fi |
51 | 63 |
|
52 | 64 | - name: Compile TypeScript |
53 | 65 | run: | |
@@ -67,13 +79,20 @@ jobs: |
67 | 79 | pip install ruamel.yaml==0.17.31 |
68 | 80 | python3 sync.py |
69 | 81 |
|
70 | | - - name: Check for changes and push |
| 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' |
71 | 92 | id: push |
72 | 93 | run: | |
73 | 94 | if [ ! -z "$(git status --porcelain)" ]; then |
74 | 95 | echo "Changes detected, committing and pushing." |
75 | | - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
76 | | - git config --global user.name "github-actions[bot]" |
77 | 96 | git add --all |
78 | 97 | # If the merge originally had conflicts, finish the merge. |
79 | 98 | # Otherwise, just commit the changes. |
@@ -92,7 +111,12 @@ jobs: |
92 | 111 | fi |
93 | 112 |
|
94 | 113 | - name: Notify about rebuild |
95 | | - if: github.event_name == 'pull_request' && steps.push.outputs.changes == 'true' |
| 114 | + if: >- |
| 115 | + github.event_name == 'pull_request' && |
| 116 | + ( |
| 117 | + steps.merge.outputs.merge-in-progress == 'true' || |
| 118 | + steps.push.outputs.changes == 'true' |
| 119 | + ) |
96 | 120 | env: |
97 | 121 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
98 | 122 | PR_NUMBER: ${{ github.event.pull_request.number }} |
|