11# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
22# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
33
4- name : Node.js Package
4+ name : Release Git Package & Publish on NPM
55
66on :
7- release :
8- types : [created]
7+ push :
8+ branches :
9+ - main
910
1011jobs :
11- build :
12+ release :
1213 runs-on : ubuntu-latest
14+
1315 steps :
14- - uses : actions/checkout@v4
15- - uses : actions/setup-node@v4
16+ # Checkout repo
17+ - name : Checkout code
18+ uses : actions/checkout@v4
19+
20+ # Setup Node.js
21+ - name : Setup Node.js
22+ uses : actions/setup-node@v4
1623 with :
17- node-version : 24
18- - run : npm run build
24+ node-version : ' 20 '
25+ registry-url : ' https://registry.npmjs.org/ '
1926
20- - name : Change directory to dist
21- run : cd dist
27+ # Install deps
28+ - name : Install dependencies
29+ run : npm install
2230
23- publish-npm :
24- needs : build
25- runs-on : ubuntu-latest
26- steps :
27- - uses : actions/checkout@v4
28- - uses : actions/setup-node@v4
31+ # Bump version dynamically & push tag
32+ - name : Bump version
33+ id : version
34+ run : |
35+ # Bump patch version (you can change to minor/major if needed)
36+ NEW_VERSION=$(npm version patch -m "chore(release): v%s [skip ci]")
37+ echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
38+
39+ # Push updated package.json and tag to main
40+ - name : Push changes
41+ uses : ad-m/github-push-action@v0.8.0
42+ with :
43+ github_token : ${{ secrets.GITHUB_TOKEN }}
44+ branch : main
45+ tags : true
46+
47+ # Create GitHub Release
48+ - name : Create GitHub Release
49+ uses : softprops/action-gh-release@v2
2950 with :
30- node-version : 24
31- registry-url : https://registry.npmjs.org/
32-
33- - name : Publish to npm
34- run : npm publish --access public
51+ tag_name : ${{ steps.version.outputs.new_version }}
52+ name : Release ${{ steps.version.outputs.new_version }}
53+ env :
54+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
55+
56+ # Publish to NPM
57+ - name : Publish to NPM
58+ run : npm publish
3559 env :
36- NODE_AUTH_TOKEN : ${{secrets.NPM_AUTH_TOKEN }}
60+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments