99 rebuild :
1010 name : Rebuild Action
1111 runs-on : ubuntu-latest
12- if : github.event.label.name == 'Rebuild'
12+ if : github.event.label.name == 'Rebuild' || github.event_name == 'workflow_dispatch'
1313
1414 permissions :
1515 contents : write # needed to push rebuilt commit
@@ -18,31 +18,47 @@ jobs:
1818 - name : Checkout
1919 uses : actions/checkout@v4
2020 with :
21- ref : ${{ github.event.pull_request.head.ref }}
21+ fetch-depth : 0
22+ ref : ${{ github.event.pull_request.head.ref || github.event.ref }}
2223
2324 - name : Remove label
25+ if : github.event_name == 'pull_request'
2426 env :
2527 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2628 PR_NUMBER : ${{ github.event.pull_request.number }}
2729 run : |
2830 gh pr edit --repo github/codeql-action "$PR_NUMBER" \
2931 --remove-label "Rebuild"
3032
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+
3138 - name : Merge in changes from base branch
39+ id : merge
3240 env :
33- BASE_BRANCH : ${{ github.event.pull_request.base.ref }}
41+ BASE_BRANCH : ${{ github.event.pull_request.base.ref || 'main' }}
3442 run : |
3543 git fetch origin "$BASE_BRANCH"
3644
3745 # 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."
4662 fi
4763
4864 - name : Compile TypeScript
@@ -63,20 +79,49 @@ jobs:
6379 pip install ruamel.yaml==0.17.31
6480 python3 sync.py
6581
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
7193 run : |
7294 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."
7596 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."
82111 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"
0 commit comments