|
| 1 | +name: Publish |
| 2 | +run-name: "${{ github.workflow }} (${{ github.ref_name }})" |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - v[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z0-9]+)? |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
| 12 | + |
| 13 | +jobs: |
| 14 | + validate: |
| 15 | + name: Validate Version |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 5 |
| 18 | + steps: |
| 19 | + - name: Checkout Repository |
| 20 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + |
| 24 | + - name: Extract version from tag |
| 25 | + id: tag_version |
| 26 | + run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 27 | + |
| 28 | + - name: Extract version from package.json |
| 29 | + id: pkg_version |
| 30 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 31 | + |
| 32 | + - name: Compare versions |
| 33 | + run: | |
| 34 | + if [ "${{ steps.tag_version.outputs.version }}" != "${{ steps.pkg_version.outputs.version }}" ]; then |
| 35 | + echo "Error: Tag version (${{ steps.tag_version.outputs.version }}) does not match package.json version (${{ steps.pkg_version.outputs.version }})" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + echo "Version validation successful: v${{ steps.pkg_version.outputs.version }}" |
| 39 | +
|
| 40 | + publish-npm: |
| 41 | + name: Publish to npm |
| 42 | + runs-on: ubuntu-latest |
| 43 | + timeout-minutes: 5 |
| 44 | + permissions: |
| 45 | + contents: write |
| 46 | + id-token: write |
| 47 | + environment: npm-registry |
| 48 | + needs: [validate] |
| 49 | + steps: |
| 50 | + - name: Checkout Repository |
| 51 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 52 | + with: |
| 53 | + persist-credentials: false |
| 54 | + |
| 55 | + - name: Initialize |
| 56 | + uses: ./.github/actions/setup-environment.yml |
| 57 | + |
| 58 | + - name: Run prepublishOnly |
| 59 | + run: bun run prepublishOnly |
| 60 | + |
| 61 | + - name: Setup Node.js |
| 62 | + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 |
| 63 | + with: |
| 64 | + node-version: lts/* |
| 65 | + registry-url: 'https://registry.npmjs.org' |
| 66 | + |
| 67 | + - name: Install latest npm |
| 68 | + run: npm install -g npm@latest |
| 69 | + |
| 70 | + - name: Publish to npm |
| 71 | + run: npm publish --provenance --access public |
| 72 | + |
| 73 | + - name: Create GitHub Release |
| 74 | + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 |
| 75 | + with: |
| 76 | + generate_release_notes: true |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments