release.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. name: Release
  2. on:
  3. push:
  4. branches:
  5. - main
  6. workflow_dispatch:
  7. concurrency:
  8. group: ${{ github.workflow }}-${{ github.ref }}
  9. cancel-in-progress: false
  10. permissions:
  11. contents: read
  12. jobs:
  13. check-release:
  14. name: Check for new version
  15. runs-on: ubuntu-latest
  16. timeout-minutes: 5
  17. outputs:
  18. should_release: ${{ steps.check.outputs.should_release }}
  19. needs_github_release: ${{ steps.check.outputs.needs_github_release }}
  20. version: ${{ steps.check.outputs.version }}
  21. steps:
  22. - name: Checkout repository
  23. uses: actions/checkout@v4
  24. - name: Compare package.json version to npm and check GitHub release
  25. id: check
  26. run: |
  27. LOCAL_VERSION=$(node -p "require('./packages/core/package.json').version")
  28. echo "Local version: $LOCAL_VERSION"
  29. NPM_VERSION=$(npm view @json-render/core version 2>/dev/null || echo "0.0.0")
  30. echo "npm version: $NPM_VERSION"
  31. if [ "$LOCAL_VERSION" != "$NPM_VERSION" ]; then
  32. echo "Version changed: $NPM_VERSION -> $LOCAL_VERSION"
  33. echo "should_release=true" >> "$GITHUB_OUTPUT"
  34. echo "needs_github_release=true" >> "$GITHUB_OUTPUT"
  35. else
  36. echo "Version unchanged on npm, skipping build and publish"
  37. echo "should_release=false" >> "$GITHUB_OUTPUT"
  38. TAG="v$LOCAL_VERSION"
  39. if gh release view "$TAG" &>/dev/null; then
  40. echo "GitHub release $TAG exists"
  41. echo "needs_github_release=false" >> "$GITHUB_OUTPUT"
  42. else
  43. echo "GitHub release $TAG is missing, will create it"
  44. echo "needs_github_release=true" >> "$GITHUB_OUTPUT"
  45. fi
  46. fi
  47. echo "version=$LOCAL_VERSION" >> "$GITHUB_OUTPUT"
  48. env:
  49. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  50. publish:
  51. name: Publish to npm
  52. needs: check-release
  53. if: needs.check-release.outputs.should_release == 'true'
  54. runs-on: ubuntu-latest
  55. timeout-minutes: 15
  56. environment: Release
  57. permissions:
  58. contents: read
  59. id-token: write
  60. steps:
  61. - name: Checkout repository
  62. uses: actions/checkout@v4
  63. - name: Install pnpm
  64. uses: pnpm/action-setup@v4
  65. - name: Setup Node.js
  66. uses: actions/setup-node@v4
  67. with:
  68. node-version: 22
  69. cache: pnpm
  70. registry-url: "https://registry.npmjs.org"
  71. - name: Install dependencies
  72. run: pnpm install --frozen-lockfile
  73. - name: Build packages
  74. run: pnpm run build
  75. - name: Publish all public packages
  76. run: pnpm -r publish --provenance --no-git-checks --access public --filter '@json-render/*'
  77. github-release:
  78. name: Create GitHub Release
  79. needs: [check-release, publish]
  80. if: >-
  81. always()
  82. && needs.check-release.outputs.needs_github_release == 'true'
  83. && (needs.publish.result == 'success' || needs.publish.result == 'skipped')
  84. runs-on: ubuntu-latest
  85. timeout-minutes: 10
  86. permissions:
  87. contents: write
  88. steps:
  89. - name: Checkout repository
  90. uses: actions/checkout@v4
  91. - name: Extract changelog entry
  92. run: |
  93. VERSION="${{ needs.check-release.outputs.version }}"
  94. awk '/<!-- release:start -->/{found=1; next} /<!-- release:end -->/{found=0} found{print}' CHANGELOG.md > /tmp/release-notes.md
  95. LINES=$(wc -l < /tmp/release-notes.md | tr -d ' ')
  96. if [ "$LINES" -lt 2 ]; then
  97. echo "Error: No release notes found between <!-- release:start --> and <!-- release:end --> markers in CHANGELOG.md"
  98. exit 1
  99. fi
  100. echo "Extracted release notes for $VERSION ($LINES lines)"
  101. - name: Create GitHub Release
  102. run: |
  103. VERSION="${{ needs.check-release.outputs.version }}"
  104. TAG="v$VERSION"
  105. if gh release view "$TAG" &>/dev/null; then
  106. echo "Release $TAG already exists"
  107. else
  108. echo "Creating release $TAG..."
  109. gh release create "$TAG" \
  110. --title "$TAG" \
  111. --target ${{ github.sha }} \
  112. --notes-file /tmp/release-notes.md
  113. fi
  114. env:
  115. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}