1- name : Manual NPM Release
1+ name : NPM Release on PR Merge
22
33on :
4- workflow_dispatch :
5- inputs :
6- version_type :
7- description : ' Version bump type'
8- required : true
9- default : ' patch'
10- type : choice
11- options :
12- - patch
13- - minor
14- - major
15- dry_run :
16- description : ' Dry run (test without publishing)'
17- required : false
18- default : false
19- type : boolean
4+ pull_request :
5+ types : [closed]
6+ branches : [main]
207
218jobs :
229 release :
10+ if : github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
2311 runs-on : ubuntu-latest
12+ environment : github action
2413
2514 services :
2615 postgres :
3524 steps :
3625 - name : Checkout code
3726 uses : actions/checkout@v4
38- with :
39- token : ${{ secrets.GITHUB_TOKEN }}
4027
4128 - name : Setup Node.js
4229 uses : actions/setup-node@v4
@@ -47,40 +34,38 @@ jobs:
4734 - name : Install dependencies
4835 run : npm ci
4936
50- - name : Configure git
37+ - name : Get package version
38+ id : package_version
5139 run : |
52- git config --local user.email "action@github.com"
53- git config --local user.name "GitHub Action"
54-
55- - name : Bump version and create tag
56- id : version_bump
57- run : |
58- if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
59- echo "🧪 DRY RUN MODE"
60- NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
61- echo "Would bump to version: $NEW_VERSION"
62- git checkout -- package.json package-lock.json
63- else
64- NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }})
65- echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
66- git push origin main --follow-tags
67- fi
40+ VERSION=$(node -p "require('./package.json').version")
41+ echo "version=$VERSION" >> $GITHUB_OUTPUT
6842
6943 - name : Run tests
70- env :
71- POSTGRES_PORT : 5432
7244 run : npm test
7345
7446 - name : Build
7547 run : npm run build
7648
7749 - name : Publish to NPM
50+ run : npm publish
51+ env :
52+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
53+
54+ - name : Create tag
7855 run : |
79- if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
80- echo "🧪 DRY RUN: Would publish to NPM"
81- npm publish --access public --dry-run
82- else
83- npm publish --access public
84- fi
56+ git config --local user.email "action@github.com"
57+ git config --local user.name "GitHub Action"
58+ git tag "v${{ steps.package_version.outputs.version }}"
59+ git push origin "v${{ steps.package_version.outputs.version }}"
8560 env :
86- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
61+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
62+
63+ - name : Create GitHub Release
64+ uses : actions/create-release@v1
65+ env :
66+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67+ with :
68+ tag_name : " v${{ steps.package_version.outputs.version }}"
69+ release_name : Release "v${{ steps.package_version.outputs.version }}"
70+ draft : false
71+ prerelease : false
0 commit comments