@@ -3,14 +3,14 @@ name: 构建和发布
33on :
44 push :
55 branches : ['main']
6+ workflow_dispatch :
67
78permissions :
89 contents : write
910 packages : write
1011
1112jobs :
1213 build :
13- if : ${{ github.event.head_commit && contains(github.event.head_commit.message, '[pub]') }}
1414 runs-on : ubuntu-latest
1515 env :
1616 HUSKY : 0
@@ -22,38 +22,51 @@ jobs:
2222 persist-credentials : true
2323
2424 - name : Setup pnpm
25- uses : pnpm/action-setup@v2
25+ uses : pnpm/action-setup@v4
2626 with :
27- version : 10.27.0
27+ version : 10.33.2
2828
2929 - name : Use Node.js
3030 uses : actions/setup-node@v6
3131 with :
3232 node-version : 24
3333 cache : ' pnpm'
34- registry-url : ' https://registry.npmjs.org'
34+ registry-url : ' https://npm.pkg.github.com'
35+ scope : ' @delta-comic'
3536
3637 - name : Install dependencies
3738 run : pnpm install --frozen-lockfile
3839
39- # build
40- - name : Change version
41- id : set-version
40+ - name : Resolve release version
41+ id : release-version
4242 env :
4343 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4444 IS_DUR_RUN : true
4545 run : |
4646 OLD_VERSION="$(node ./script/update-version.mts)"
47+ if [ -z "$OLD_VERSION" ]; then
48+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
49+ exit 0
50+ fi
51+
52+ NEW_VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('./package.json', 'utf8')).version")"
4753 echo "old_version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
54+ echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
55+ echo "should_publish=true" >> "$GITHUB_OUTPUT"
4856
4957 - name : Build
50- run : |
51- pnpm run build || pnpm run build
58+ if : steps.release-version.outputs.should_publish == 'true'
59+ run : pnpm run build
5260
53- # publish
54- - name : Run semantic-release
61+ - name : Publish GitHub package
62+ if : steps.release-version.outputs.should_publish == 'true'
63+ env :
64+ NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
65+ run : pnpm publish --registry=https://npm.pkg.github.com --no-git-checks
66+
67+ - name : Create GitHub release
68+ if : steps.release-version.outputs.should_publish == 'true'
5569 env :
5670 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57- run : |
58- pnpm publish
59- pnpm exec semantic-release
71+ NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72+ run : pnpm exec semantic-release
0 commit comments