Skip to content

Commit 27ca2f5

Browse files
authored
fix(ci): replace close/reopen hack with workflow_dispatch for bot PRs (#592)
GITHUB_TOKEN suppresses all events it creates (push, pull_request, etc.) so the close/reopen workaround never triggered CI or enterprise audit workflows. Replace with `gh workflow run ci.yml` which uses the exempt workflow_dispatch event. Add job summaries with instructions to click "Update branch" to trigger enterprise required workflows until a proper fix is in place.
1 parent 9d885fa commit 27ca2f5

2 files changed

Lines changed: 58 additions & 21 deletions

File tree

.github/workflows/generate.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
name: Sync OpenAPI definition
3333
runs-on: ubuntu-latest
3434
permissions:
35+
actions: write # To trigger CI workflow via workflow_dispatch
3536
contents: write # To push generated SDK code
3637
pull-requests: write # To create PRs for review
3738
outputs:
@@ -72,7 +73,11 @@ jobs:
7273
- name: Commit and push changes
7374
if: steps.check.outputs.has_changes == 'true'
7475
run: |
75-
git checkout -b automated/open-api
76+
# Branch from main~1 so the PR is behind main, making the
77+
# "Update branch" button available to trigger enterprise checks.
78+
git stash
79+
git checkout -b automated/open-api HEAD~1
80+
git stash pop
7681
git add .
7782
git commit -m "fix(openapi): sync with openapi definition"
7883
git push origin automated/open-api -fu
@@ -109,18 +114,36 @@ jobs:
109114
fi
110115
111116
# Pushes made with GITHUB_TOKEN don't trigger other workflows.
112-
# Close/reopen the PR to generate a pull_request.reopened event,
113-
# which triggers required CI and enterprise audit workflows.
117+
# Use workflow_dispatch to directly trigger CI on the PR branch.
114118
- name: Trigger CI checks
119+
if: steps.check.outputs.has_changes == 'true'
120+
env:
121+
GH_TOKEN: ${{ github.token }}
122+
run: gh workflow run ci.yml --ref automated/open-api
123+
124+
- name: Add job summary
115125
if: steps.check.outputs.has_changes == 'true'
116126
env:
117127
GH_TOKEN: ${{ github.token }}
118128
run: |
119-
pr_number=$(gh pr list --head automated/open-api --json number --jq '.[0].number')
120-
if [ -n "$pr_number" ]; then
121-
gh pr close "$pr_number"
122-
gh pr reopen "$pr_number"
123-
fi
129+
pr_number=$(gh pr list --head automated/open-api --json number --jq '.[0].number' || echo "")
130+
pr_url="https://github.com/${{ github.repository }}/pull/${pr_number}"
131+
132+
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
133+
## OpenAPI Sync Complete
134+
135+
**PR:** [#${pr_number}](${pr_url})
136+
137+
> **Note:** Enterprise required workflows (e.g. Audit GHA Workflows) won't trigger
138+
> automatically on bot PRs. Click **"Update branch"** on the PR to trigger them,
139+
> or push an empty commit to the branch:
140+
>
141+
> \`\`\`sh
142+
> git fetch origin automated/open-api && git checkout automated/open-api
143+
> git commit --allow-empty -m "chore: trigger enterprise checks"
144+
> git push origin automated/open-api
145+
> \`\`\`
146+
EOF
124147
125148
- uses: SocketDev/socket-registry/.github/actions/cleanup-git-signing@bbe46386c0a2bc6baefd02916234956a38e622d5 # main
126149
if: always()

.github/workflows/weekly-update.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
if: needs.check-updates.outputs.has-updates == 'true' && inputs.dry-run != true
4646
runs-on: ubuntu-latest
4747
permissions:
48+
actions: write
4849
contents: write
4950
pull-requests: write
5051
steps:
@@ -57,7 +58,9 @@ jobs:
5758
run: |
5859
BRANCH_NAME="weekly-update-$(date +%Y%m%d)"
5960
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git"
60-
git checkout -b "$BRANCH_NAME"
61+
# Branch from HEAD~1 so the PR is behind main, making the
62+
# "Update branch" button available to trigger enterprise checks.
63+
git checkout -b "$BRANCH_NAME" HEAD~1
6164
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
6265
6366
- uses: SocketDev/socket-registry/.github/actions/setup-git-signing@bbe46386c0a2bc6baefd02916234956a38e622d5 # main
@@ -269,30 +272,41 @@ jobs:
269272
--base main
270273
271274
# Pushes made with GITHUB_TOKEN don't trigger other workflows.
272-
# Close/reopen the PR to generate a pull_request.reopened event,
273-
# which triggers required CI and enterprise audit workflows.
275+
# Use workflow_dispatch to directly trigger CI on the PR branch.
274276
- name: Trigger CI checks
275277
if: steps.final.outputs.success == 'true' && steps.validate.outputs.valid == 'true' && steps.changes.outputs.has-changes == 'true'
276278
env:
277279
GH_TOKEN: ${{ github.token }}
278280
BRANCH_NAME: ${{ steps.branch.outputs.branch }}
279-
run: |
280-
pr_number=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number')
281-
if [ -n "$pr_number" ]; then
282-
gh pr close "$pr_number"
283-
gh pr reopen "$pr_number"
284-
fi
281+
run: gh workflow run ci.yml --ref "$BRANCH_NAME"
285282

286283
- name: Add job summary
287284
if: steps.final.outputs.success == 'true' && steps.validate.outputs.valid == 'true' && steps.changes.outputs.has-changes == 'true'
288285
env:
286+
GH_TOKEN: ${{ github.token }}
289287
BRANCH_NAME: ${{ steps.branch.outputs.branch }}
290288
run: |
291289
COMMIT_COUNT=$(git rev-list --count origin/main..HEAD)
292-
echo "## Weekly Update Complete" >> $GITHUB_STEP_SUMMARY
293-
echo "" >> $GITHUB_STEP_SUMMARY
294-
echo "**Branch:** \`${BRANCH_NAME}\`" >> $GITHUB_STEP_SUMMARY
295-
echo "**Commits:** ${COMMIT_COUNT}" >> $GITHUB_STEP_SUMMARY
290+
pr_number=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number' || echo "")
291+
pr_url="https://github.com/${{ github.repository }}/pull/${pr_number}"
292+
293+
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
294+
## Weekly Update Complete
295+
296+
**PR:** [#${pr_number}](${pr_url})
297+
**Branch:** \`${BRANCH_NAME}\`
298+
**Commits:** ${COMMIT_COUNT}
299+
300+
> **Note:** Enterprise required workflows (e.g. Audit GHA Workflows) won't trigger
301+
> automatically on bot PRs. Click **"Update branch"** on the PR to trigger them,
302+
> or push an empty commit to the branch:
303+
>
304+
> \`\`\`sh
305+
> git fetch origin ${BRANCH_NAME} && git checkout ${BRANCH_NAME}
306+
> git commit --allow-empty -m "chore: trigger enterprise checks"
307+
> git push origin ${BRANCH_NAME}
308+
> \`\`\`
309+
EOF
296310
297311
- name: Upload Claude output
298312
if: always()

0 commit comments

Comments
 (0)