Skip to content

Commit 906d9ff

Browse files
committed
ci: publish package to github packages
1 parent 376fb56 commit 906d9ff

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

.github/workflows/build.yaml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ name: 构建和发布
33
on:
44
push:
55
branches: ['main']
6+
workflow_dispatch:
67

78
permissions:
89
contents: write
910
packages: write
1011

1112
jobs:
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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@delta-comic/delta-comic-plugin-layout",
3-
"version": "0.7.2",
3+
"version": "0.9.2",
44
"description": "希望的涟漪",
55
"homepage": "https://github.com/delta-comic/delta-comic-plugin-layout",
66
"license": "AGPL-3.0-only",
@@ -36,6 +36,7 @@
3636
"lint-staged": "lint-staged",
3737
"lint:fix": "vp lint --fix --type-aware",
3838
"preview": "vp preview",
39+
"publish:github": "pnpm run build && pnpm publish --registry=https://npm.pkg.github.com --no-git-checks",
3940
"set-ver": "node ./script/set-version.mts",
4041
"typecheck": "vue-tsc --noEmit -p ./tsconfig.json --composite false"
4142
},
@@ -112,4 +113,4 @@
112113
"esbuild"
113114
]
114115
}
115-
}
116+
}

0 commit comments

Comments
 (0)