Skip to content

Commit d28d546

Browse files
committed
ci: add GitHub Actions workflow to publish to npm on production merge
1 parent cc9d6ba commit d28d546

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish to npm
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- production
8+
9+
jobs:
10+
publish:
11+
if: github.event.pull_request.merged == true
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
registry-url: 'https://registry.npmjs.org'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Build
28+
run: npm run build
29+
30+
- name: Get package version
31+
id: pkg
32+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
33+
34+
- name: Publish to npm
35+
run: npm publish --access public
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38+
39+
- name: Create GitHub release
40+
uses: softprops/action-gh-release@v2
41+
with:
42+
tag_name: v${{ steps.pkg.outputs.version }}
43+
name: v${{ steps.pkg.outputs.version }}
44+
body: |
45+
Published from PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}
46+
generate_release_notes: true

0 commit comments

Comments
 (0)