File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name : Publish to NPM
22
33on :
4+ release :
5+ types : [published]
46 workflow_dispatch :
5- inputs :
6- version :
7- description : " 发布版本号 (例如: 1.0.0)"
8- required : true
9- type : string
107
118permissions :
129 contents : write
2421 fetch-depth : 0
2522 token : ${{ secrets.GITHUB_TOKEN }}
2623
24+ - name : Extract version from tag
25+ id : get_version
26+ run : |
27+ # Get tag from release event or use ref for workflow_dispatch
28+ if [ "${{ github.event_name }}" = "release" ]; then
29+ TAG="${{ github.event.release.tag_name }}"
30+ else
31+ TAG="${{ github.ref_name }}"
32+ fi
33+ # Remove 'v' prefix if present
34+ VERSION="${TAG#v}"
35+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
36+ echo "Extracted version: $VERSION"
37+
2738 - name : Setup pnpm
2839 uses : pnpm/action-setup@v4
2940 with :
4657 run : pnpm build
4758
4859 - name : Update version
49- run : npm version ${{ github.event.inputs.version }} --no-git-tag-version --allow-same-version
60+ run : npm version ${{ steps.get_version.outputs.VERSION }} --no-git-tag-version --allow-same-version
5061
5162 - name : Publish to npm
5263 env :
5869 git config user.name "github-actions[bot]"
5970 git config user.email "github-actions[bot]@users.noreply.github.com"
6071 git add package.json
61- git diff --staged --quiet || git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
72+ git diff --staged --quiet || git commit -m "chore: bump version to ${{ steps.get_version.outputs.VERSION }}"
6273 git push origin HEAD:main
You can’t perform that action at this time.
0 commit comments