44 workflow_dispatch :
55 inputs :
66 version :
7- description : " Release version (e.g., 0.1.6 or 0.1.6-pre.1 )"
7+ description : " Release version (e.g., 0.1.6)"
88 required : true
99 type : string
1010
@@ -23,44 +23,40 @@ jobs:
2323 - name : Checkout
2424 uses : actions/checkout@v4
2525 with :
26- token : ${{ secrets.GITHUB_TOKEN }}
2726 persist-credentials : true
2827
2928 - name : Configure git user
3029 run : |
3130 git config user.name "github-actions[bot]"
3231 git config user.email "github-actions[bot]@users.noreply.github.com"
3332
34- - name : Validate branch is main
35- run : |
36- CURRENT_BRANCH="${GITHUB_REF_NAME}"
37- if [ "${CURRENT_BRANCH}" != "main" ]; then
38- echo "Release must be run from main branch, got: ${CURRENT_BRANCH}"
39- exit 1
40- fi
41-
4233 - name : Validate version format
4334 run : |
4435 VERSION="${{ inputs.version }}"
4536 if ! echo "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
4637 echo "Invalid version format: ${VERSION}"
47- echo "Expected: digits.digits.digits or digits.digits.digits-pre-suffix"
4838 exit 1
4939 fi
5040
5141 - name : Update version in package.json
5242 run : |
53- VERSION=${{ inputs.version }}
54- node -e "var fs=require('fs'),p=JSON.parse(fs.readFileSync('package.json','utf8'));p.version='${VERSION}';fs.writeFileSync('package.json',JSON.stringify(p,null,2)+String.fromCharCode(10))"
43+ VERSION="${{ inputs.version }}"
44+ node -e "
45+ var fs = require('fs');
46+ var pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
47+ pkg.version = process.argv[1];
48+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + String.fromCharCode(10));
49+ " "${VERSION}"
5550
5651 - name : Commit version bump
57- run : git commit -am 'release: v${{ inputs.version }}'
52+ run : |
53+ git commit -am "release: v${{ inputs.version }}"
5854
5955 - name : Create tag
60- run : git tag 'v${{ inputs.version }}'
61-
62- - name : Push commit to main
63- run : git push origin main
56+ run : |
57+ git tag "v${{ inputs.version }}"
6458
65- - name : Push tag
66- run : git push origin 'v${{ inputs.version }}'
59+ - name : Push commit and tag
60+ run : |
61+ git push origin main
62+ git push origin "v${{ inputs.version }}"
0 commit comments