release.yml 4.7 KB

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