|
| 1 | +# Manual Release Flow Implementation Plan |
| 2 | + |
| 3 | +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. |
| 4 | +
|
| 5 | +**Goal:** Gate tagging and R2 uploads to manual workflow_dispatch runs while keeping build/lint/test on all branches, and add a gh CLI trigger script. |
| 6 | + |
| 7 | +**Architecture:** Add lightweight bash tests to assert the build workflow’s triggers and release gating. Refactor `.github/workflows/build.yml` to remove branch filters and to run semantic-release/release only on workflow_dispatch. Add a CLI helper script that wraps `gh workflow run` for manual dispatch. |
| 8 | + |
| 9 | +**Tech Stack:** GitHub Actions YAML, Bash, gh CLI |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Assert build workflow gating and refactor triggers |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Create: `scripts/build-workflow.test.sh` |
| 17 | +- Modify: `.github/workflows/build.yml` |
| 18 | + |
| 19 | +**Step 1: Write the failing test** |
| 20 | + |
| 21 | +```bash |
| 22 | +#!/usr/bin/env bash |
| 23 | +set -euo pipefail |
| 24 | + |
| 25 | +workflow=".github/workflows/build.yml" |
| 26 | + |
| 27 | +if [[ ! -f "$workflow" ]]; then |
| 28 | + echo "Missing $workflow" >&2 |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +if grep -qE '^[[:space:]]+branches:' "$workflow"; then |
| 33 | + echo "Expected no branch filters in build workflow" >&2 |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +semantic_block=$(awk ' |
| 38 | + $1=="semantic-release:" {in=1; next} |
| 39 | + in && /^[^[:space:]]/ {in=0} |
| 40 | + in {print} |
| 41 | +' "$workflow") |
| 42 | + |
| 43 | +if ! grep -q "if: github.event_name == 'workflow_dispatch'" <<<"$semantic_block"; then |
| 44 | + echo "Expected semantic-release gated by workflow_dispatch" >&2 |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +release_block=$(awk ' |
| 49 | + $1=="release:" {in=1; next} |
| 50 | + in && /^[^[:space:]]/ {in=0} |
| 51 | + in {print} |
| 52 | +' "$workflow") |
| 53 | + |
| 54 | +if ! grep -q "needs.semantic-release.outputs.published == 'true'" <<<"$release_block"; then |
| 55 | + echo "Expected release job to depend on semantic-release published output" >&2 |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +if ! grep -q "github.event_name == 'workflow_dispatch'" <<<"$release_block"; then |
| 60 | + echo "Expected release job gated by workflow_dispatch" >&2 |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +echo "OK" |
| 65 | +``` |
| 66 | + |
| 67 | +**Step 2: Run test to verify it fails** |
| 68 | + |
| 69 | +Run: `bash scripts/build-workflow.test.sh` |
| 70 | + |
| 71 | +Expected: FAIL because branch filters exist and semantic-release is not gated by workflow_dispatch. |
| 72 | + |
| 73 | +**Step 3: Write minimal implementation** |
| 74 | + |
| 75 | +Update `.github/workflows/build.yml`: |
| 76 | +- Remove `branches:` filters under `push` and `pull_request`. |
| 77 | +- Set `semantic-release` job to `if: github.event_name == 'workflow_dispatch'`. |
| 78 | +- Gate `release` job with `if: needs.semantic-release.outputs.published == 'true' && github.event_name == 'workflow_dispatch'`. |
| 79 | + |
| 80 | +**Step 4: Run test to verify it passes** |
| 81 | + |
| 82 | +Run: `bash scripts/build-workflow.test.sh` |
| 83 | + |
| 84 | +Expected: PASS |
| 85 | + |
| 86 | +**Step 5: Commit** |
| 87 | + |
| 88 | +```bash |
| 89 | +git add scripts/build-workflow.test.sh .github/workflows/build.yml |
| 90 | +git commit -m "ci: gate releases behind manual workflow_dispatch" |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +### Task 2: Add gh CLI trigger script (TDD) |
| 96 | + |
| 97 | +**Files:** |
| 98 | +- Create: `scripts/trigger-release.test.sh` |
| 99 | +- Create: `scripts/trigger-release.sh` |
| 100 | + |
| 101 | +**Step 1: Write the failing test** |
| 102 | + |
| 103 | +```bash |
| 104 | +#!/usr/bin/env bash |
| 105 | +set -euo pipefail |
| 106 | + |
| 107 | +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 108 | +script="$root/scripts/trigger-release.sh" |
| 109 | + |
| 110 | +tmp="$(mktemp -d)" |
| 111 | +trap 'rm -rf "$tmp"' EXIT |
| 112 | + |
| 113 | +stub="$tmp/gh" |
| 114 | +cat > "$stub" <<'STUB' |
| 115 | +#!/usr/bin/env bash |
| 116 | +echo "$@" > "$CAPTURE_FILE" |
| 117 | +STUB |
| 118 | +chmod +x "$stub" |
| 119 | + |
| 120 | +export GH_BIN="$stub" |
| 121 | + |
| 122 | +CAPTURE_FILE="$tmp/args1" "$script" --ref feature/test --workflow build.yml |
| 123 | +expected="workflow run build.yml --ref feature/test" |
| 124 | +got="$(cat "$tmp/args1")" |
| 125 | +if [[ "$got" != "$expected" ]]; then |
| 126 | + echo "expected: $expected" >&2 |
| 127 | + echo "got: $got" >&2 |
| 128 | + exit 1 |
| 129 | +fi |
| 130 | + |
| 131 | +CAPTURE_FILE="$tmp/args2" "$script" --workflow build.yml |
| 132 | +expected="workflow run build.yml --ref main" |
| 133 | +got="$(cat "$tmp/args2")" |
| 134 | +if [[ "$got" != "$expected" ]]; then |
| 135 | + echo "expected: $expected" >&2 |
| 136 | + echo "got: $got" >&2 |
| 137 | + exit 1 |
| 138 | +fi |
| 139 | + |
| 140 | +echo "OK" |
| 141 | +``` |
| 142 | + |
| 143 | +**Step 2: Run test to verify it fails** |
| 144 | + |
| 145 | +Run: `bash scripts/trigger-release.test.sh` |
| 146 | + |
| 147 | +Expected: FAIL because `scripts/trigger-release.sh` does not exist. |
| 148 | + |
| 149 | +**Step 3: Write minimal implementation** |
| 150 | + |
| 151 | +Create `scripts/trigger-release.sh`: |
| 152 | + |
| 153 | +```bash |
| 154 | +#!/usr/bin/env bash |
| 155 | +set -euo pipefail |
| 156 | + |
| 157 | +usage() { |
| 158 | + cat <<'USAGE' |
| 159 | +Usage: scripts/trigger-release.sh [--ref <git-ref>] [--workflow <workflow-file>] |
| 160 | +
|
| 161 | +Triggers the manual release workflow via gh CLI. |
| 162 | +
|
| 163 | +Options: |
| 164 | + --ref, -r Git ref to run the workflow on (default: main) |
| 165 | + --workflow, -w Workflow file name (default: build.yml) |
| 166 | + --help, -h Show help |
| 167 | +USAGE |
| 168 | +} |
| 169 | + |
| 170 | +ref="main" |
| 171 | +workflow="build.yml" |
| 172 | + |
| 173 | +while [[ $# -gt 0 ]]; do |
| 174 | + case "$1" in |
| 175 | + -r|--ref) |
| 176 | + ref="$2" |
| 177 | + shift 2 |
| 178 | + ;; |
| 179 | + -w|--workflow) |
| 180 | + workflow="$2" |
| 181 | + shift 2 |
| 182 | + ;; |
| 183 | + -h|--help) |
| 184 | + usage |
| 185 | + exit 0 |
| 186 | + ;; |
| 187 | + *) |
| 188 | + echo "Unknown argument: $1" >&2 |
| 189 | + usage |
| 190 | + exit 1 |
| 191 | + ;; |
| 192 | + esac |
| 193 | +done |
| 194 | + |
| 195 | +gh_bin="${GH_BIN:-gh}" |
| 196 | +if command -v "$gh_bin" >/dev/null 2>&1; then |
| 197 | + gh_cmd="$gh_bin" |
| 198 | +elif [[ -x "$gh_bin" ]]; then |
| 199 | + gh_cmd="$gh_bin" |
| 200 | +else |
| 201 | + echo "gh CLI not found. Install from https://cli.github.com" >&2 |
| 202 | + exit 1 |
| 203 | +fi |
| 204 | + |
| 205 | +repo_root=$(git rev-parse --show-toplevel 2>/dev/null || true) |
| 206 | +if [[ -z "$repo_root" ]]; then |
| 207 | + echo "Not inside a git repository." >&2 |
| 208 | + exit 1 |
| 209 | +fi |
| 210 | + |
| 211 | +cd "$repo_root" |
| 212 | +"$gh_cmd" workflow run "$workflow" --ref "$ref" |
| 213 | + |
| 214 | +echo "Triggered $workflow on ref $ref" |
| 215 | +``` |
| 216 | + |
| 217 | +Make it executable: `chmod +x scripts/trigger-release.sh` |
| 218 | + |
| 219 | +**Step 4: Run test to verify it passes** |
| 220 | + |
| 221 | +Run: `bash scripts/trigger-release.test.sh` |
| 222 | + |
| 223 | +Expected: PASS |
| 224 | + |
| 225 | +**Step 5: Commit** |
| 226 | + |
| 227 | +```bash |
| 228 | +git add scripts/trigger-release.test.sh scripts/trigger-release.sh |
| 229 | +git commit -m "scripts: add gh workflow dispatch helper" |
| 230 | +``` |
0 commit comments