Trigger npm publish on every push to main #1
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: | |
| push: | |
| tags: ['v*'] | |
| branches: [main] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| registry-url: https://registry.npmjs.org | |
| - run: npm ci | |
| - run: npm run typecheck | |
| - run: npm test | |
| - name: Check if version already published | |
| id: check | |
| run: | | |
| LOCAL=$(node -p "require('./package.json').version") | |
| REMOTE=$(npm view @oxgeneral/orch version 2>/dev/null || echo "0.0.0") | |
| if [ "$LOCAL" = "$REMOTE" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "Version $LOCAL already published — skipping" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Publishing $LOCAL (remote has $REMOTE)" | |
| fi | |
| - run: npm publish --access public | |
| if: steps.check.outputs.skip != 'true' | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |