Skip to content

Commit a1bd0f5

Browse files
authored
fix(changelog): make scheduled draft run idempotent instead of time-gated (#52)
The 9 AM Toronto wall-clock gate required the run to execute in a 1-hour window, but GitHub's scheduler routinely delays cron triggers by 30-60+ minutes. Delayed runs landed outside the window and silently skipped, so some Fridays produced no changelog at all. Replace the time gate with an idempotency check: a scheduled run skips only when a draft changelog PR is already open. Both Friday crons now act as redundancy (whichever fires first does the work) and the job no longer depends on wall-clock execution time.
1 parent 7837ff0 commit a1bd0f5

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

.github/workflows/changelog-draft.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,29 @@ jobs:
3333
runs-on: ubuntu-latest
3434

3535
steps:
36-
- name: Gate scheduled run to 9 AM Toronto
36+
- name: Skip scheduled run if a changelog draft PR is already open
3737
id: gate
3838
shell: bash
39+
env:
40+
GITHUB_TOKEN: ${{ github.token }}
3941
run: |
4042
should_run=true
4143
44+
# Scheduled runs are idempotent rather than time-gated: GitHub's
45+
# scheduler can delay a cron by an hour or more, so we can't rely on
46+
# the wall-clock execution time. Two crons fire each Friday (one per
47+
# DST offset) for redundancy; whichever runs first does the work, and
48+
# any later run skips once a draft PR exists. Manual dispatch always
49+
# runs so drafts can be regenerated on demand.
4250
if [ "${{ github.event_name }}" = "schedule" ]; then
43-
toronto_hour="$(TZ=America/Toronto date +%H)"
44-
toronto_weekday="$(TZ=America/Toronto date +%u)"
51+
open_drafts="$(gh pr list \
52+
--repo "$GITHUB_REPOSITORY" \
53+
--state open \
54+
--json headRefName \
55+
--jq '[.[] | select(.headRefName | startswith("automation/changelog-"))] | length')"
4556
46-
if [ "$toronto_hour" != "09" ] || [ "$toronto_weekday" != "5" ]; then
57+
if [ "$open_drafts" != "0" ]; then
58+
echo "Found $open_drafts open changelog draft PR(s); skipping."
4759
should_run=false
4860
fi
4961
fi

0 commit comments

Comments
 (0)