Skip to content

Commit 2f2a349

Browse files
committed
Create "publish" workflow
1 parent fce051b commit 2f2a349

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/publish.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
dry-run:
20+
description: 'Run in "dry run" mode'
21+
type: boolean
22+
default: false
23+
required: true
24+
25+
permissions:
26+
id-token: write
27+
contents: write
28+
29+
jobs:
30+
publish:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v5
36+
with:
37+
# Required to allow push to master without the checks/PR
38+
token: ${{ secrets.GH_PUSH_TOKEN }}
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v6
42+
with:
43+
node-version: '24'
44+
registry-url: 'https://registry.npmjs.org'
45+
46+
- name: Update npm
47+
run: npm install -g npm@latest
48+
49+
- name: Install dependencies
50+
run: npm install
51+
52+
- name: Verifying provenance attestations
53+
run: npm audit signatures
54+
55+
- name: Run tests
56+
run: npm test
57+
58+
- name: Bump version and create tag
59+
id: bump-version
60+
run: |
61+
git config --global user.name "github-actions[bot]"
62+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
63+
TAG=$(npm version ${{ github.event.inputs.bump }} -m "Release %s")
64+
echo "Created tag: $TAG"
65+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
66+
67+
- name: Push changes to master
68+
if: ${{ !inputs.dry-run }}
69+
run: |
70+
git push origin master --follow-tags
71+
72+
- name: Publish to npm
73+
env:
74+
DRY_RUN_FLAG: ${{ inputs.dry-run && '--dry-run' || '' }}
75+
run: npm publish --provenance --access=public $DRY_RUN_FLAG
76+
77+
- name: Create GitHub Release
78+
if: ${{ !inputs.dry-run }}
79+
uses: softprops/action-gh-release@v2
80+
with:
81+
tag_name: ${{ steps.bump-version.outputs.tag }}
82+
generate_release_notes: true
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)