Publish to npm #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: | |
| workflow_dispatch: | |
| inputs: | |
| version_bump: | |
| description: 'Version bump type' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| dry_run: | |
| description: 'Dry run (skip actual publish)' | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| # Only allow publishing from master branch | |
| # TODO: Remove publish-actin before merging | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/publish-actin' | |
| environment: release | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update npm for trusted publishing | |
| run: npm install -g npm@latest | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm run test | |
| - name: Build | |
| run: npm run build | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Bump version | |
| run: 'npm version ${{ inputs.version_bump }} -m "chore: release v%s"' | |
| - name: Push version commit and tag | |
| if: ${{ inputs.dry_run == false }} | |
| run: git push --follow-tags | |
| - name: Publish to npm | |
| if: ${{ inputs.dry_run == false }} | |
| # auth works by adding github.com/roboflow/inference-sdk-js as a trusted publisher in https://www.npmjs.com/package/@roboflow/inference-sdk | |
| run: npm publish --access public | |
| - name: Create GitHub Release | |
| if: ${{ inputs.dry_run == false }} | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| gh release create "v$VERSION" \ | |
| --title "v$VERSION" \ | |
| --generate-notes | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Dry run summary | |
| if: ${{ inputs.dry_run == true }} | |
| run: | | |
| echo "🧪 Dry run completed successfully!" | |
| echo "Version would be: $(node -p "require('./package.json').version")" | |
| echo "Package contents:" | |
| npm pack --dry-run |