Repository navigation
feat: implement issue #1052 — Codify the off-peak scheduling standard and offset this repo's 11 minute-0 crons #1053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d3adffb
feat: implement issue #1052 — Codify the off-peak scheduling standard…
donpetry-bot 8ddcb74
Merge branch 'main' into dev-lead/issue-1052-20260901-0149
don-petry 8164d75
fix(reviews): address review comments [skip ci-relay]
donpetry-bot f66454a
Merge branch 'main' into dev-lead/issue-1052-20260901-0149
don-petry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Quality gate for the off-peak scheduled-workflow timing check: the pure helper | ||
| # lib, the CI check that consumes it, and their validating bats tests. | ||
| # | ||
| # Triggered on any PR that touches: | ||
| # - scripts/lib/cron-timing.sh | ||
| # - scripts/check-cron-timing.sh | ||
| # - test/scripts/cron-timing/** | ||
| # - .github/workflows/cron-timing-tests.yml | ||
| # | ||
| # Gate: bats validates that cron_minute_is_zero flags minute-0 crons, that | ||
| # cron_offset_minute is deterministic, in 1..59, and de-collides the two | ||
| # historical pairs, and that check-cron-timing.sh fails a minute-0 fixture, | ||
| # points at the standard, and passes the repo's own (now offset) workflows. | ||
| # ShellCheck of the scripts is covered by the existing scripts/**/*.sh job in | ||
| # ci.yml. Standard: standards/ci-standards.md → "Scheduled Workflow Timing" (#1052). | ||
| # Modeled on .github/workflows/pr-limits-tests.yml. | ||
|
|
||
| name: Cron-timing Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'scripts/lib/cron-timing.sh' | ||
| - 'scripts/check-cron-timing.sh' | ||
| - 'test/scripts/cron-timing/**' | ||
| - '.github/workflows/cron-timing-tests.yml' | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'scripts/lib/cron-timing.sh' | ||
| - 'scripts/check-cron-timing.sh' | ||
| - 'test/scripts/cron-timing/**' | ||
| - '.github/workflows/cron-timing-tests.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: cron-timing-tests-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Validate cron timing | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 1 | ||
| # Read-only test job — never pushes; don't leave the token in git config. | ||
| persist-credentials: false | ||
|
|
||
| - name: Install bats | ||
| run: | | ||
| set -euo pipefail | ||
| sudo apt-get update -qq | ||
| sudo apt-get install -y --no-install-recommends bats | ||
|
|
||
| - name: Run bats suite | ||
| run: bats --print-output-on-failure test/scripts/cron-timing/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| # check-cron-timing.sh — fail if any workflow in .github/workflows/ schedules a | ||
| # cron on the top of the hour (minute field 0). Enforces the off-peak | ||
| # scheduled-workflow timing standard (standards/ci-standards.md → "Scheduled | ||
| # Workflow Timing"). Wired into ci.yml's Lint job and | ||
| # .dev-lead/scripts/dev-lead-lint.sh. | ||
| # | ||
| # Usage: check-cron-timing.sh [workflow-dir] | ||
| # workflow-dir defaults to the repo's own .github/workflows/. The templates in | ||
| # standards/workflows/ are deliberately out of scope — retiming them is | ||
| # downstream fan-out (tracked in petry-projects/.github-private#726), not this | ||
| # repo obeying the convention. | ||
|
|
||
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
| # shellcheck source=scripts/lib/cron-timing.sh | ||
| source "${SCRIPT_DIR}/lib/cron-timing.sh" | ||
|
|
||
| WORKFLOW_DIR="${1:-${SCRIPT_DIR}/../.github/workflows}" | ||
| STANDARD='standards/ci-standards.md → "Scheduled Workflow Timing"' | ||
|
|
||
| violations=0 | ||
| shopt -s nullglob | ||
| for wf in "${WORKFLOW_DIR}"/*.yml "${WORKFLOW_DIR}"/*.yaml; do | ||
| # Pull every quoted cron expression out of the file. A cron line looks like: | ||
| # - cron: '0 7 * * *' # comment | ||
| while IFS= read -r expr; do | ||
| [ -n "$expr" ] || continue | ||
| if cron_minute_is_zero "$expr"; then | ||
| { | ||
| printf 'FAIL: %s — cron "%s" fires at minute 0 (top of the hour).\n' \ | ||
| "$(basename "$wf")" "$expr" | ||
| printf ' Offset the minute field off :00 per %s.\n' "$STANDARD" | ||
| printf ' Suggested minute for this file: %s\n' "$(cron_offset_minute "$wf")" | ||
| } >&2 | ||
| violations=$((violations + 1)) | ||
| fi | ||
| done < <(grep -oE "cron:[[:space:]]*['\"][^'\"]+['\"]" "$wf" \ | ||
| | sed -E "s/cron:[[:space:]]*['\"]//; s/['\"]$//") | ||
| done | ||
|
|
||
| if [ "$violations" -gt 0 ]; then | ||
| printf '\n%d scheduled workflow(s) fire on the top of the hour. See %s.\n' \ | ||
| "$violations" "$STANDARD" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "cron-timing: all scheduled workflows in ${WORKFLOW_DIR} are offset off the top of the hour" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bash | ||
| # cron-timing.sh — pure, side-effect-free helpers for the off-peak | ||
| # scheduled-workflow timing standard (standards/ci-standards.md → "Scheduled | ||
| # Workflow Timing", promoted from the petry-projects/.github-private repo-local | ||
| # convention). No external calls; safe to `source` from a workflow, the CI | ||
| # check (scripts/check-cron-timing.sh), or a bats test. | ||
| # | ||
| # The same helpers both *detect* a top-of-the-hour cron and *pick* its | ||
| # deterministic replacement minute, so the CI check and the chosen values can | ||
| # never disagree, and a newly added workflow gets a defensible minute for free. | ||
|
|
||
| # Echo the minute field (field 1) of a 5-field cron expression. Leading and | ||
| # trailing whitespace is tolerated (default IFS word-splitting trims it). | ||
| cron_minute_field() { | ||
| local minute _rest | ||
| read -r minute _rest <<<"$1" | ||
| printf '%s' "$minute" | ||
| } | ||
|
|
||
| # Return 0 (true) when the cron minute field is a top-of-the-hour start (a bare | ||
| # `0`) — the behaviour the off-peak standard forbids (`0 * * * *`, `0 7 * * *`, | ||
| # `0 */4 * * *`, …). Any offset minute (17, 41, */15, …) returns non-zero. | ||
| cron_minute_is_zero() { | ||
| [[ "$(cron_minute_field "$1")" == "0" ]] | ||
| } | ||
|
|
||
| # Deterministic off-peak minute (1..59) for a workflow filename. Hashing the | ||
| # filename spreads workflows across the hour and moves any minute-0 cron to a | ||
| # non-zero minute, letting the check and the suggested value agree without | ||
| # hand-picking. Uniqueness across files is not guaranteed — hash collisions are | ||
| # possible; the no-duplicate-crons test catches any that occur in practice. | ||
| # cksum is POSIX and reproducible on every runner; the basename keeps the result | ||
| # path-independent so callers may pass a bare name or a full path. | ||
| cron_offset_minute() { | ||
| local name checksum | ||
| name="$(basename -- "$1")" | ||
| checksum="$(printf '%s' "$name" | cksum)" | ||
| checksum="${checksum%% *}" # keep the leading numeric checksum only | ||
| printf '%s' "$(( checksum % 59 + 1 ))" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.