Publish to npm #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to npm | |
| on: | |
| release: | |
| types: [published] | |
| concurrency: | |
| group: npm-publish-${{ github.event.release.tag_name }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v5 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.22.1 | |
| registry-url: https://registry.npmjs.org | |
| cache: yarn | |
| - name: Set up Yarn | |
| run: | | |
| corepack enable | |
| corepack prepare yarn@1.22.22 --activate | |
| - name: Upgrade npm | |
| run: npm install -g npm@latest | |
| - name: Show tool versions | |
| run: | | |
| node --version | |
| npm --version | |
| yarn --version | |
| - name: Verify release tag matches package.json version | |
| shell: bash | |
| run: | | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" | |
| echo "package.json: $PKG_VERSION" | |
| echo "release tag: $TAG_VERSION" | |
| test "$PKG_VERSION" = "$TAG_VERSION" | |
| - name: Check if version already exists on npm | |
| shell: bash | |
| run: | | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then | |
| echo "Version already published: ${PACKAGE_NAME}@${PACKAGE_VERSION}" | |
| exit 1 | |
| fi | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Build package | |
| run: yarn build | |
| - name: Inspect publish contents | |
| run: npm pack --dry-run | |
| - name: Publish package | |
| run: npm publish --access public |