|
| 1 | +name: Create a tag and publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: 'Version bump type' |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + default: 'minor' |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + - premajor |
| 16 | + - preminor |
| 17 | + - prepatch |
| 18 | + - prerelease |
| 19 | + preid: |
| 20 | + description: 'Prerelease identifier (see "npm version") for pre* bumps' |
| 21 | + type: string |
| 22 | + required: false |
| 23 | + npmPreTag: |
| 24 | + description: 'NPM tag used for all pre* bumps' |
| 25 | + type: string |
| 26 | + default: 'next' |
| 27 | + required: false |
| 28 | + dryRun: |
| 29 | + description: 'Run in "dry run" mode' |
| 30 | + type: boolean |
| 31 | + default: false |
| 32 | + required: true |
| 33 | + |
| 34 | +permissions: |
| 35 | + id-token: write |
| 36 | + contents: write |
| 37 | + |
| 38 | +jobs: |
| 39 | + publish: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v5 |
| 45 | + with: |
| 46 | + # Required to allow push to master without the checks/PR |
| 47 | + token: ${{ secrets.GH_PUSH_TOKEN }} |
| 48 | + |
| 49 | + - name: Set up Node.js |
| 50 | + uses: actions/setup-node@v6 |
| 51 | + with: |
| 52 | + node-version: '24' |
| 53 | + registry-url: 'https://registry.npmjs.org' |
| 54 | + |
| 55 | + - name: Update npm |
| 56 | + run: npm install -g npm@latest |
| 57 | + |
| 58 | + - name: Install dependencies |
| 59 | + run: npm install |
| 60 | + |
| 61 | + - name: List of installed dependencies |
| 62 | + run: npm ls -a |
| 63 | + |
| 64 | + - name: Verifying provenance attestations |
| 65 | + run: npm audit signatures |
| 66 | + |
| 67 | + - name: Run tests |
| 68 | + run: npm test |
| 69 | + |
| 70 | + - name: Bump version and create tag |
| 71 | + id: bump-version |
| 72 | + env: |
| 73 | + PREID_FLAG: ${{ startsWith(inputs.bump, 'pre') && inputs.preid && format('--preid {0}', inputs.preid) || '' }} |
| 74 | + run: | |
| 75 | + git config --global user.name "github-actions[bot]" |
| 76 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 77 | + TAG=$(npm version ${{ github.event.inputs.bump }} $PREID_FLAG -m "Release %s") |
| 78 | + echo "Created tag: $TAG" |
| 79 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 80 | +
|
| 81 | + - name: Publish to npm |
| 82 | + env: |
| 83 | + DRY_RUN_FLAG: ${{ inputs.dryRun && '--dry-run' || '' }} |
| 84 | + TAG_FLAG: ${{ startsWith(inputs.bump, 'pre') && format('--tag {0}', inputs.npmPreTag) || ''}} |
| 85 | + run: npm publish --provenance --access=public $DRY_RUN_FLAG $TAG_FLAG |
| 86 | + |
| 87 | + - name: Push changes to master |
| 88 | + if: ${{ !inputs.dryRun }} |
| 89 | + run: | |
| 90 | + git push origin master --follow-tags |
| 91 | +
|
| 92 | + - name: Create GitHub Release |
| 93 | + if: ${{ !inputs.dryRun }} |
| 94 | + uses: softprops/action-gh-release@v2 |
| 95 | + with: |
| 96 | + tag_name: ${{ steps.bump-version.outputs.tag }} |
| 97 | + generate_release_notes: true |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments