Add version command (#5) #8
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: [created] | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - 'package.json' | |
| branches: | |
| - main | |
| - master | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10.12.1 | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build project | |
| run: pnpm run build | |
| - name: Check if version already exists | |
| id: check-version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| PACKAGE_NAME=$(node -p "require('./package.json').name") | |
| if npm view ${PACKAGE_NAME}@${VERSION} version > /dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION already exists on npm, skipping publish" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Version $VERSION is new, will publish" | |
| fi | |
| - name: Publish to npm | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: npm publish --access public --provenance | |
| continue-on-error: false |