Skip to content

Commit f37531c

Browse files
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
1 parent e2d5522 commit f37531c

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
@@ -54,6 +54,9 @@ permissions:
5454

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

0 commit comments

Comments
 (0)