|
| 1 | +name: Publish package to npmjs registry |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [published] |
| 5 | + |
| 6 | +jobs: |
| 7 | + publish-npm: |
| 8 | + if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }} |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + id-token: write |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v7 |
| 15 | + with: |
| 16 | + ref: ${{ github.event.release.tag_name }} |
| 17 | + persist-credentials: false |
| 18 | + - uses: actions/setup-node@v7 |
| 19 | + with: |
| 20 | + node-version: 24 |
| 21 | + registry-url: https://registry.npmjs.org/ |
| 22 | + cache: 'npm' |
| 23 | + - name: Check the release tag matches package.json |
| 24 | + env: |
| 25 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 26 | + run: | |
| 27 | + PKG_VERSION="v$(node -p "require('./package.json').version")" |
| 28 | + if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then |
| 29 | + echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + - run: npm ci |
| 33 | + - name: Update npm |
| 34 | + run: npm install -g npm@latest |
| 35 | + - name: Release |
| 36 | + run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }} |
| 37 | + |
| 38 | + publish-github: |
| 39 | + if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }} |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + packages: write |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v7 |
| 46 | + with: |
| 47 | + ref: ${{ github.event.release.tag_name }} |
| 48 | + persist-credentials: false |
| 49 | + - uses: actions/setup-node@v7 |
| 50 | + with: |
| 51 | + node-version: 24 |
| 52 | + registry-url: https://npm.pkg.github.com/ |
| 53 | + cache: 'npm' |
| 54 | + - name: Check the release tag matches package.json |
| 55 | + env: |
| 56 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 57 | + run: | |
| 58 | + PKG_VERSION="v$(node -p "require('./package.json').version")" |
| 59 | + if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then |
| 60 | + echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + - run: npm ci |
| 64 | + - name: Update npm |
| 65 | + run: npm install -g npm@latest |
| 66 | + - name: Release |
| 67 | + run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }} |
| 68 | + env: |
| 69 | + NODE_AUTH_TOKEN: ${{ github.token }} |
0 commit comments