release.yml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. name: Release & Publish
  2. on:
  3. push:
  4. tags:
  5. - 'v*'
  6. workflow_dispatch:
  7. inputs:
  8. version:
  9. description: 'Version to release (e.g., 1.2.3)'
  10. required: true
  11. type: string
  12. permissions:
  13. contents: write
  14. packages: write
  15. jobs:
  16. release:
  17. runs-on: ubuntu-latest
  18. steps:
  19. - uses: actions/checkout@v4
  20. with:
  21. fetch-depth: 0
  22. - name: Use Node.js 20.x
  23. uses: actions/setup-node@v4
  24. with:
  25. node-version: '20.x'
  26. registry-url: 'https://registry.npmjs.org'
  27. cache: 'npm'
  28. - name: Install dependencies
  29. run: npm ci
  30. - name: Run tests
  31. run: npm test
  32. - name: Run linter
  33. run: npm run lint
  34. - name: Build
  35. run: npm run build
  36. - name: Set version from input
  37. if: github.event_name == 'workflow_dispatch'
  38. run: |
  39. npm version ${{ github.event.inputs.version }} --no-git-tag-version
  40. echo "VERSION=v${{ github.event.inputs.version }}" >> $GITHUB_ENV
  41. - name: Set version from tag
  42. if: github.event_name == 'push'
  43. run: |
  44. echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
  45. TAG_VERSION=${GITHUB_REF#refs/tags/v}
  46. CURRENT_VERSION=$(node -p "require('./package.json').version")
  47. if [ "$TAG_VERSION" != "$CURRENT_VERSION" ]; then
  48. npm version $TAG_VERSION --no-git-tag-version
  49. fi
  50. - name: Create Release
  51. uses: softprops/action-gh-release@v2
  52. with:
  53. tag_name: ${{ env.VERSION }}
  54. name: Release ${{ env.VERSION }}
  55. body: |
  56. ## What's Changed
  57. **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.before }}...${{ env.VERSION }}
  58. draft: false
  59. prerelease: false
  60. - name: Publish to npm
  61. run: npm publish
  62. env:
  63. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  64. - name: Commit version bump
  65. if: github.event_name == 'workflow_dispatch'
  66. run: |
  67. git config --global user.name 'github-actions[bot]'
  68. git config --global user.email 'github-actions[bot]@users.noreply.github.com'
  69. git add package.json package-lock.json
  70. git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
  71. git push