|
| 1 | +name: Publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_bump: |
| 7 | + description: 'Version bump type' |
| 8 | + required: true |
| 9 | + default: 'patch' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + dry_run: |
| 16 | + description: 'Dry run (skip actual publish)' |
| 17 | + required: false |
| 18 | + default: false |
| 19 | + type: boolean |
| 20 | + |
| 21 | +jobs: |
| 22 | + publish: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + # Only allow publishing from master branch |
| 25 | + # TODO: Remove publish-actin before merging |
| 26 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/publish-actin' |
| 27 | + environment: release |
| 28 | + permissions: |
| 29 | + contents: write |
| 30 | + id-token: write |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - uses: actions/setup-node@v4 |
| 37 | + with: |
| 38 | + node-version: '20' |
| 39 | + cache: 'npm' |
| 40 | + registry-url: 'https://registry.npmjs.org' |
| 41 | + |
| 42 | + - name: Update npm for trusted publishing |
| 43 | + run: npm install -g npm@latest |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + run: npm ci |
| 47 | + |
| 48 | + - name: Run tests |
| 49 | + run: npm run test |
| 50 | + |
| 51 | + - name: Build |
| 52 | + run: npm run build |
| 53 | + |
| 54 | + - name: Configure git |
| 55 | + run: | |
| 56 | + git config user.name "github-actions[bot]" |
| 57 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 58 | +
|
| 59 | + - name: Bump version |
| 60 | + run: 'npm version ${{ inputs.version_bump }} -m "chore: release v%s"' |
| 61 | + |
| 62 | + - name: Push version commit and tag |
| 63 | + if: ${{ inputs.dry_run == false }} |
| 64 | + run: git push --follow-tags |
| 65 | + |
| 66 | + - name: Publish to npm |
| 67 | + if: ${{ inputs.dry_run == false }} |
| 68 | + # auth works by adding github.com/roboflow/inference-sdk-js as a trusted publisher in https://www.npmjs.com/package/@roboflow/inference-sdk |
| 69 | + run: npm publish --access public |
| 70 | + |
| 71 | + - name: Create GitHub Release |
| 72 | + if: ${{ inputs.dry_run == false }} |
| 73 | + run: | |
| 74 | + VERSION=$(node -p "require('./package.json').version") |
| 75 | + gh release create "v$VERSION" \ |
| 76 | + --title "v$VERSION" \ |
| 77 | + --generate-notes |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + |
| 81 | + - name: Dry run summary |
| 82 | + if: ${{ inputs.dry_run == true }} |
| 83 | + run: | |
| 84 | + echo "🧪 Dry run completed successfully!" |
| 85 | + echo "Version would be: $(node -p "require('./package.json').version")" |
| 86 | + echo "Package contents:" |
| 87 | + npm pack --dry-run |
0 commit comments