Skip to content

Commit 5276445

Browse files
marco-ippolitoaduh95
authored andcommitted
tools: skip dependency update if PR has non-bot commits
When the tools-deps-update workflow finds a new version of a dependency, peter-evans/create-pull-request force-pushes the Action's branch, discarding any commits a collaborator pushed to the existing PR to fix the update. On scheduled runs and on manual runs for all dependencies, check whether the open PR for the Action's branch contains commits not authored by the bot before running the updater, and if so skip the update for that dependency instead of overwriting them. A manual run for a single dependency still updates the PR, as it is assumed to be an intentional override. Signed-off-by: Marco Ippolito <marcoippolito54@gmail.com> Assisted-by: claude:opus-5.5 PR-URL: #66503 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 7f9f5d5 commit 5276445

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

‎.github/workflows/tools.yml‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ permissions:
5555

5656
jobs:
5757
tools-deps-update:
58+
permissions:
59+
contents: read
60+
pull-requests: read
5861
if: github.repository == 'nodejs/node' || github.event_name == 'workflow_dispatch'
5962
# cannot use ubuntu-slim here because some update scripts require Docker
6063
runs-on: ubuntu-latest
@@ -327,35 +330,53 @@ jobs:
327330
cat temp-output
328331
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
329332
rm temp-output
333+
env:
334+
BRANCH_NAME: actions/${{ github.ref_name != 'main' && format('{0}/', github.ref_name) || '' }}tools-update-${{ matrix.id }}
330335
steps:
336+
- name: Check for non-bot commits on the existing pull request
337+
id: check-pr
338+
# Updating the Action's PR force-pushes its branch, so skip the update
339+
# if someone pushed their own commits to it to avoid discarding them.
340+
# When 'inputs.id == matrix.id', non-bot commits are being overwritten
341+
if: github.event_name == 'schedule' || inputs.id == 'all'
342+
env:
343+
GH_TOKEN: ${{ github.token }}
344+
run: |
345+
PR_URL=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH_NAME" --state open \
346+
--json url,commits,isCrossRepository \
347+
--jq '[.[] | select(.isCrossRepository | not) | select(any(.commits[].authors[]; .email != "github-bot@iojs.org")) | .url] | join(" ")')
348+
if [ -n "$PR_URL" ]; then
349+
echo "::notice::Skipping update, $PR_URL has commits not authored by the bot"
350+
echo "hasNonBotCommits=true" >> "$GITHUB_OUTPUT"
351+
fi
331352
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
332-
if: github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
353+
if: (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
333354
with:
334355
persist-credentials: false
335356
- name: Set up Python ${{ env.PYTHON_VERSION }}
336-
if: matrix.requires-python && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
357+
if: matrix.requires-python && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
337358
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
338359
with:
339360
python-version: ${{ env.PYTHON_VERSION }}
340361
allow-prereleases: true
341362
- name: Set up Nix
342-
if: matrix.id == 'nixpkgs-unstable' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
363+
if: matrix.id == 'nixpkgs-unstable' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
343364
uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
344365
- run: ${{ matrix.run }}
345-
if: github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
366+
if: (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
346367
env:
347368
GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}
348369
- name: Generate commit message if not set
349-
if: env.COMMIT_MSG == '' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
370+
if: env.COMMIT_MSG == '' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
350371
run: |
351372
echo "COMMIT_MSG=${{ matrix.subsystem }}: update ${{ matrix.id }} to $NEW_VERSION" >> "$GITHUB_ENV"
352373
- uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
353-
if: github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
374+
if: (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id) && steps.check-pr.outputs.hasNonBotCommits != 'true'
354375
# Creates a PR or update the Action's existing PR, or
355376
# no-op if the base branch is already up-to-date.
356377
with:
357378
token: ${{ secrets.GH_USER_TOKEN }}
358-
branch: actions/${{ github.ref_name != 'main' && format('{0}/', github.ref_name) || '' }}tools-update-${{ matrix.id }} # Custom branch *just* for this Action.
379+
branch: ${{ env.BRANCH_NAME }} # Custom branch *just* for this Action.
359380
delete-branch: true
360381
commit-message: ${{ env.COMMIT_MSG }}
361382
labels: ${{ matrix.label }}

0 commit comments

Comments
 (0)