Files
AnyPS5/.github/workflows/progress-comment.yml
T
MarcZX10 6eab9533e5 fix(ci): check the progress comment's pull request against the run before commenting
The comment job took the pull request number from the report artifact. The report job runs tools/progress.py from the pull request's own checkout, so that code can write any number into the artifact. The job then checked only that the named pull request had the run's head commit, so a second open pull request in the base repository with the same head commit could receive the comment. The job now compares the head commit, head branch and head repository of the named pull request with the run's, with gh pr view, and skips the comment on any mismatch. It runs no repository code and does not check out the repository.
2026-11-01 07:17:17 +00:00

46 lines
1.8 KiB
YAML

name: Progress comment
on:
workflow_run:
workflows: [Progress report]
types: [completed]
permissions:
actions: read
pull-requests: write
jobs:
comment:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
name: progress-report
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RUN_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_REF: ${{ github.event.workflow_run.head_branch }}
RUN_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
run: |
pr=$(cat pr)
[[ $pr =~ ^[0-9]+$ ]] || exit 1
identity=$(gh pr view "$pr" --json headRefOid,headRefName,headRepositoryOwner,headRepository --jq '[.headRefOid, .headRefName, .headRepositoryOwner.login + "/" + .headRepository.name] | @tsv') || identity=""
[ "$identity" = "$(printf '%s\t%s\t%s' "$RUN_SHA" "$RUN_REF" "$RUN_REPO")" ] || exit 0
marker='<!-- progress-report -->'
id=$(gh api "repos/$GH_REPO/issues/$pr/comments" --paginate \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" | head -n1)
if [ -f report.md ]; then
printf '%s\n%s' "$marker" "$(cat report.md)" > body.md
if [ -n "$id" ]; then
gh api -X PATCH "repos/$GH_REPO/issues/comments/$id" -F [email protected] > /dev/null
else
gh pr comment "$pr" --body-file body.md
fi
elif [ -n "$id" ]; then
gh api -X DELETE "repos/$GH_REPO/issues/comments/$id"
fi