1
0

release.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. - run: npm ci
  34. - name: Ensure zip/unzip
  35. run: sudo apt-get update -qq && sudo apt-get install -y -qq zip unzip
  36. - name: Resolve version
  37. id: ver
  38. run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
  39. - name: Promote [Unreleased] → [<version>] in CHANGELOG.md
  40. # Idempotent: a no-op if [Unreleased] is empty OR if the previous
  41. # run already moved everything. Auto-commit + push the change back
  42. # so the version block on main is the source of truth going
  43. # forward (and so subsequent extract-release-notes.mjs calls
  44. # surface the full content even if this run is re-triggered).
  45. run: |
  46. set -euo pipefail
  47. V="${{ steps.ver.outputs.version }}"
  48. before=$(git rev-parse HEAD)
  49. node scripts/prepare-release.mjs "$V"
  50. if git diff --quiet -- CHANGELOG.md; then
  51. echo "CHANGELOG.md unchanged — nothing to commit."
  52. else
  53. git config user.name "github-actions[bot]"
  54. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  55. git add CHANGELOG.md
  56. git commit -m "docs(changelog): promote [Unreleased] into [${V}]" -m "[skip ci] Auto-generated by Release workflow."
  57. # Push to the branch the workflow was triggered on (main).
  58. git push origin "HEAD:${GITHUB_REF#refs/heads/}"
  59. fi
  60. - name: Build all platform bundles
  61. run: |
  62. for t in darwin-arm64 darwin-x64 linux-x64 linux-arm64 win32-x64 win32-arm64; do
  63. bash scripts/build-bundle.sh "$t"
  64. done
  65. ls -lh release
  66. - name: Generate SHA256SUMS
  67. # Published as a release asset; the npm launcher verifies downloaded
  68. # bundles against it (basenames only, so its path.basename match works).
  69. run: |
  70. ( cd release && sha256sum codegraph-* > SHA256SUMS )
  71. cat release/SHA256SUMS
  72. - name: Release notes from CHANGELOG.md
  73. # The [<version>] block was guaranteed-populated by the
  74. # "Promote" step above, so the [Unreleased] fallback should
  75. # never be needed in practice. Kept for defense-in-depth.
  76. run: |
  77. V="${{ steps.ver.outputs.version }}"
  78. node scripts/extract-release-notes.mjs "$V" > notes.md 2>/dev/null \
  79. || node scripts/extract-release-notes.mjs Unreleased > notes.md 2>/dev/null || true
  80. if [ ! -s notes.md ]; then
  81. echo "::error::No release notes in CHANGELOG.md for [$V] or [Unreleased]."
  82. exit 1
  83. fi
  84. echo "----- release notes -----"; cat notes.md
  85. - name: Create GitHub Release
  86. env:
  87. GH_TOKEN: ${{ github.token }}
  88. run: |
  89. TAG="v${{ steps.ver.outputs.version }}"
  90. # Idempotent: create the release once, otherwise (re-run) refresh assets.
  91. if gh release view "$TAG" >/dev/null 2>&1; then
  92. gh release upload "$TAG" release/codegraph-* release/SHA256SUMS --clobber
  93. else
  94. gh release create "$TAG" release/codegraph-* release/SHA256SUMS --title "$TAG" --notes-file notes.md
  95. fi
  96. - name: Publish to npm
  97. env:
  98. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  99. run: |
  100. V="${{ steps.ver.outputs.version }}"
  101. bash scripts/pack-npm.sh "$V"
  102. # Platform packages first, then the main shim (which depends on them).
  103. # Skip any already on the registry so a re-run only fills in gaps.
  104. for dir in release/npm/codegraph-* release/npm/main; do
  105. name=$(node -p "require('./$dir/package.json').name")
  106. if npm view "$name@$V" version >/dev/null 2>&1; then
  107. echo "skip $name@$V (already published)"
  108. else
  109. echo "publishing $name@$V"
  110. ( cd "$dir" && npm publish --access public )
  111. fi
  112. done
  113. - name: Verify every package is actually on the registry
  114. run: |
  115. V="${{ steps.ver.outputs.version }}"
  116. # npm publish can print success without persisting; confirm against the
  117. # registry (with retries for propagation) so green means really shipped.
  118. for dir in release/npm/codegraph-* release/npm/main; do
  119. name=$(node -p "require('./$dir/package.json').name")
  120. ok=
  121. for i in 1 2 3 4 5 6; do
  122. if npm view "$name@$V" version >/dev/null 2>&1; then ok=1; break; fi
  123. echo "waiting for $name@$V to appear ($i)…"; sleep 10
  124. done
  125. [ -n "$ok" ] || { echo "::error::$name@$V never appeared on the registry"; exit 1; }
  126. echo "verified $name@$V"
  127. done
  128. - name: Sync packages to npmmirror
  129. # npmmirror/cnpm mirror lazily and frequently never pull the per-platform
  130. # optionalDependencies on their own, so `npm i` there fails with
  131. # "no prebuilt bundle" (issue #303). Nudge a sync now so mirror users get
  132. # the bundle without waiting. Best-effort — the launcher also self-heals
  133. # from GitHub Releases — so a mirror hiccup never fails the release.
  134. continue-on-error: true
  135. run: |
  136. for dir in release/npm/codegraph-* release/npm/main; do
  137. name=$(node -p "require('./$dir/package.json').name")
  138. enc=$(node -p "encodeURIComponent(require('./$dir/package.json').name)")
  139. echo "sync $name"
  140. curl -s -X PUT "https://registry.npmmirror.com/-/package/$enc/syncs" || true
  141. echo
  142. done