From ddc8e21357e9219ea1f414ae97da30691b830d7c Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 16:46:25 +0100 Subject: [PATCH 1/7] Allow running rebuild workflow on workflow dispatch --- .github/workflows/rebuild.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 97cac94fbd..459c08d339 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -9,7 +9,7 @@ jobs: rebuild: name: Rebuild Action runs-on: ubuntu-latest - if: github.event.label.name == 'Rebuild' + if: github.event.label.name == 'Rebuild' || github.event_name == 'workflow_dispatch' permissions: contents: write # needed to push rebuilt commit @@ -18,9 +18,10 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.ref }} + ref: ${{ github.event.pull_request.head.ref || github.event.ref }} - name: Remove label + if: github.event_name == 'pull_request' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} @@ -30,7 +31,7 @@ jobs: - name: Merge in changes from base branch env: - BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + BASE_BRANCH: ${{ github.event.pull_request.base.ref || 'main' }} run: | git fetch origin "$BASE_BRANCH" @@ -64,8 +65,9 @@ jobs: python3 sync.py - name: Check for changes and push + id: push env: - BRANCH: ${{ github.event.pull_request.head.ref }} + BRANCH: ${{ github.event.pull_request.head.ref || github.event.ref }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | @@ -75,8 +77,16 @@ jobs: git add --all git commit -m "Rebuild" git push origin "HEAD:$BRANCH" - echo "Pushed a commit to rebuild the Action." \ - "Please mark the PR as ready for review to trigger PR checks." | - gh pr comment --body-file - --repo github/codeql-action "$PR_NUMBER" - gh pr ready --undo --repo github/codeql-action "$PR_NUMBER" + echo "::set-output name=changes::true" fi + + - name: Notify about rebuild + if: github.event_name == 'pull_request' && steps.push.outputs.changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + echo "Pushed a commit to rebuild the Action." \ + "Please mark the PR as ready for review to trigger PR checks." | + gh pr comment --body-file - --repo github/codeql-action "$PR_NUMBER" + gh pr ready --undo --repo github/codeql-action "$PR_NUMBER" From 3425bf931d5dc2ec49cf84c665cd6d7f8f05bfd7 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:21:48 +0100 Subject: [PATCH 2/7] Use updated output API --- .github/workflows/rebuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 459c08d339..7d2379f977 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -77,7 +77,7 @@ jobs: git add --all git commit -m "Rebuild" git push origin "HEAD:$BRANCH" - echo "::set-output name=changes::true" + echo "changes=true" >> $GITHUB_OUTPUT fi - name: Notify about rebuild From 2ee230f7c4b3a1d8e74eb0390a44ac3383f43b8b Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:34:44 +0100 Subject: [PATCH 3/7] Update .github/workflows/rebuild.yml --- .github/workflows/rebuild.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 7d2379f977..431c80a25f 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -68,8 +68,6 @@ jobs: id: push env: BRANCH: ${{ github.event.pull_request.head.ref || github.event.ref }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} run: | if [ ! -z "$(git status --porcelain)" ]; then git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" From bf301d1b7719403937c1b0c1154455ab70f2ca23 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:46:04 +0100 Subject: [PATCH 4/7] Finish merge if in progress --- .github/workflows/rebuild.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 431c80a25f..e0be8719bb 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -73,7 +73,13 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add --all - git commit -m "Rebuild" + # If the merge originally had conflicts, finish the merge. + # Otherwise, just commit the changes. + if git rev-parse --verify MERGE_HEAD >/dev/null 2>&1; then + git merge --continue + else + git commit -m "Rebuild" + fi git push origin "HEAD:$BRANCH" echo "changes=true" >> $GITHUB_OUTPUT fi From 1fd38a47126f5db6b094114210551318a678b973 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:50:25 +0100 Subject: [PATCH 5/7] Improve logging --- .github/workflows/rebuild.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index e0be8719bb..003543acae 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -36,16 +36,19 @@ jobs: git fetch origin "$BASE_BRANCH" # Allow merge conflicts in `lib`, since rebuilding should resolve them. - git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected" + git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing..." # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check # since `node_modules/@types/semver/README.md` fails it. if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then - echo "Merge conflicts detected outside of lib/ directory. Please resolve them manually." + echo "Merge conflicts were detected outside of the lib directory. Please resolve them manually." git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true exit 1 fi + echo "No merge conflicts found outside the lib directory. We should be able to resolve all of" \ + "these by rebuilding the Action." + - name: Compile TypeScript run: | npm install @@ -70,18 +73,24 @@ jobs: BRANCH: ${{ github.event.pull_request.head.ref || github.event.ref }} run: | if [ ! -z "$(git status --porcelain)" ]; then + echo "Changes detected, pushing them to branch $BRANCH" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add --all # If the merge originally had conflicts, finish the merge. # Otherwise, just commit the changes. if git rev-parse --verify MERGE_HEAD >/dev/null 2>&1; then + echo "In progress merge detected, finishing it up." git merge --continue else + echo "No in-progress merge detected, committing changes." git commit -m "Rebuild" fi + echo "Pushing changes to branch $BRANCH" git push origin "HEAD:$BRANCH" echo "changes=true" >> $GITHUB_OUTPUT + else + echo "No changes detected, nothing to commit." fi - name: Notify about rebuild From 2afb4e6f3c84ec0534284f2b47ae8206dcb401bf Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:51:55 +0100 Subject: [PATCH 6/7] Avoid specifying branch unnecessarily --- .github/workflows/rebuild.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 003543acae..3426b4a928 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -69,11 +69,9 @@ jobs: - name: Check for changes and push id: push - env: - BRANCH: ${{ github.event.pull_request.head.ref || github.event.ref }} run: | if [ ! -z "$(git status --porcelain)" ]; then - echo "Changes detected, pushing them to branch $BRANCH" + echo "Changes detected, committing and pushing." git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add --all @@ -86,8 +84,8 @@ jobs: echo "No in-progress merge detected, committing changes." git commit -m "Rebuild" fi - echo "Pushing changes to branch $BRANCH" - git push origin "HEAD:$BRANCH" + echo "Pushing changes" + git push echo "changes=true" >> $GITHUB_OUTPUT else echo "No changes detected, nothing to commit." From bd62bf449cd8695f818546752cc8157693e1716c Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 7 Aug 2025 17:59:32 +0100 Subject: [PATCH 7/7] Finish in-progress merges --- .github/workflows/rebuild.yml | 54 +++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 3426b4a928..cfdd21d713 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -18,6 +18,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: + fetch-depth: 0 ref: ${{ github.event.pull_request.head.ref || github.event.ref }} - name: Remove label @@ -29,25 +30,36 @@ jobs: gh pr edit --repo github/codeql-action "$PR_NUMBER" \ --remove-label "Rebuild" + - name: Configure git + run: | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + - name: Merge in changes from base branch + id: merge env: BASE_BRANCH: ${{ github.event.pull_request.base.ref || 'main' }} run: | git fetch origin "$BASE_BRANCH" # Allow merge conflicts in `lib`, since rebuilding should resolve them. - git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing..." - - # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check - # since `node_modules/@types/semver/README.md` fails it. - if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then - echo "Merge conflicts were detected outside of the lib directory. Please resolve them manually." - git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true - exit 1 - fi + git merge "origin/$BASE_BRANCH" || echo "Merge conflicts detected, continuing." + MERGE_RESULT=$? - echo "No merge conflicts found outside the lib directory. We should be able to resolve all of" \ - "these by rebuilding the Action." + if [ "$MERGE_RESULT" -ne 0 ]; then + echo "merge-in-progress=true" >> $GITHUB_OUTPUT + + # Check for merge conflicts outside of `lib`. Disable git diff's trailing whitespace check + # since `node_modules/@types/semver/README.md` fails it. + if git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/'; then + echo "Merge conflicts were detected outside of the lib directory. Please resolve them manually." + git -c core.whitespace=-trailing-space diff --check | grep --invert-match '^lib/' || true + exit 1 + fi + + echo "No merge conflicts found outside the lib directory. We should be able to resolve all of" \ + "these by rebuilding the Action." + fi - name: Compile TypeScript run: | @@ -67,13 +79,20 @@ jobs: pip install ruamel.yaml==0.17.31 python3 sync.py - - name: Check for changes and push + - name: "Merge in progress: Finish merge and push" + if: steps.merge.outputs.merge-in-progress == 'true' + run: | + echo "Finishing merge and pushing changes." + git add --all + git commit --no-edit + git push + + - name: "No merge in progress: Check for changes and push" + if: steps.merge.outputs.merge-in-progress != 'true' id: push run: | if [ ! -z "$(git status --porcelain)" ]; then echo "Changes detected, committing and pushing." - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" git add --all # If the merge originally had conflicts, finish the merge. # Otherwise, just commit the changes. @@ -92,7 +111,12 @@ jobs: fi - name: Notify about rebuild - if: github.event_name == 'pull_request' && steps.push.outputs.changes == 'true' + if: >- + github.event_name == 'pull_request' && + ( + steps.merge.outputs.merge-in-progress == 'true' || + steps.push.outputs.changes == 'true' + ) env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }}