11name : Release
22
33on :
4- push :
5- tags :
6- - ' v*'
4+ workflow_dispatch :
5+ inputs :
6+ release_type :
7+ description : ' Release type'
8+ required : true
9+ default : ' patch'
10+ type : choice
11+ options :
12+ - patch
13+ - minor
14+ - major
15+ - prerelease
16+
17+ env :
18+ NODE_VERSION : ' 22'
719
820jobs :
921 release :
10- name : Release
22+ name : Create Release
1123 runs-on : ubuntu-latest
1224 permissions :
13- contents : read
14- id-token : write # For npm provenance
15-
25+ contents : write
26+ issues : write
27+ pull-requests : write
1628 steps :
1729 - name : Checkout code
1830 uses : actions/checkout@v4
19-
20- - name : Install pnpm
31+ with :
32+ fetch-depth : 0
33+ token : ${{ secrets.GITHUB_TOKEN }}
34+
35+ - name : Setup pnpm
2136 uses : pnpm/action-setup@v4
2237 with :
23- version : 9
24-
38+ version : latest
39+
2540 - name : Setup Node.js
2641 uses : actions/setup-node@v4
2742 with :
28- node-version : 20
43+ node-version : ${{ env.NODE_VERSION }}
2944 cache : ' pnpm'
30- registry-url : ' https://registry.npmjs.org'
31-
45+
3246 - name : Install dependencies
3347 run : pnpm install --frozen-lockfile
34-
48+
3549 - name : Run tests
36- run : pnpm test:run
37-
38- - name : Build package
39- run : pnpm build
40-
41- - name : Publish to npm
42- run : pnpm publish --access public --provenance
43- env :
44- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
45-
50+ run : |
51+ pnpm typecheck
52+ pnpm lint
53+ pnpm test:run
54+ pnpm build
55+
56+ - name : Configure git
57+ run : |
58+ git config --local user.email "[email protected] " 59+ git config --local user.name "GitHub Action"
60+
61+ - name : Bump version and create tag
62+ id : version
63+ run : |
64+ # Get current version
65+ CURRENT_VERSION=$(node -p "require('./package.json').version")
66+ echo "Current version: $CURRENT_VERSION"
67+
68+ # Bump version
69+ NEW_VERSION=$(pnpm version ${{ github.event.inputs.release_type }} --no-git-tag-version | tail -1)
70+ NEW_VERSION="${NEW_VERSION#v}" # Remove 'v' prefix if present
71+
72+ echo "New version: $NEW_VERSION"
73+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
74+ echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
75+
76+ - name : Generate changelog
77+ id : changelog
78+ run : |
79+ # Get commits since last tag
80+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
81+
82+ if [ -z "$LAST_TAG" ]; then
83+ COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
84+ else
85+ COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges $LAST_TAG..HEAD)
86+ fi
87+
88+ if [ -z "$COMMITS" ]; then
89+ COMMITS="- Initial release"
90+ fi
91+
92+ # Create changelog
93+ CHANGELOG="## What's Changed
94+ $COMMITS
95+
96+ **Full Changelog**: https://github.com/${{ github.repository }}/compare/$LAST_TAG...v${{ steps.version.outputs.version }}"
97+
98+ # Save to file and output
99+ echo "$CHANGELOG" > changelog.md
100+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
101+ echo "$CHANGELOG" >> $GITHUB_OUTPUT
102+ echo "EOF" >> $GITHUB_OUTPUT
103+
104+ - name : Commit version bump
105+ run : |
106+ git add package.json
107+ git commit -m "chore: bump version to v${{ steps.version.outputs.version }}"
108+ git tag "v${{ steps.version.outputs.version }}"
109+
110+ - name : Push changes
111+ run : |
112+ git push origin main
113+ git push origin "v${{ steps.version.outputs.version }}"
114+
46115 - name : Create GitHub Release
47- uses : actions/create-release@v1
48- env :
49- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
116+ uses : softprops/action-gh-release@v1
50117 with :
51- tag_name : ${{ github.ref }}
52- release_name : Release ${{ github.ref }}
118+ tag_name : " v${{ steps.version.outputs.version }}"
119+ name : " Release v${{ steps.version.outputs.version }}"
120+ body : ${{ steps.changelog.outputs.changelog }}
53121 draft : false
54- prerelease : false
122+ prerelease : ${{ contains(github.event.inputs.release_type, 'prerelease') }}
123+ env :
124+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
125+
126+ - name : Setup npm registry
127+ run : echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
128+
129+ - name : Publish to npm
130+ run : pnpm publish --access public --no-git-checks
0 commit comments