| inputs: |
| 6 | version: |
| 7 | description: Package version in x.y.z format |
| 8 | required: true |
| 9 | type: string |
| 10 | provenance: |
| 11 | description: Include npm provenance attestation |
| 12 | required: false |
| 13 | default: false |
| 14 | type: boolean |
| 15 |
| 16 | permissions: |
| 17 | contents: write |
| 18 | id-token: write |
| 19 |
| 20 | jobs: |
| 21 | publish: |
| 22 | runs-on: ubuntu-latest |
| 23 |
| 24 | steps: |
| 25 | - name: Checkout |
| 26 | uses: actions/checkout@v7 |
| 27 | with: |
| 28 | fetch-depth: 0 |
| 29 |
| 30 | - name: Setup Node.js |
| 31 | uses: actions/setup-node@v7 |
| 32 | with: |
| 33 | node-version: lts/* |
| 34 | registry-url: https://registry.npmjs.org |
| 35 | package-manager-cache: false |
| 36 |
| 37 | - name: Validate version format |
| 38 | env: |
| 39 | VERSION: ${{ inputs.version }} |
| 40 | run: | |
| 41 | if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 42 | echo "Invalid version: $VERSION" |
| 43 | echo "Expected format: x.y.z" |
| 44 | exit 1 |
| 45 | fi |
| 46 |
| 47 | - name: Configure git user |
| 48 | run: | |
| 49 | git config user.name "github-actions[bot]" |
| 50 | git config user.email "github-actions[bot]@users.noreply.github.com" |
| 51 |
| 52 | - name: Ensure tag does not exist |
| 53 | env: |
| 54 | VERSION: ${{ inputs.version }} |
| 55 | run: | |
| 56 | if git rev-parse "v$VERSION" >/dev/null 2>&1; then |
| 57 | echo "Tag v$VERSION already exists" |
| 58 | exit 1 |
| 59 | fi |
| 60 |
| 61 | - name: Update package version and commit |
| 62 | env: |
| 63 | VERSION: ${{ inputs.version }} |
| 64 | run: | |
| 65 | npm version "$VERSION" --no-git-tag-version |
| 66 | git add package.json |
| 67 | git commit -m "chore(release): v$VERSION" |
| 68 |
| 69 | - name: Build package |
| 70 | run: | |
| 71 | npm install |
| 72 | npm run build |
| 73 |
| 74 | - name: Publish to npm |
| 75 | env: |
| 76 | PROVENANCE: ${{ inputs.provenance }} |
| 77 | run: | |
| 78 | if [[ "$PROVENANCE" == "true" ]]; then |
| 79 | npm publish --access public --provenance |
| 80 | else |
| 81 | npm publish --access public |
| 82 | fi |
| 83 |
| 84 | - name: Create and push tag |
| 85 | env: |
| 86 | VERSION: ${{ inputs.version }} |
| 87 | run: | |
| 88 | git tag "v$VERSION" |
| 89 | git push origin HEAD |
| 90 | git push origin "v$VERSION" |
| 91 |
| 92 | - name: Pack npm tarball |
| 93 | run: | |
| 94 | npm pack --pack-destination dist |
| 95 |
| 96 | - name: Create GitHub release |
| 97 | env: |
| 98 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | VERSION: ${{ inputs.version }} |
| 100 | run: | |
| 101 | gh release create "v$VERSION" \ |
| 102 | --title "v$VERSION" \ |
| 103 | --generate-notes \ |
| 104 | dist/*.tgz |
| 105 |