Repository navigation
feat: implement issue #851 — [#850 A] Automated standards-deploy driver (scheduled fleet sweep → standards-sync PRs) #854
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
cd60399
feat: implement issue #851 — [#850 A] Automated standards-deploy driv…
donpetry-bot 11eae23
Merge branch 'main' into dev-lead/issue-851-20260721-2303
don-petry ec5864a
fix: address Copilot review on standards-deploy driver (#851)
don-petry dc0ed12
fix: correct no-op path assertion in driver.bats (#851)
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Scheduled fleet sweep that brings every org repo up to the standard workflow | ||
| # stubs — the automation the compliance audit was missing (petry-projects/.github#851). | ||
| # | ||
| # The audit only *files* remediation issues; it never deploys. This workflow runs | ||
| # scripts/deploy-standard-workflows.sh across the fleet on the org cadence (and on | ||
| # demand), opening `standards-sync` PRs wherever a repo drifts — a missing required | ||
| # stub, or a stub pinned off its agent's current channel. Compliant repos open | ||
| # nothing (the deploy script is idempotent), and SKIP_REPOS / SKIP_OVERRIDES are | ||
| # respected by the script. This is a driver, not a reimplementation: all deploy | ||
| # logic lives in the script and its libs. | ||
| # | ||
| # Pairs with #850-B (auto-merge) so the sweep -> PR -> merge loop closes with no | ||
| # manual intervention. | ||
| name: Standards Deploy | ||
| # readme-report: Weekly fleet sweep that opens standards-sync PRs for repos drifted off the org-standard workflow stubs. | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 8 * * 1' # Every Monday at 08:00 UTC — offset from the Fri 12:00 UTC compliance audit | ||
| workflow_dispatch: | ||
| inputs: | ||
| target_repo: | ||
| description: 'Limit the sweep to a single repo (name). Leave blank to sweep the whole fleet.' | ||
| required: false | ||
| type: string | ||
| target_workflow: | ||
| description: 'Limit to a single workflow stub (e.g. dev-lead.yml). Leave blank for all deployable.' | ||
| required: false | ||
| type: string | ||
| dry_run: | ||
| description: 'Dry run — plan drift only, open no PRs' | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: standards-deploy | ||
| cancel-in-progress: false # Let an in-flight sweep finish to avoid partial PR state | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Sweep fleet and open standards-sync PRs | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| permissions: | ||
| contents: read # only to check out this repo; all cross-repo writes use the PAT below | ||
| env: | ||
| GH_TOKEN: ${{ secrets.ORG_SCORECARD_TOKEN }} | ||
| TARGET_REPO: ${{ inputs.target_repo }} | ||
| TARGET_WORKFLOW: ${{ inputs.target_workflow }} | ||
| DRY_RUN: ${{ inputs.dry_run == true && 'true' || 'false' }} | ||
| steps: | ||
| - name: Checkout .github repo | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
|
|
||
| - name: Run standards-deploy fleet sweep | ||
| run: bash scripts/standards-deploy-driver.sh | ||
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,45 @@ | ||
| #!/usr/bin/env bash | ||
| # standards-deploy-driver.sh — scheduled fleet-sweep driver for the org-standard | ||
| # workflow deployer (petry-projects/.github#851, Epic #850). | ||
| # | ||
| # The compliance audit only *files* remediation issues; bringing the fleet to | ||
| # standard still required a human running deploy-standard-workflows.sh by hand. | ||
| # This driver closes that gap: the standards-deploy.yml workflow runs it on the | ||
| # org cadence (and on demand), so drifted repos get standards-sync PRs opened | ||
| # automatically. | ||
| # | ||
| # It is deliberately THIN — it adds NO deploy logic. All drift detection, | ||
| # SKIP_REPOS / SKIP_OVERRIDES handling, ring/channel pinning, idempotency, and | ||
| # PR creation live in deploy-standard-workflows.sh and its libs. This driver only | ||
| # maps workflow_dispatch inputs (environment variables) onto that script's flags | ||
| # and runs it, so the dispatch surface stays unit-testable. | ||
| # | ||
| # Inputs (environment variables, all optional): | ||
| # TARGET_REPO Limit the sweep to a single repo (--repo). Blank = whole fleet. | ||
| # TARGET_WORKFLOW Limit to a single workflow (--workflow). Blank = all deployable. | ||
| # DRY_RUN "true" -> pass --dry-run (plan only, open no PRs). | ||
| # | ||
| # Overridable for tests: | ||
| # DEPLOY_SCRIPT Path to the deploy script (default: sibling in this dir). | ||
| # | ||
| # Requires GH_TOKEN with repo scope for cross-repo branch + PR creation. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| DEPLOY_SCRIPT="${DEPLOY_SCRIPT:-$SCRIPT_DIR/deploy-standard-workflows.sh}" | ||
|
|
||
| TARGET_REPO="${TARGET_REPO:-}" | ||
| TARGET_WORKFLOW="${TARGET_WORKFLOW:-}" | ||
| DRY_RUN="${DRY_RUN:-false}" | ||
|
|
||
| # Build the flag list from the inputs. An empty list means "whole fleet, all | ||
| # deployable workflows" — the scheduled default. | ||
| declare -a args=() | ||
| [[ -n "$TARGET_REPO" ]] && args+=(--repo "$TARGET_REPO") | ||
| [[ -n "$TARGET_WORKFLOW" ]] && args+=(--workflow "$TARGET_WORKFLOW") | ||
| [[ "$DRY_RUN" == "true" ]] && args+=(--dry-run) | ||
|
|
||
| echo "[driver] standards-deploy sweep — repo=${TARGET_REPO:-<all>} workflow=${TARGET_WORKFLOW:-<all>} dry_run=${DRY_RUN}" | ||
|
|
||
| exec bash "$DEPLOY_SCRIPT" "${args[@]}" |
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,135 @@ | ||
| #!/usr/bin/env bats | ||
| # Tests for scripts/standards-deploy-driver.sh — the scheduled fleet-sweep driver | ||
| # for the org-standard workflow deployer (petry-projects/.github#851). | ||
| # | ||
| # The driver is intentionally thin: it maps workflow_dispatch inputs (env vars) | ||
| # into flags for scripts/deploy-standard-workflows.sh and runs it. Two layers are | ||
| # exercised here: | ||
| # 1. argv mapping — a fake deploy script records the flags it is handed, so the | ||
| # env→flag translation (repo / workflow / dry-run / default fleet) is pinned. | ||
| # 2. drift-detection + no-op paths — the driver runs the REAL deploy script | ||
| # against a fake `gh`, proving a drifted repo plans a PR and a compliant repo | ||
| # opens nothing (idempotent), the same guarantees the schedule relies on. | ||
|
|
||
| setup() { | ||
| TT_TMP="$(mktemp -d)" | ||
| REPO_ROOT="$(cd -- "${BATS_TEST_DIRNAME}/../../.." && pwd)" | ||
| DRIVER="${REPO_ROOT}/scripts/standards-deploy-driver.sh" | ||
| ARGV_LOG="${TT_TMP}/argv.log"; export ARGV_LOG | ||
| GH_CALLS="${TT_TMP}/gh-calls.log"; export GH_CALLS | ||
| : > "$GH_CALLS" | ||
| } | ||
|
|
||
| teardown() { rm -rf "$TT_TMP"; } | ||
|
|
||
| # A fake deploy script that records exactly the argv the driver hands it. Wired in | ||
| # via the DEPLOY_SCRIPT override so the argv-mapping tests never touch the network. | ||
| install_fake_deploy() { | ||
| local fake="${TT_TMP}/fake-deploy.sh" | ||
| cat > "$fake" <<'FAKE' | ||
| #!/usr/bin/env bash | ||
| { for a in "$@"; do printf '%s\n' "$a"; done; } > "$ARGV_LOG" | ||
| FAKE | ||
| chmod +x "$fake" | ||
| DEPLOY_SCRIPT="$fake"; export DEPLOY_SCRIPT | ||
| } | ||
|
|
||
| # Fake `gh` mirroring the deploy script's own tests: contents API 404s when | ||
| # GH_CONTENT_B64 is unset (stub missing → drift) and returns it as the file body | ||
| # when set (stub present → compliant). `gh repo list` echoes $GH_REPO_LIST. | ||
| install_gh_stub() { | ||
| local bin="${TT_TMP}/bin" | ||
| mkdir -p "$bin" | ||
| cat > "$bin/gh" <<'STUB' | ||
| #!/usr/bin/env bash | ||
| { printf 'gh'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'; } >> "$GH_CALLS" | ||
| if [ "${1:-}" = "repo" ] && [ "${2:-}" = "list" ]; then | ||
| printf '%s\n' ${GH_REPO_LIST:-} | ||
| exit 0 | ||
| fi | ||
| if [ "${1:-}" = "api" ]; then | ||
| case "$2" in | ||
| *contents*) | ||
| if [ -n "${GH_CONTENT_B64:-}" ]; then | ||
| printf '{"sha":"abc123","content":"%s"}' "$GH_CONTENT_B64" | ||
| exit 0 | ||
| fi | ||
| exit 1 ;; # simulate 404 — file absent | ||
| esac | ||
| fi | ||
| exit 0 | ||
| STUB | ||
| chmod +x "$bin/gh" | ||
| PATH="${bin}:${PATH}"; export PATH | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # argv mapping | ||
| # --------------------------------------------------------------------------- | ||
| @test "maps target_repo, target_workflow, and dry_run to script flags" { | ||
| install_fake_deploy | ||
| run env TARGET_REPO=markets TARGET_WORKFLOW=dev-lead.yml DRY_RUN=true \ | ||
| bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| # Flags recorded in order, one per line. | ||
| run cat "$ARGV_LOG" | ||
| [ "${lines[0]}" = "--repo" ] | ||
| [ "${lines[1]}" = "markets" ] | ||
| [ "${lines[2]}" = "--workflow" ] | ||
| [ "${lines[3]}" = "dev-lead.yml" ] | ||
| [ "${lines[4]}" = "--dry-run" ] | ||
| } | ||
|
|
||
| @test "no inputs sweeps the whole fleet (no --repo / --workflow flags)" { | ||
| install_fake_deploy | ||
| run bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| run cat "$ARGV_LOG" | ||
| # Empty argv => whole-fleet, all-workflows sweep. | ||
| [ ! -s "$ARGV_LOG" ] | ||
| } | ||
|
|
||
| @test "dry_run defaults off — no --dry-run flag when unset" { | ||
| install_fake_deploy | ||
| run env TARGET_REPO=markets bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| ! grep -qx -- '--dry-run' "$ARGV_LOG" | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # drift-detection + no-op paths (driver over the REAL deploy script) | ||
| # --------------------------------------------------------------------------- | ||
| @test "drift path: a missing stub is planned as a PR" { | ||
| install_gh_stub | ||
| run env GH_TOKEN=x TARGET_REPO=markets TARGET_WORKFLOW=add-to-project.yml DRY_RUN=true \ | ||
| bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| echo "$output" | grep -qE 'Would open PR for markets .* add-to-project.yml' | ||
| # dry-run must not mutate. | ||
| ! grep -q 'git/refs --method POST' "$GH_CALLS" | ||
| ! grep -q 'gh pr create' "$GH_CALLS" | ||
| } | ||
|
|
||
| @test "no-op path: a compliant stub opens nothing" { | ||
| local template="${REPO_ROOT}/standards/workflows/add-to-project.yml" | ||
| GH_CONTENT_B64="$(base64 -w 0 "$template" 2>/dev/null || base64 -b 0 "$template")" | ||
| export GH_CONTENT_B64 | ||
| install_gh_stub | ||
| run env GH_TOKEN=x TARGET_REPO=markets TARGET_WORKFLOW=add-to-project.yml DRY_RUN=true \ | ||
| bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| echo "$output" | grep -q 'already compliant' | ||
| # True absence check: fail if any line plans a PR. `grep -vq` was wrong — it | ||
| # succeeds whenever *any* line doesn't match, so it can't prove absence. | ||
| ! echo "$output" | grep -q 'Would open PR' | ||
| } | ||
|
don-petry marked this conversation as resolved.
Resolved
|
||
|
|
||
| @test "fleet sweep iterates every repo from gh repo list" { | ||
| GH_REPO_LIST="markets TalkTerm"; export GH_REPO_LIST | ||
| install_gh_stub | ||
| run env GH_TOKEN=x TARGET_WORKFLOW=add-to-project.yml DRY_RUN=true bash "$DRIVER" | ||
| [ "$status" -eq 0 ] | ||
| # Both fleet repos are drifted (stub absent) => both planned, none skipped. | ||
| echo "$output" | grep -qE 'Would open PR for markets' | ||
| echo "$output" | grep -qE 'Would open PR for TalkTerm' | ||
| } | ||
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.