1
0

release.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. name: Release
  2. # Manually triggered ("Run workflow"). On trigger it:
  3. # 1. reads the version from package.json,
  4. # 2. promotes `## [Unreleased]` content into `## [<version>]` in
  5. # CHANGELOG.md (and commits + pushes that change back to main), so
  6. # the published release notes are never sparse just because the
  7. # maintainer didn't pre-stage the [<version>] block by hand,
  8. # 3. builds a self-contained bundle for every platform (one runner — there's no
  9. # native compilation, so cross-packaging is fine),
  10. # 4. creates the GitHub Release (tag v<version>) with all archives, using the
  11. # release notes from CHANGELOG.md,
  12. # 5. publishes the npm thin-installer (shim + per-platform packages).
  13. #
  14. # Before triggering: bump package.json. CHANGELOG.md entries can live under
  15. # `## [Unreleased]` — step 2 takes care of moving them. Set the NPM_TOKEN secret.
  16. on:
  17. workflow_dispatch: {}
  18. permissions:
  19. contents: write # create the GitHub Release + tag, push the CHANGELOG promote
  20. jobs:
  21. release:
  22. runs-on: ubuntu-latest
  23. steps:
  24. - uses: actions/checkout@v6
  25. with:
  26. # Default checkout is detached at a SHA; we need an actual branch
  27. # so the CHANGELOG-promote commit knows where to push.
  28. ref: ${{ github.ref }}
  29. - uses: actions/setup-node@v6
  30. with:
  31. node-version: 22
  32. registry-url: https://registry.npmjs.org
  33. - name: Sync package-lock.json if version drifted
  34. # When the maintainer bumps the version on package.json only — for
  35. # example via a GitHub web-UI edit — `npm ci` would refuse to run
  36. # with `EUSAGE: npm ci can only install packages when your
  37. # package.json and package-lock.json … are in sync`. This step
  38. # rewrites just the lock-file's version fields (top-level + the
  39. # `packages.""` entry) to match package.json, then auto-commits
  40. # and pushes the result so on-disk truth on `main` stays
  41. # consistent. Idempotent: if the lock file already matches, no
  42. # commit is made.
  43. run: |
  44. set -euo pipefail
  45. PKG_V=$(node -p "require('./package.json').version")
  46. LOCK_V=$(node -p "require('./package-lock.json').version")
  47. if [ "$PKG_V" = "$LOCK_V" ]; then
  48. echo "package-lock.json already at $PKG_V — nothing to sync."
  49. exit 0
  50. fi
  51. echo "Lock-file version drift: lock=$LOCK_V, package=$PKG_V. Syncing."
  52. # `--package-lock-only` rewrites only the lock file, doesn't
  53. # touch node_modules or actually install anything. Cheap.
  54. npm install --package-lock-only --ignore-scripts
  55. # Sanity: lockfile should now report the package version.
  56. NEW_LOCK_V=$(node -p "require('./package-lock.json').version")
  57. if [ "$NEW_LOCK_V" != "$PKG_V" ]; then
  58. echo "::error::lock-file still at $NEW_LOCK_V after sync attempt; expected $PKG_V"; exit 1
  59. fi
  60. if git diff --quiet -- package-lock.json; then
  61. echo "lock file unchanged after sync? bailing"; exit 1
  62. fi
  63. git config user.name "github-actions[bot]"
  64. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  65. git add package-lock.json
  66. git commit -m "release: sync package-lock.json to ${PKG_V}" -m "[skip ci] Auto-generated by Release workflow."
  67. git push origin "HEAD:${GITHUB_REF#refs/heads/}"
  68. - run: npm ci
  69. - name: Ensure zip/unzip
  70. run: sudo apt-get update -qq && sudo apt-get install -y -qq zip unzip
  71. - name: Resolve version
  72. id: ver
  73. run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
  74. - name: Promote [Unreleased] → [<version>] in CHANGELOG.md
  75. # Idempotent: a no-op if [Unreleased] is empty OR if the previous
  76. # run already moved everything. Auto-commit + push the change back
  77. # so the version block on main is the source of truth going
  78. # forward (and so subsequent extract-release-notes.mjs calls
  79. # surface the full content even if this run is re-triggered).
  80. run: |
  81. set -euo pipefail
  82. V="${{ steps.ver.outputs.version }}"
  83. before=$(git rev-parse HEAD)
  84. node scripts/prepare-release.mjs "$V"
  85. if git diff --quiet -- CHANGELOG.md; then
  86. echo "CHANGELOG.md unchanged — nothing to commit."
  87. else
  88. git config user.name "github-actions[bot]"
  89. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  90. git add CHANGELOG.md
  91. git commit -m "docs(changelog): promote [Unreleased] into [${V}]" -m "[skip ci] Auto-generated by Release workflow."
  92. # Push to the branch the workflow was triggered on (main).
  93. git push origin "HEAD:${GITHUB_REF#refs/heads/}"
  94. fi
  95. - name: Build all platform bundles
  96. run: |
  97. for t in darwin-arm64 darwin-x64 linux-x64 linux-arm64 win32-x64 win32-arm64; do
  98. bash scripts/build-bundle.sh "$t"
  99. done
  100. ls -lh release
  101. - name: Generate SHA256SUMS
  102. # Published as a release asset; the npm launcher verifies downloaded
  103. # bundles against it (basenames only, so its path.basename match works).
  104. run: |
  105. ( cd release && sha256sum codegraph-* > SHA256SUMS )
  106. cat release/SHA256SUMS
  107. - name: Release notes from CHANGELOG.md
  108. # The [<version>] block was guaranteed-populated by the
  109. # "Promote" step above, so the [Unreleased] fallback should
  110. # never be needed in practice. Kept for defense-in-depth.
  111. run: |
  112. V="${{ steps.ver.outputs.version }}"
  113. node scripts/extract-release-notes.mjs "$V" > notes.md 2>/dev/null \
  114. || node scripts/extract-release-notes.mjs Unreleased > notes.md 2>/dev/null || true
  115. if [ ! -s notes.md ]; then
  116. echo "::error::No release notes in CHANGELOG.md for [$V] or [Unreleased]."
  117. exit 1
  118. fi
  119. echo "----- release notes -----"; cat notes.md
  120. - name: Create GitHub Release
  121. env:
  122. GH_TOKEN: ${{ github.token }}
  123. run: |
  124. TAG="v${{ steps.ver.outputs.version }}"
  125. # Idempotent: create the release once, otherwise (re-run) refresh assets.
  126. if gh release view "$TAG" >/dev/null 2>&1; then
  127. gh release upload "$TAG" release/codegraph-* release/SHA256SUMS --clobber
  128. else
  129. gh release create "$TAG" release/codegraph-* release/SHA256SUMS --title "$TAG" --notes-file notes.md
  130. fi
  131. - name: Publish to npm
  132. env:
  133. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  134. run: |
  135. V="${{ steps.ver.outputs.version }}"
  136. bash scripts/pack-npm.sh "$V"
  137. # Platform packages first, then the main shim (which depends on them).
  138. # Skip any already on the registry so a re-run only fills in gaps.
  139. for dir in release/npm/codegraph-* release/npm/main; do
  140. name=$(node -p "require('./$dir/package.json').name")
  141. if npm view "$name@$V" version >/dev/null 2>&1; then
  142. echo "skip $name@$V (already published)"
  143. else
  144. echo "publishing $name@$V"
  145. ( cd "$dir" && npm publish --access public )
  146. fi
  147. done
  148. - name: Verify every package is actually on the registry
  149. run: |
  150. V="${{ steps.ver.outputs.version }}"
  151. # npm publish can print success without persisting; confirm against the
  152. # registry (with retries for propagation) so green means really shipped.
  153. for dir in release/npm/codegraph-* release/npm/main; do
  154. name=$(node -p "require('./$dir/package.json').name")
  155. ok=
  156. for i in 1 2 3 4 5 6; do
  157. if npm view "$name@$V" version >/dev/null 2>&1; then ok=1; break; fi
  158. echo "waiting for $name@$V to appear ($i)…"; sleep 10
  159. done
  160. [ -n "$ok" ] || { echo "::error::$name@$V never appeared on the registry"; exit 1; }
  161. echo "verified $name@$V"
  162. done
  163. - name: Sync packages to npmmirror
  164. # npmmirror/cnpm mirror lazily and frequently never pull the per-platform
  165. # optionalDependencies on their own, so `npm i` there fails with
  166. # "no prebuilt bundle" (issue #303). Nudge a sync now so mirror users get
  167. # the bundle without waiting. Best-effort — the launcher also self-heals
  168. # from GitHub Releases — so a mirror hiccup never fails the release.
  169. continue-on-error: true
  170. run: |
  171. for dir in release/npm/codegraph-* release/npm/main; do
  172. name=$(node -p "require('./$dir/package.json').name")
  173. enc=$(node -p "encodeURIComponent(require('./$dir/package.json').name)")
  174. echo "sync $name"
  175. curl -s -X PUT "https://registry.npmmirror.com/-/package/$enc/syncs" || true
  176. echo
  177. done