Skip to content

Commit 1cd5fe7

Browse files
ci: automate npm publishing on push to master
1 parent 1f00de0 commit 1cd5fe7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/publish.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
name: Publish to npm
22

33
on:
4+
push:
5+
branches: [master]
46
release:
57
types: [published]
8+
workflow_dispatch:
69

710
permissions:
811
contents: read
912

1013
jobs:
1114
publish:
1215
runs-on: ubuntu-latest
16+
# Only publish if it's a push to master or a release
17+
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/master')
1318

1419
steps:
1520
- uses: actions/checkout@v4
@@ -30,7 +35,9 @@ jobs:
3035
- name: Test
3136
run: npm test
3237

33-
- name: Publish
34-
run: npm publish --access public
38+
- name: Publish to npm
39+
run: |
40+
# Try to publish, but don't fail if the version is already published
41+
npm publish --access public || echo "Version already published or publish failed. Skipping."
3542
env:
3643
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)