Skip to content

Commit 526f721

Browse files
authored
fix(workflow): add GH_TOKEN to gh CLI steps and split variable/label auth (#7768)
## Summary Fix CI poller and waiting-for-ci workflows failing with `gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable`. Failing run: https://github.com/getsentry/publish/actions/runs/24251134122/job/70810504705 ## Changes - Add `GH_TOKEN: ${{ github.token }}` to the `waiting-for-ci` comment step in `publish.yml` - Split `ci-pending.yml` step into two: label change uses app token, `gh variable set` uses `GITHUB_TOKEN` - Same split in `ci-poller.yml`: check/label step uses app token, variable disable step uses `GITHUB_TOKEN` ## Root Cause 1. `gh` CLI requires `GH_TOKEN` to be explicitly set in GitHub Actions — it does not auto-detect `GITHUB_TOKEN` 2. `gh variable set` needs the `actions_variables` permission which the GitHub App token may not have. Using `GITHUB_TOKEN` with `actions: write` from the workflow permissions works.
1 parent 7245d06 commit 526f721

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

.github/workflows/ci-pending.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ jobs:
2121
app-id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
2222
private-key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
2323

24-
- name: Add ci-pending label and enable poller
24+
- name: Add ci-pending label
2525
env:
26+
# Use the app token so the label event triggers publish.yml
27+
# (GITHUB_TOKEN events are suppressed by GitHub).
2628
GH_TOKEN: ${{ steps.token.outputs.token }}
2729
run: |
2830
gh issue edit "${{ github.event.issue.number }}" \
2931
-R "$GITHUB_REPOSITORY" \
3032
--add-label "ci-pending"
3133
32-
# Enable the cron poller (ci-poller.yml) so it starts checking
34+
- name: Enable cron poller
35+
env:
36+
# Use GITHUB_TOKEN (with actions:write) for variable access —
37+
# the app token may not have the actions_variables permission.
38+
GH_TOKEN: ${{ github.token }}
39+
run: |
3340
gh variable set CI_POLLER_HAS_PENDING -R "$GITHUB_REPOSITORY" -b "true"

.github/workflows/ci-poller.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
private-key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
2929

3030
- name: Check CI status for ci-pending issues
31+
id: check
3132
env:
3233
# Use the app token so label changes trigger publish.yml
3334
# (GITHUB_TOKEN events are suppressed by GitHub).
@@ -42,8 +43,7 @@ jobs:
4243
4344
count=$(echo "$issues" | jq length)
4445
if [[ "$count" == "0" ]]; then
45-
echo "No ci-pending issues found. Disabling poller."
46-
gh variable set CI_POLLER_HAS_PENDING -R "$GITHUB_REPOSITORY" -b "false"
46+
echo "No ci-pending issues found."
4747
exit 0
4848
fi
4949
echo "Found ${count} ci-pending issue(s)."
@@ -140,11 +140,17 @@ jobs:
140140
fi
141141
done
142142
143-
# Re-check if there are still pending issues; disable poller if none remain.
144-
# Note: there's a small race window where ci-pending.yml could set the
145-
# variable to "true" right before we set it to "false" here. In that case
146-
# the new issue waits at most one cron tick (5 min) — ci-pending.yml will
147-
# set the variable again on the next issue:opened event if needed.
143+
# Disable the poller if no ci-pending issues remain. Uses GITHUB_TOKEN
144+
# (with actions:write) since the app token may lack actions_variables
145+
# permission.
146+
# Note: there's a small race window where ci-pending.yml could set the
147+
# variable to "true" right before we set it to "false" here. In that case
148+
# the new issue waits at most one cron tick (5 min) — ci-pending.yml will
149+
# set the variable again on the next issue:opened event if needed.
150+
- name: Disable poller if no pending issues remain
151+
env:
152+
GH_TOKEN: ${{ github.token }}
153+
run: |
148154
remaining=$(gh issue list -R "$GITHUB_REPOSITORY" \
149155
--state open \
150156
--label ci-pending \

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
&& contains(github.event.issue.labels.*.name, 'ci-pending')
2626
steps:
2727
- name: Comment on issue
28+
env:
29+
GH_TOKEN: ${{ github.token }}
2830
run: |
2931
gh issue comment "${{ github.event.issue.number }}" \
3032
-R "$GITHUB_REPOSITORY" \

0 commit comments

Comments
 (0)