Skip to content

Commit bd62bf4

Browse files
committed
Finish in-progress merges
1 parent 2afb4e6 commit bd62bf4

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

.github/workflows/rebuild.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v4
2020
with:
21+
fetch-depth: 0
2122
ref: ${{ github.event.pull_request.head.ref || github.event.ref }}
2223

2324
- name: Remove label
@@ -29,25 +30,36 @@ jobs:
2930
gh pr edit --repo github/codeql-action "$PR_NUMBER" \
3031
--remove-label "Rebuild"
3132
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+
3238
- name: Merge in changes from base branch
39+
id: merge
3340
env:
3441
BASE_BRANCH: ${{ github.event.pull_request.base.ref || 'main' }}
3542
run: |
3643
git fetch origin "$BASE_BRANCH"
3744
3845
# 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=$?
4848
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
5163
5264
- name: Compile TypeScript
5365
run: |
@@ -67,13 +79,20 @@ jobs:
6779
pip install ruamel.yaml==0.17.31
6880
python3 sync.py
6981
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'
7192
id: push
7293
run: |
7394
if [ ! -z "$(git status --porcelain)" ]; then
7495
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]"
7796
git add --all
7897
# If the merge originally had conflicts, finish the merge.
7998
# Otherwise, just commit the changes.
@@ -92,7 +111,12 @@ jobs:
92111
fi
93112
94113
- 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+
)
96120
env:
97121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98122
PR_NUMBER: ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)