1+ name : Publish Package to NPM
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : ' Version to publish (e.g., 1.0.0, patch, minor, major)'
8+ required : true
9+ default : ' patch'
10+ tag :
11+ description : ' NPM tag (e.g., latest, beta, next)'
12+ required : true
13+ default : ' latest'
14+
15+ jobs :
16+ publish :
17+ runs-on : ubuntu-latest
18+ steps :
19+ - uses : actions/checkout@v4
20+ with :
21+ # This ensures complete repo history for version management
22+ fetch-depth : 0
23+
24+ - name : Setup Node.js
25+ uses : actions/setup-node@v4
26+ with :
27+ node-version : ' 20.x'
28+ registry-url : ' https://registry.npmjs.org'
29+ cache : ' npm'
30+
31+ - name : Install dependencies
32+ run : npm ci
33+
34+ - name : Set custom version
35+ id : set-version
36+ run : |
37+ # For semantic versioning keywords (patch, minor, major)
38+ if [[ "${{ github.event.inputs.version }}" =~ ^(patch|minor|major)$ ]]; then
39+ npm version ${{ github.event.inputs.version }} --no-git-tag-version
40+ # For explicit versions (e.g., 1.0.0)
41+ else
42+ npm version ${{ github.event.inputs.version }} --no-git-tag-version --allow-same-version
43+ fi
44+ echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
45+
46+ - name : Build package
47+ run : npm run build
48+
49+ - name : Run tests
50+ run : npm test
51+
52+ - name : Publish to NPM
53+ run : npm publish --tag ${{ github.event.inputs.tag }}
54+ env :
55+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
56+
57+ - name : Create Git tag
58+ run : |
59+ git config --local user.email "[email protected] " 60+ git config --local user.name "nclsndr"
61+ git tag -a v${{ steps.set-version.outputs.new_version }} -m "Release v${{ steps.set-version.outputs.new_version }}"
62+ git push origin v${{ steps.set-version.outputs.new_version }}
63+ env :
64+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments