1
0

release.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. # Tag the current commit with the version in package.json and publish a
  3. # matching GitHub Release whose body is the corresponding CHANGELOG.md entry.
  4. #
  5. # Run AFTER you have:
  6. # - bumped package.json
  7. # - added a `## [X.Y.Z] - YYYY-MM-DD` block at the top of CHANGELOG.md
  8. # - committed, pushed to origin, and run `npm publish`
  9. #
  10. # Idempotent: safe to re-run after a partial failure. Skips steps that are
  11. # already done (tag created, tag pushed, release published).
  12. #
  13. # Usage: ./scripts/release.sh
  14. set -euo pipefail
  15. cd "$(dirname "$0")/.."
  16. VERSION=$(node -p "require('./package.json').version")
  17. TAG="v${VERSION}"
  18. REPO=$(git remote get-url origin | sed -E 's|.*github\.com[:/]||; s|\.git$||')
  19. if [ -z "${REPO}" ]; then
  20. echo "error: could not derive owner/repo from origin remote URL" >&2
  21. exit 1
  22. fi
  23. if ! grep -q "^## \[${VERSION}\]" CHANGELOG.md; then
  24. echo "error: no '## [${VERSION}]' entry found in CHANGELOG.md" >&2
  25. exit 1
  26. fi
  27. # Extract notes with paragraph unwrapping — GitHub Releases render with
  28. # GFM hard-breaks, so the CHANGELOG's hard-wrapped lines would show as
  29. # visible `<br>` breaks otherwise. The helper joins continuation lines
  30. # into a single line per bullet.
  31. NOTES=$(node scripts/extract-release-notes.mjs "${VERSION}")
  32. if [ -z "${NOTES}" ]; then
  33. echo "error: failed to extract changelog notes for ${VERSION}" >&2
  34. exit 1
  35. fi
  36. if git rev-parse "${TAG}" >/dev/null 2>&1; then
  37. echo "✓ tag ${TAG} already exists locally"
  38. else
  39. echo "→ tagging ${TAG}"
  40. git tag "${TAG}"
  41. fi
  42. if git ls-remote --exit-code --tags origin "${TAG}" >/dev/null 2>&1; then
  43. echo "✓ tag ${TAG} already on origin"
  44. else
  45. echo "→ pushing ${TAG} to origin"
  46. git push origin "${TAG}"
  47. fi
  48. if gh release view "${TAG}" --repo "${REPO}" >/dev/null 2>&1; then
  49. echo "✓ release ${TAG} already published"
  50. else
  51. echo "→ creating GitHub Release ${TAG} on ${REPO}"
  52. gh release create "${TAG}" \
  53. --repo "${REPO}" \
  54. --title "${TAG}" \
  55. --notes "${NOTES}"
  56. fi
  57. echo "done: https://github.com/${REPO}/releases/tag/${TAG}"