Skip to content

Commit c0314d6

Browse files
committed
ci: post release title statuses only for the tagpr PR head
The branch-prefix check alone let anyone with write access dispatch the title workflow from a `tagpr-from-*` branch they created and get both title statuses on any commit. The job now posts them only when the commit is the head of an open PR from that branch opened by github-actions[bot], which is how tagpr opens release PRs.
1 parent 6eead05 commit c0314d6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎.github/workflows/check-pr-title.yaml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,16 @@ jobs:
152152
# Check runs from a dispatch are not attached to the release PR, so they cannot
153153
# satisfy main's required title checks. Commit statuses on the same SHA are, so
154154
# this posts both contexts. The release PR's title comes from
155-
# .github/tagpr-template.md, so there is nothing to validate.
155+
# .github/tagpr-template.md, so there is nothing to validate; the statuses are
156+
# posted only when this SHA is the head of an open PR that tagpr opened from
157+
# this branch.
156158
release-pr-statuses:
157159
name: Release PR title statuses
158160
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
159161
runs-on: ubuntu-slim
160162
timeout-minutes: 5
161163
permissions:
164+
pull-requests: read
162165
statuses: write
163166
steps:
164167
- name: Post title check statuses
@@ -170,6 +173,13 @@ jobs:
170173
echo "::error::Only tagpr release branches get title statuses."
171174
exit 1
172175
fi
176+
release_prs="$(gh api "repos/$GITHUB_REPOSITORY/pulls" \
177+
-f state=open -f head="$GITHUB_REPOSITORY_OWNER:$REF_NAME" --method GET \
178+
--jq "[.[] | select(.head.sha == \"$GITHUB_SHA\" and .user.login == \"github-actions[bot]\")] | length")"
179+
if [ "$release_prs" -eq 0 ]; then
180+
echo "::error::${GITHUB_SHA} is not the head of an open tagpr release PR from ${REF_NAME}."
181+
exit 1
182+
fi
173183
for context in 'Validate PR title' 'Validate PR title scope'; do
174184
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
175185
-f state=success \

0 commit comments

Comments
 (0)