@@ -318,35 +318,54 @@ jobs:
318318 cat temp-output
319319 tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
320320 rm temp-output
321+ env :
322+ BRANCH_NAME : actions/${{ github.ref_name != 'main' && format('{0}/', github.ref_name) || '' }}tools-update-${{ matrix.id }}
321323 steps :
322- - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
324+ - name : Check for non-bot commits on the existing pull request
325+ id : check-pr
323326 if : github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
327+ # Updating the Action's PR force-pushes its branch, so skip the update
328+ # if someone pushed their own commits to it to avoid discarding them.
329+ env :
330+ GH_TOKEN : ${{ secrets.GH_USER_TOKEN }}
331+ run : |
332+ PR_URL=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$BRANCH_NAME" --state open \
333+ --json url,commits,isCrossRepository \
334+ --jq '[.[] | select(.isCrossRepository | not) | select(any(.commits[].authors[]; .email != "github-bot@iojs.org")) | .url] | join(" ")')
335+ if [ -n "$PR_URL" ]; then
336+ echo "::notice::Skipping update, $PR_URL has commits not authored by the bot"
337+ echo "update=false" >> "$GITHUB_OUTPUT"
338+ else
339+ echo "update=true" >> "$GITHUB_OUTPUT"
340+ fi
341+ - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
342+ if : steps.check-pr.outputs.update == 'true'
324343 with :
325344 persist-credentials : false
326345 - name : Set up Python ${{ env.PYTHON_VERSION }}
327- if : matrix.requires-python && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
346+ if : matrix.requires-python && steps.check-pr.outputs.update == 'true'
328347 uses : actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
329348 with :
330349 python-version : ${{ env.PYTHON_VERSION }}
331350 allow-prereleases : true
332351 - name : Set up Nix
333- if : matrix.id == 'nixpkgs-unstable' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
352+ if : matrix.id == 'nixpkgs-unstable' && steps.check-pr.outputs.update == 'true'
334353 uses : cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
335354 - run : ${{ matrix.run }}
336- if : github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
355+ if : steps.check-pr.outputs.update == 'true'
337356 env :
338357 GITHUB_TOKEN : ${{ secrets.GH_USER_TOKEN }}
339358 - name : Generate commit message if not set
340- if : env.COMMIT_MSG == '' && (github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id)
359+ if : env.COMMIT_MSG == '' && steps.check-pr.outputs.update == 'true'
341360 run : |
342361 echo "COMMIT_MSG=${{ matrix.subsystem }}: update ${{ matrix.id }} to $NEW_VERSION" >> "$GITHUB_ENV"
343362 - uses : peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
344- if : github.event_name == 'schedule' || inputs.id == 'all' || inputs.id == matrix.id
363+ if : steps.check-pr.outputs.update == 'true'
345364 # Creates a PR or update the Action's existing PR, or
346365 # no-op if the base branch is already up-to-date.
347366 with :
348367 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.
368+ branch : ${{ env.BRANCH_NAME }} # Custom branch *just* for this Action.
350369 delete-branch : true
351370 commit-message : ${{ env.COMMIT_MSG }}
352371 labels : ${{ matrix.label }}
0 commit comments