diff --git a/.github/workflows/commit_checks.yml b/.github/workflows/commit_checks.yml index e7e44555610..da46d211017 100644 --- a/.github/workflows/commit_checks.yml +++ b/.github/workflows/commit_checks.yml @@ -1,7 +1,12 @@ name: Commit Quality +# pull_request_target gives fork PRs a token that can post the comments. That +# is safe only while this workflow never runs PR code: the checkouts take +# Tools/ci from the base branch, so never give them a ref from the PR, and pass +# PR fields (title, body, branch names) to the scripts through env, never +# inline in a run block. on: - pull_request: + pull_request_target: types: [opened, edited, synchronize, reopened] permissions: @@ -9,13 +14,14 @@ permissions: pull-requests: write issues: write +# github.ref is the base branch under pull_request_target, shared by every PR +# against it, so group by PR number. concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true env: PR_NUMBER: ${{ github.event.pull_request.number }} - IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }} jobs: pr-title: @@ -38,7 +44,6 @@ jobs: echo "exit_code=$rc" >> "$GITHUB_OUTPUT" - name: Post or clear comment - if: env.IS_FORK == 'false' env: GH_TOKEN: ${{ github.token }} run: | @@ -54,12 +59,7 @@ jobs: - name: Result if: steps.check.outputs.exit_code != '0' run: | - if [ "$IS_FORK" = "true" ]; then - # Output the entire content of the comment on the job log as a substitute for the comment. - tee -a "$GITHUB_STEP_SUMMARY" < comment.md - else - echo "::error::PR title check failed. See the PR comment for details." - fi + echo "::error::PR title check failed. See the PR comment for details." exit 1 pr-body: @@ -67,7 +67,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - if: env.IS_FORK == 'false' uses: actions/checkout@v6 with: sparse-checkout: Tools/ci @@ -92,7 +91,6 @@ jobs: echo "message=$message" >> "$GITHUB_OUTPUT" - name: Post or clear comment - if: env.IS_FORK == 'false' env: GH_TOKEN: ${{ github.token }} run: |