ci(commit_checks): post title and description comments on fork PRs

A fork PR gets a read-only token under pull_request, so the PR title and
PR description comments were skipped for forks. A fork contributor with
a bad title got a red check and the reason only in the job summary that
#29816 added as a workaround.

Run the workflow on pull_request_target, like the labeler, so the token
can post the comments on fork PRs too. The jobs only read the title, the
body and the base branch from the event and run Tools/ci from the base
branch, never code from the PR. Group the concurrency by PR number,
because github.ref is the base branch under this trigger and PRs against
the same branch would cancel each other. Drop the fork-only job summary,
which the comment replaces.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche committed 2026-11-16 10:39:20 -08:00
1 parent 40fee1673f
commit f1b15087f0
1 file changed
+10 -12
+10 -12
View File
@@ -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: |