|
| 1 | +# Cut a GitHub Release for the WHOLE pi-dispatch tool when the ROOT package.json version changes on main. |
| 2 | +# |
| 3 | +# This is distinct from release.yml, which PUBLISHES the @edgehero/pi-dispatch-admin npm package (and tags |
| 4 | +# its own releases admin-v*). This workflow owns the v* tags = the product's releases. To cut one, bump |
| 5 | +# `version` in the root package.json in a PR; it is idempotent (skips when the tag already exists), so an |
| 6 | +# unrelated root package.json edit — a dependency bump, a script tweak — is a no-op. |
| 7 | +# |
| 8 | +# main is branch-protected (PR + 1 approving review), so a push here is an already-approved merge — nothing |
| 9 | +# here merges anything (CONST-MERGE-NEVER-AUTOMATIC). No secret is required to tag a release; the optional |
| 10 | +# repo secret ANTHROPIC_API_KEY enables AI-written notes, and without it the release falls back to a plain |
| 11 | +# commit list. Optional repo variable RELEASE_MODEL (default: claude-sonnet-5). |
| 12 | + |
| 13 | +name: repo-release |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches: [main] |
| 18 | + paths: |
| 19 | + - "package.json" # the ROOT one only (a bare path does not match nested workspace package.json files) |
| 20 | + - ".github/workflows/repo-release.yml" |
| 21 | + - ".github/scripts/release-notes.mjs" |
| 22 | + workflow_dispatch: {} |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: write # create tags + releases |
| 26 | + |
| 27 | +concurrency: |
| 28 | + group: repo-release |
| 29 | + cancel-in-progress: false |
| 30 | + |
| 31 | +jobs: |
| 32 | + release: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 # full history for the release-notes commit range |
| 38 | + |
| 39 | + - uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: "22.19" |
| 42 | + |
| 43 | + - name: Resolve version + decide release |
| 44 | + id: v |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ github.token }} |
| 47 | + run: | |
| 48 | + V=$(node -p "require('./package.json').version") |
| 49 | + echo "version=$V" >> "$GITHUB_OUTPUT" |
| 50 | + if gh release view "v$V" >/dev/null 2>&1; then |
| 51 | + echo "release=no" >> "$GITHUB_OUTPUT"; echo "release v$V already exists — skip" |
| 52 | + else |
| 53 | + echo "release=yes" >> "$GITHUB_OUTPUT" |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Build release notes |
| 57 | + if: steps.v.outputs.release == 'yes' |
| 58 | + env: |
| 59 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 60 | + RELEASE_MODEL: ${{ vars.RELEASE_MODEL }} |
| 61 | + run: | |
| 62 | + # Range since the previous tool release (v*); the whole repo, not just one workspace. |
| 63 | + PREV=$(git tag --list 'v*' --sort=-v:refname | head -n1) |
| 64 | + RANGE=${PREV:+$PREV..HEAD} |
| 65 | + COMMITS=$(git log $RANGE --no-merges --pretty=format:'- %s' | head -n 80) |
| 66 | + if [ -n "$ANTHROPIC_API_KEY" ] && COMMITS="$COMMITS" VERSION="v${{ steps.v.outputs.version }}" \ |
| 67 | + node .github/scripts/release-notes.mjs > /tmp/notes.md 2>/tmp/notes.err; then |
| 68 | + echo "release notes: AI-written" |
| 69 | + else |
| 70 | + echo "release notes: AI unavailable ($(head -n1 /tmp/notes.err 2>/dev/null)) — using commit list" |
| 71 | + { echo "### Changes"; echo; printf '%s\n' "$COMMITS"; } > /tmp/notes.md |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Create GitHub Release |
| 75 | + if: steps.v.outputs.release == 'yes' |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ github.token }} |
| 78 | + run: | |
| 79 | + gh release create "v${{ steps.v.outputs.version }}" \ |
| 80 | + --title "pi-dispatch v${{ steps.v.outputs.version }}" \ |
| 81 | + --notes-file /tmp/notes.md |
0 commit comments