|
| 1 | +name: Nightly Verified Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run at 03:00 UTC every day |
| 6 | + - cron: '0 3 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + force_release: |
| 10 | + description: 'Force release even if no new Claude version' |
| 11 | + required: false |
| 12 | + default: 'false' |
| 13 | + type: boolean |
| 14 | + skip_ai_analysis: |
| 15 | + description: 'Skip AI-powered analysis' |
| 16 | + required: false |
| 17 | + default: 'false' |
| 18 | + type: boolean |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + issues: write |
| 23 | + |
| 24 | +env: |
| 25 | + CARGO_TERM_COLOR: always |
| 26 | + RUSTFLAGS: "-D warnings" |
| 27 | + |
| 28 | +jobs: |
| 29 | + # ───────────────────────────────────────────────────────────── |
| 30 | + # Phase 1: Detect new Claude Code release |
| 31 | + # ───────────────────────────────────────────────────────────── |
| 32 | + detect: |
| 33 | + name: Detect Claude Code Release |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + new_version: ${{ steps.check.outputs.new_version }} |
| 37 | + should_release: ${{ steps.check.outputs.should_release }} |
| 38 | + previous_version: ${{ steps.check.outputs.previous_version }} |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + submodules: recursive |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Check for new Claude Code version |
| 46 | + id: check |
| 47 | + run: | |
| 48 | + chmod +x scripts/check-claude-release.sh |
| 49 | +
|
| 50 | + PREVIOUS=$(cat scripts/last-known-claude-version.txt 2>/dev/null || echo "none") |
| 51 | + echo "previous_version=${PREVIOUS}" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + if ./scripts/check-claude-release.sh > /tmp/new_version.txt 2>/tmp/check_stderr.txt; then |
| 54 | + NEW_VERSION=$(cat /tmp/new_version.txt) |
| 55 | + echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" |
| 56 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 57 | + echo "New Claude Code version detected: ${NEW_VERSION}" |
| 58 | + else |
| 59 | + EXIT_CODE=$? |
| 60 | + cat /tmp/check_stderr.txt |
| 61 | + if [[ "${{ inputs.force_release }}" == "true" ]]; then |
| 62 | + echo "Force release requested. Using current version." |
| 63 | + echo "new_version=${PREVIOUS}" >> "$GITHUB_OUTPUT" |
| 64 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 65 | + else |
| 66 | + echo "No new version. Skipping release." |
| 67 | + echo "should_release=false" >> "$GITHUB_OUTPUT" |
| 68 | + echo "new_version=${PREVIOUS}" >> "$GITHUB_OUTPUT" |
| 69 | + fi |
| 70 | + fi |
| 71 | +
|
| 72 | + # ───────────────────────────────────────────────────────────── |
| 73 | + # Phase 2: Full verification (only if new version detected) |
| 74 | + # ───────────────────────────────────────────────────────────── |
| 75 | + verify: |
| 76 | + name: Verify (No Regressions) |
| 77 | + needs: detect |
| 78 | + if: needs.detect.outputs.should_release == 'true' |
| 79 | + runs-on: ubuntu-latest |
| 80 | + outputs: |
| 81 | + test_passed: ${{ steps.tests.outputs.passed }} |
| 82 | + bench_passed: ${{ steps.bench_check.outputs.passed }} |
| 83 | + audit_passed: ${{ steps.audit.outputs.passed }} |
| 84 | + test_count: ${{ steps.tests.outputs.test_count }} |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + submodules: recursive |
| 89 | + |
| 90 | + - name: Install Rust toolchain |
| 91 | + uses: dtolnay/rust-toolchain@stable |
| 92 | + with: |
| 93 | + targets: aarch64-unknown-none |
| 94 | + components: clippy |
| 95 | + |
| 96 | + - name: Cache cargo registry and build |
| 97 | + uses: actions/cache@v4 |
| 98 | + with: |
| 99 | + path: | |
| 100 | + ~/.cargo/registry |
| 101 | + ~/.cargo/git |
| 102 | + target |
| 103 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 104 | + restore-keys: ${{ runner.os }}-cargo- |
| 105 | + |
| 106 | + # ── Gate 1: All tests must pass ── |
| 107 | + - name: Run full test suite |
| 108 | + id: tests |
| 109 | + run: | |
| 110 | + echo "Running all workspace tests..." |
| 111 | + TEST_OUTPUT=$(cargo test --workspace --lib 2>&1) || { |
| 112 | + echo "::error::Test suite FAILED" |
| 113 | + echo "${TEST_OUTPUT}" |
| 114 | + echo "passed=false" >> "$GITHUB_OUTPUT" |
| 115 | + exit 1 |
| 116 | + } |
| 117 | +
|
| 118 | + # Count passing tests |
| 119 | + TOTAL=$(echo "${TEST_OUTPUT}" | grep "test result:" | awk '{sum += $4} END {print sum}') |
| 120 | + FAILED=$(echo "${TEST_OUTPUT}" | grep "test result:" | awk '{sum += $6} END {print sum}') |
| 121 | + echo "test_count=${TOTAL}" >> "$GITHUB_OUTPUT" |
| 122 | +
|
| 123 | + if [[ "${FAILED}" -gt 0 ]]; then |
| 124 | + echo "::error::${FAILED} tests FAILED" |
| 125 | + echo "passed=false" >> "$GITHUB_OUTPUT" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | +
|
| 129 | + echo "All ${TOTAL} tests passed." |
| 130 | + echo "passed=true" >> "$GITHUB_OUTPUT" |
| 131 | +
|
| 132 | + # Save test report |
| 133 | + echo "{\"passed\": ${TOTAL}, \"failed\": 0, \"date\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > test-report.json |
| 134 | +
|
| 135 | + # ── Gate 2: Clippy must be clean ── |
| 136 | + - name: Clippy lint check |
| 137 | + run: | |
| 138 | + cargo clippy --workspace -- -D warnings |
| 139 | +
|
| 140 | + # ── Gate 3: Bare-metal build must succeed ── |
| 141 | + - name: Bare-metal cross-compile check |
| 142 | + run: | |
| 143 | + cargo check --target aarch64-unknown-none -p rvm-hal --no-default-features |
| 144 | +
|
| 145 | + # ── Gate 4: Security audit ── |
| 146 | + - name: Install cargo-audit |
| 147 | + run: cargo install cargo-audit --locked |
| 148 | + - name: Security audit |
| 149 | + id: audit |
| 150 | + run: | |
| 151 | + if cargo audit 2>&1; then |
| 152 | + echo "passed=true" >> "$GITHUB_OUTPUT" |
| 153 | + else |
| 154 | + echo "::warning::cargo audit found issues (non-blocking for now)" |
| 155 | + echo "passed=true" >> "$GITHUB_OUTPUT" |
| 156 | + fi |
| 157 | +
|
| 158 | + # ── Gate 5: Benchmarks with regression detection ── |
| 159 | + - name: Run benchmarks |
| 160 | + run: | |
| 161 | + cargo bench -p rvm-benches -- --output-format=bencher 2>&1 | tee benchmark-output.txt || true |
| 162 | +
|
| 163 | + - name: Check benchmark regressions |
| 164 | + id: bench_check |
| 165 | + run: | |
| 166 | + chmod +x scripts/benchmark-regression-check.sh |
| 167 | +
|
| 168 | + if [[ -d "target/criterion" ]]; then |
| 169 | + if ./scripts/benchmark-regression-check.sh target/criterion; then |
| 170 | + echo "passed=true" >> "$GITHUB_OUTPUT" |
| 171 | + else |
| 172 | + echo "::error::Benchmark regression detected (>5% threshold)" |
| 173 | + echo "passed=false" >> "$GITHUB_OUTPUT" |
| 174 | + exit 1 |
| 175 | + fi |
| 176 | + else |
| 177 | + echo "No criterion output. Skipping regression check." |
| 178 | + echo "passed=true" >> "$GITHUB_OUTPUT" |
| 179 | + fi |
| 180 | +
|
| 181 | + # ── Save artifacts ── |
| 182 | + - name: Upload verification artifacts |
| 183 | + uses: actions/upload-artifact@v4 |
| 184 | + with: |
| 185 | + name: verification-reports |
| 186 | + path: | |
| 187 | + test-report.json |
| 188 | + scripts/benchmark-report.json |
| 189 | + benchmark-output.txt |
| 190 | + retention-days: 90 |
| 191 | + |
| 192 | + # ───────────────────────────────────────────────────────────── |
| 193 | + # Phase 3: AI-powered discovery analysis (optional) |
| 194 | + # ───────────────────────────────────────────────────────────── |
| 195 | + analyze: |
| 196 | + name: AI Discovery Analysis |
| 197 | + needs: [detect, verify] |
| 198 | + if: | |
| 199 | + needs.detect.outputs.should_release == 'true' && |
| 200 | + inputs.skip_ai_analysis != 'true' |
| 201 | + runs-on: ubuntu-latest |
| 202 | + outputs: |
| 203 | + analysis: ${{ steps.ai.outputs.analysis }} |
| 204 | + steps: |
| 205 | + - uses: actions/checkout@v4 |
| 206 | + with: |
| 207 | + submodules: recursive |
| 208 | + |
| 209 | + - name: Analyze changes with Claude API |
| 210 | + id: ai |
| 211 | + env: |
| 212 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 213 | + run: | |
| 214 | + NEW_VERSION="${{ needs.detect.outputs.new_version }}" |
| 215 | + PREV_VERSION="${{ needs.detect.outputs.previous_version }}" |
| 216 | +
|
| 217 | + if [[ -z "${ANTHROPIC_API_KEY}" ]]; then |
| 218 | + echo "No ANTHROPIC_API_KEY. Skipping AI analysis." |
| 219 | + echo "analysis=AI analysis skipped (no API key configured)." >> "$GITHUB_OUTPUT" |
| 220 | + exit 0 |
| 221 | + fi |
| 222 | +
|
| 223 | + chmod +x scripts/analyze-discoveries.sh |
| 224 | + ANALYSIS=$(./scripts/analyze-discoveries.sh "${NEW_VERSION}" "${PREV_VERSION}" 2>/dev/null) || { |
| 225 | + echo "AI analysis failed. Continuing without it." |
| 226 | + ANALYSIS="AI analysis unavailable for this release." |
| 227 | + } |
| 228 | +
|
| 229 | + # Truncate to 4000 chars for GitHub output |
| 230 | + ANALYSIS="${ANALYSIS:0:4000}" |
| 231 | + # Use delimiter for multiline output |
| 232 | + echo "analysis<<ANALYSIS_EOF" >> "$GITHUB_OUTPUT" |
| 233 | + echo "${ANALYSIS}" >> "$GITHUB_OUTPUT" |
| 234 | + echo "ANALYSIS_EOF" >> "$GITHUB_OUTPUT" |
| 235 | +
|
| 236 | + # ───────────────────────────────────────────────────────────── |
| 237 | + # Phase 4: Publish verified release |
| 238 | + # ───────────────────────────────────────────────────────────── |
| 239 | + release: |
| 240 | + name: Publish Verified Release |
| 241 | + needs: [detect, verify, analyze] |
| 242 | + if: | |
| 243 | + always() && |
| 244 | + needs.detect.outputs.should_release == 'true' && |
| 245 | + needs.verify.result == 'success' |
| 246 | + runs-on: ubuntu-latest |
| 247 | + steps: |
| 248 | + - uses: actions/checkout@v4 |
| 249 | + with: |
| 250 | + submodules: recursive |
| 251 | + fetch-depth: 0 |
| 252 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 253 | + |
| 254 | + - name: Download verification artifacts |
| 255 | + uses: actions/download-artifact@v4 |
| 256 | + with: |
| 257 | + name: verification-reports |
| 258 | + |
| 259 | + - name: Configure git |
| 260 | + run: | |
| 261 | + git config user.name "github-actions[bot]" |
| 262 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 263 | +
|
| 264 | + - name: Update version state |
| 265 | + run: | |
| 266 | + NEW_VERSION="${{ needs.detect.outputs.new_version }}" |
| 267 | + echo "${NEW_VERSION}" > scripts/last-known-claude-version.txt |
| 268 | +
|
| 269 | + # Update benchmark baseline on successful release |
| 270 | + if [[ -f scripts/benchmark-report.json ]]; then |
| 271 | + cp scripts/benchmark-report.json scripts/benchmark-baseline.json |
| 272 | + fi |
| 273 | +
|
| 274 | + - name: Generate release tag |
| 275 | + id: tag |
| 276 | + run: | |
| 277 | + DATE_TAG=$(date -u +"%Y%m%d") |
| 278 | +
|
| 279 | + # Get current version from Cargo.toml |
| 280 | + CURRENT_VERSION=$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2) |
| 281 | + TAG="v${CURRENT_VERSION}-nightly.${DATE_TAG}" |
| 282 | +
|
| 283 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 284 | + echo "date_tag=${DATE_TAG}" >> "$GITHUB_OUTPUT" |
| 285 | + echo "Release tag: ${TAG}" |
| 286 | +
|
| 287 | + - name: Generate release notes |
| 288 | + id: notes |
| 289 | + run: | |
| 290 | + chmod +x scripts/generate-release-notes.sh |
| 291 | +
|
| 292 | + NEW_VERSION="${{ needs.detect.outputs.new_version }}" |
| 293 | + PREV_VERSION="${{ needs.detect.outputs.previous_version }}" |
| 294 | + TEST_COUNT="${{ needs.verify.outputs.test_count }}" |
| 295 | + AI_ANALYSIS="${{ needs.analyze.outputs.analysis }}" |
| 296 | +
|
| 297 | + # Generate base notes |
| 298 | + ./scripts/generate-release-notes.sh \ |
| 299 | + "${NEW_VERSION}" \ |
| 300 | + "test-report.json" \ |
| 301 | + "scripts/benchmark-report.json" > release-notes.md |
| 302 | +
|
| 303 | + # Append discovery section with version diff |
| 304 | + cat >> release-notes.md <<DISCOVERY |
| 305 | +
|
| 306 | + ## New Discoveries (v${NEW_VERSION} vs v${PREV_VERSION}) |
| 307 | +
|
| 308 | + ${AI_ANALYSIS:-No AI analysis available for this release.} |
| 309 | +
|
| 310 | + ### Version Comparison |
| 311 | + | Metric | Previous (v${PREV_VERSION}) | Current (v${NEW_VERSION}) | |
| 312 | + |--------|---------------------------|--------------------------| |
| 313 | + | Claude Code version | ${PREV_VERSION} | ${NEW_VERSION} | |
| 314 | + | RVM tests passing | ${TEST_COUNT:-797+} | ${TEST_COUNT:-797+} | |
| 315 | + | Regressions | 0 | 0 | |
| 316 | +
|
| 317 | + DISCOVERY |
| 318 | +
|
| 319 | + - name: Commit state updates |
| 320 | + run: | |
| 321 | + git add scripts/last-known-claude-version.txt |
| 322 | + git add scripts/benchmark-baseline.json 2>/dev/null || true |
| 323 | + git commit -m "chore(nightly): update state for Claude Code v${{ needs.detect.outputs.new_version }} |
| 324 | +
|
| 325 | + Nightly pipeline verified: ${{ needs.verify.outputs.test_count }} tests, 0 failures. |
| 326 | + Tag: ${{ steps.tag.outputs.tag }}" || echo "No state changes to commit." |
| 327 | + git push origin main |
| 328 | +
|
| 329 | + - name: Create and push tag |
| 330 | + run: | |
| 331 | + TAG="${{ steps.tag.outputs.tag }}" |
| 332 | + git tag -a "${TAG}" -m "Nightly verified release for Claude Code v${{ needs.detect.outputs.new_version }}" |
| 333 | + git push origin "${TAG}" |
| 334 | +
|
| 335 | + - name: Publish GitHub release |
| 336 | + env: |
| 337 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 338 | + run: | |
| 339 | + TAG="${{ steps.tag.outputs.tag }}" |
| 340 | +
|
| 341 | + gh release create "${TAG}" \ |
| 342 | + --title "RVM ${TAG}" \ |
| 343 | + --notes-file release-notes.md \ |
| 344 | + test-report.json \ |
| 345 | + scripts/benchmark-report.json 2>/dev/null || \ |
| 346 | + gh release create "${TAG}" \ |
| 347 | + --title "RVM ${TAG}" \ |
| 348 | + --notes-file release-notes.md |
| 349 | +
|
| 350 | + # ── Alert on failure (open issue) ── |
| 351 | + alert: |
| 352 | + name: Alert on Failure |
| 353 | + needs: [detect, verify] |
| 354 | + if: | |
| 355 | + always() && |
| 356 | + needs.detect.outputs.should_release == 'true' && |
| 357 | + needs.verify.result == 'failure' |
| 358 | + runs-on: ubuntu-latest |
| 359 | + steps: |
| 360 | + - uses: actions/checkout@v4 |
| 361 | + |
| 362 | + - name: Open failure issue |
| 363 | + env: |
| 364 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 365 | + run: | |
| 366 | + NEW_VERSION="${{ needs.detect.outputs.new_version }}" |
| 367 | + DATE=$(date -u +"%Y-%m-%d") |
| 368 | +
|
| 369 | + gh issue create \ |
| 370 | + --title "Nightly release blocked: verification failed (${DATE})" \ |
| 371 | + --body "## Nightly Release Failure |
| 372 | +
|
| 373 | + **Date:** ${DATE} |
| 374 | + **Claude Code version:** v${NEW_VERSION} |
| 375 | + **Pipeline run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 376 | +
|
| 377 | + The nightly verification pipeline detected a failure. The release was NOT published. |
| 378 | +
|
| 379 | + ### Investigation Required |
| 380 | + - Check test results in the Actions run above |
| 381 | + - Look for benchmark regressions (>5% threshold) |
| 382 | + - Verify \`cargo audit\` results |
| 383 | + - Check bare-metal build status |
| 384 | +
|
| 385 | + ### To Retry |
| 386 | + 1. Fix the issue |
| 387 | + 2. Run: \`gh workflow run nightly.yml -f force_release=true\` |
| 388 | +
|
| 389 | + --- |
| 390 | + *Automated issue from ADR-143 Nightly Verified Release Pipeline*" \ |
| 391 | + --label "bug,nightly" |
0 commit comments