1+ name : Release and Publish
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version_type :
7+ description : ' Version type (prerelease, prepatch, patch, preminor, minor, premajor, major)'
8+ required : true
9+ default : ' patch'
10+ type : choice
11+ options :
12+ - prerelease
13+ - prepatch
14+ - patch
15+ - preminor
16+ - minor
17+ - premajor
18+ - major
19+ custom_version :
20+ description : ' Custom version (leave empty to use version_type)'
21+ required : false
22+ type : string
23+ dist_tag :
24+ description : ' npm distribution tag (latest, next, beta, etc)'
25+ required : false
26+ default : ' latest'
27+ type : string
28+
29+ jobs :
30+ release-and-publish :
31+ runs-on : ubuntu-latest
32+ permissions :
33+ contents : write
34+ packages : write
35+ id-token : write
36+ steps :
37+ - name : Checkout code
38+ uses : actions/checkout@v4
39+ with :
40+ fetch-depth : 0
41+ token : ${{ secrets.PAT_GITHUB }}
42+
43+ - name : Setup Node.js
44+ uses : actions/setup-node@v4
45+ with :
46+ node-version : ' 18.x'
47+ registry-url : ' https://registry.npmjs.org'
48+
49+ - name : Setup Bun
50+ uses : oven-sh/setup-bun@v1
51+ with :
52+ bun-version : latest
53+
54+ - name : Install dependencies
55+ run : bun install
56+
57+ - name : Configure Git
58+ run : |
59+ git config --local user.email "action@github.com"
60+ git config --local user.name "GitHub Action"
61+ git config pull.rebase false
62+
63+ - name : Bump version
64+ id : bump_version
65+ run : |
66+ if [ -n "${{ github.event.inputs.custom_version }}" ]; then
67+ echo "Using custom version ${{ github.event.inputs.custom_version }}"
68+ npm version ${{ github.event.inputs.custom_version }} --no-git-tag-version
69+ echo "VERSION=${{ github.event.inputs.custom_version }}" >> $GITHUB_ENV
70+ else
71+ echo "Bumping ${{ github.event.inputs.version_type }} version"
72+ NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
73+ echo "VERSION=${NEW_VERSION:1}" >> $GITHUB_ENV
74+ fi
75+ echo "New version: ${{ env.VERSION }}"
76+
77+ - name : Generate Changelog
78+ run : |
79+ # Generate the full changelog
80+ npm run changelog
81+ # Generate release notes for just this version
82+ npm run changelog:latest
83+
84+ - name : Build project
85+ run : bun run build && bun run build:http
86+
87+ - name : Commit and push changes
88+ run : |
89+ git pull origin main --no-edit
90+ git add package.json CHANGELOG.md
91+ git commit -m "Bump version to v${{ env.VERSION }}"
92+ git push --force-with-lease
93+
94+ - name : Create and push tag
95+ run : |
96+ # Delete the tag if it already exists locally
97+ git tag -d "v${{ env.VERSION }}" 2>/dev/null || true
98+ # Delete the tag if it exists on the remote
99+ git push origin --delete "v${{ env.VERSION }}" 2>/dev/null || true
100+ # Create and push the new tag
101+ git tag -a "v${{ env.VERSION }}" -m "Release v${{ env.VERSION }}"
102+ git push origin "v${{ env.VERSION }}"
103+
104+ - name : Create GitHub Release
105+ uses : softprops/action-gh-release@v1
106+ with :
107+ tag_name : v${{ env.VERSION }}
108+ name : Release v${{ env.VERSION }}
109+ body_path : RELEASE_NOTES.md
110+ generate_release_notes : false
111+ env :
112+ GITHUB_TOKEN : ${{ secrets.PAT_GITHUB }}
113+
114+ - name : Publish to npm
115+ run : npm publish --access public --provenance --tag ${{ github.event.inputs.dist_tag || 'latest' }}
116+ env :
117+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments