Skip to content

Commit fc650ef

Browse files
skyamgarpclaude
andcommitted
Update community PR test workflow with final CI approach
- Push rebased code to community-pr-test-<N> branch and trigger ci.yml via workflow_dispatch so module_ci and module_acceptance run against the test branch, not the fork or main - Split permission check into its own job with authorized output - Remove ok-to-test label and tag author on rebase conflicts - Replace workflow_run-based failure notification with direct comment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 537597b commit fc650ef

1 file changed

Lines changed: 38 additions & 25 deletions

File tree

.github/workflows/community_pr_test.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,37 @@ permissions:
1717
issues: write
1818

1919
jobs:
20-
create-test-pr:
20+
check-permission:
2121
if: |
2222
github.event_name == 'pull_request_target' &&
2323
contains(github.event.pull_request.labels.*.name, 'ok-to-test') &&
2424
github.event.pull_request.head.repo.full_name != github.repository
2525
runs-on: ubuntu-latest
26+
outputs:
27+
authorized: ${{ steps.check.outputs.authorized }}
2628
steps:
2729
- name: Verify labeler has write access
30+
id: check
2831
env:
2932
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3033
LABELER: ${{ github.event.sender.login }}
3134
run: |
3235
PERMISSION=$(gh api repos/${{ github.repository }}/collaborators/${LABELER}/permission --jq '.permission')
33-
if [[ "$PERMISSION" != "write" && "$PERMISSION" != "admin" && "$PERMISSION" != "maintain" ]]; then
36+
if [[ "$PERMISSION" == "write" || "$PERMISSION" == "admin" || "$PERMISSION" == "maintain" ]]; then
37+
echo "authorized=true" >> "$GITHUB_OUTPUT"
38+
else
3439
echo "${LABELER} has permission '${PERMISSION}' — removing label and notifying."
40+
echo "authorized=false" >> "$GITHUB_OUTPUT"
3541
gh pr edit ${{ github.event.pull_request.number }} --remove-label "ok-to-test"
3642
gh pr comment ${{ github.event.pull_request.number }} \
3743
--body "The \`ok-to-test\` label can only be applied by maintainers. It has been removed."
38-
exit 0
3944
fi
4045
46+
create-test-pr:
47+
needs: check-permission
48+
if: needs.check-permission.outputs.authorized == 'true'
49+
runs-on: ubuntu-latest
50+
steps:
4151
- name: Checkout community PR head
4252
uses: actions/checkout@v4
4353
with:
@@ -58,17 +68,19 @@ jobs:
5868
echo "failed=true" >> "$GITHUB_OUTPUT"
5969
fi
6070
61-
- name: Comment and exit on conflict
71+
- name: Remove label and comment on conflict
6272
if: steps.rebase.outputs.failed == 'true'
6373
env:
6474
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6575
COMMUNITY_PR_NUMBER: ${{ github.event.pull_request.number }}
76+
COMMUNITY_PR_AUTHOR: ${{ github.event.pull_request.user.login }}
6677
run: |
78+
gh pr edit "${COMMUNITY_PR_NUMBER}" --remove-label "ok-to-test"
6779
gh pr comment "${COMMUNITY_PR_NUMBER}" \
68-
--body "Cannot run tests: this PR has merge conflicts with \`main\`. Please rebase and re-apply the \`ok-to-test\` label."
80+
--body "@${COMMUNITY_PR_AUTHOR} Cannot run tests: this PR has merge conflicts with \`main\`. Please rebase."
6981
exit 1
7082
71-
- name: Push branch and open or update test PR
83+
- name: Push branch, open or update test PR, and trigger CI
7284
env:
7385
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7486
COMMUNITY_PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -79,30 +91,32 @@ jobs:
7991
run: |
8092
BRANCH="community-pr-test-${COMMUNITY_PR_NUMBER}"
8193
82-
echo "Community PR #${COMMUNITY_PR_NUMBER} from fork ${COMMUNITY_PR_FORK} — proceeding."
83-
94+
# Push rebased community PR code to a branch on this repo.
95+
# ci.yml triggered via workflow_dispatch on this branch will run
96+
# module_ci and module_acceptance against this code, not the fork.
8497
git push origin "HEAD:refs/heads/${BRANCH}" --force
8598
8699
EXISTING=$(gh pr list --head "${BRANCH}" --state open --json number --jq '.[0].number')
87100
if [ -n "$EXISTING" ]; then
88101
echo "Updated branch for existing test PR #${EXISTING}."
89102
gh pr comment "${EXISTING}" \
90103
--body "Branch updated with latest commits from community PR #${COMMUNITY_PR_NUMBER}."
91-
exit 0
104+
else
105+
PR_BODY=$(printf '%s\n\n%s\n%s\n%s\n\n%s' \
106+
"Automated test PR to run CI on behalf of community PR #${COMMUNITY_PR_NUMBER}." \
107+
"**Original PR:** ${COMMUNITY_PR_URL}" \
108+
"**Author:** @${COMMUNITY_PR_AUTHOR}" \
109+
"**Fork:** \`${COMMUNITY_PR_FORK}\`" \
110+
"> **Note:** This PR was created automatically when the \`ok-to-test\` label was applied. Do not merge — close it once tests complete and review the original PR instead.")
111+
112+
gh pr create \
113+
--title "[Test] Community PR #${COMMUNITY_PR_NUMBER}: ${COMMUNITY_PR_TITLE}" \
114+
--body "${PR_BODY}" \
115+
--base main \
116+
--head "${BRANCH}"
92117
fi
93118
94-
PR_BODY=$(printf '%s\n\n%s\n%s\n%s\n\n%s' \
95-
"Automated test PR to run CI on behalf of community PR #${COMMUNITY_PR_NUMBER}." \
96-
"**Original PR:** ${COMMUNITY_PR_URL}" \
97-
"**Author:** @${COMMUNITY_PR_AUTHOR}" \
98-
"**Fork:** \`${COMMUNITY_PR_FORK}\`" \
99-
"> **Note:** This PR was created automatically when the \`ok-to-test\` label was applied. Do not merge — close it once tests complete and review the original PR instead.")
100-
101-
gh pr create \
102-
--title "[Test] Community PR #${COMMUNITY_PR_NUMBER}: ${COMMUNITY_PR_TITLE}" \
103-
--body "${PR_BODY}" \
104-
--base main \
105-
--head "${BRANCH}"
119+
gh workflow run ci.yml --ref "${BRANCH}"
106120
107121
notify-on-failure:
108122
if: |
@@ -114,14 +128,13 @@ jobs:
114128
env:
115129
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116130
BRANCH: ${{ github.event.workflow_run.head_branch }}
117-
TEST_PR_URL: ${{ github.event.workflow_run.pull_requests[0].url }}
131+
RUN_URL: ${{ github.event.workflow_run.html_url }}
118132
run: |
119-
# Extract the original PR number from the branch name (community-pr-test-<N>)
120133
COMMUNITY_PR_NUMBER="${BRANCH#community-pr-test-}"
121134
122135
COMMENT_BODY=$(printf '%s\n\n%s\n%s' \
123136
"CI tests failed on the test PR for this community PR. Please review the failures and push a fix." \
124-
"**Test PR:** ${TEST_PR_URL}" \
125-
"**CI run:** ${{ github.event.workflow_run.html_url }}")
137+
"**Test branch:** \`${BRANCH}\`" \
138+
"**CI run:** ${RUN_URL}")
126139
127140
gh pr comment "${COMMUNITY_PR_NUMBER}" --body "${COMMENT_BODY}"

0 commit comments

Comments
 (0)