release.yml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. npm version ${GITHUB_REF#refs/tags/v} --no-git-tag-version
  46. - name: Create Release
  47. uses: softprops/action-gh-release@v2
  48. with:
  49. tag_name: ${{ env.VERSION }}
  50. name: Release ${{ env.VERSION }}
  51. body: |
  52. ## What's Changed
  53. **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.event.before }}...${{ env.VERSION }}
  54. draft: false
  55. prerelease: false
  56. - name: Publish to npm
  57. run: npm publish
  58. env:
  59. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  60. - name: Commit version bump
  61. if: github.event_name == 'workflow_dispatch'
  62. run: |
  63. git config --global user.name 'github-actions[bot]'
  64. git config --global user.email 'github-actions[bot]@users.noreply.github.com'
  65. git add package.json package-lock.json
  66. git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
  67. git push