Skip to content

Commit 6df80ed

Browse files
authored
Create publish.yml
Create publish.yml
1 parent 6349498 commit 6df80ed

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish Package to npmjs
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
push:
8+
branches:
9+
- main
10+
11+
# cancel previous runs if a new one is triggered
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
id-token: write
21+
steps:
22+
- uses: actions/checkout@v4
23+
# Setup .npmrc file to publish to npm
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: "22.x"
27+
registry-url: "https://registry.npmjs.org"
28+
- run: npm install
29+
30+
- name: Get version from package.json
31+
id: version
32+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
33+
34+
- name: Create Git tag
35+
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') && github.event_name != 'workflow_dispatch' }}
36+
run: |
37+
git config --local user.email "[email protected]"
38+
git config --local user.name "GitHub Action"
39+
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
40+
git push origin "v${{ steps.version.outputs.version }}"
41+
42+
- name: Create GitHub Release
43+
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') && github.event_name != 'workflow_dispatch' }}
44+
uses: softprops/action-gh-release@v1
45+
with:
46+
tag_name: v${{ steps.version.outputs.version }}
47+
name: Release v${{ steps.version.outputs.version }}
48+
generate_release_notes: true
49+
50+
- run: npm publish --provenance --access public
51+
# only if the commit message contains chore(release), or if manually triggered with workflow_dispatch
52+
if: ${{ contains(github.event.head_commit.message, 'chore(release)') || github.event_name == 'workflow_dispatch' }}
53+
env:
54+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)