Skip to content

Commit 5a79f34

Browse files
committed
chore: 🤖 调整发布脚本
1 parent 78b8b48 commit 5a79f34

File tree

1 file changed

+26
-97
lines changed

1 file changed

+26
-97
lines changed

.github/workflows/release.yml

Lines changed: 26 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,59 @@
1+
# This action will publish the package to npm and create a GitHub release.
12
name: Release
23

34
on:
5+
# Run `npm run bump` to bump the version and create a git tag.
46
push:
57
tags:
6-
- 'v*'
8+
- "v*"
9+
710
workflow_dispatch:
8-
inputs:
9-
version:
10-
description: '发布版本 (例如: 1.0.0)'
11-
required: true
12-
type: string
11+
12+
permissions:
13+
contents: write
14+
id-token: write
1315

1416
jobs:
15-
release:
17+
publish:
1618
runs-on: ubuntu-latest
17-
permissions:
18-
contents: write
19-
packages: write
20-
id-token: write
21-
2219
steps:
23-
- name: 检出代码
20+
- name: Checkout
2421
uses: actions/checkout@v5
25-
with:
26-
fetch-depth: 0
2722

28-
- name: 设置 Node.js
29-
uses: actions/setup-node@v4
30-
with:
31-
node-version: 22.18.0
32-
registry-url: 'https://registry.npmjs.org'
33-
34-
- name: 安装 pnpm
23+
- name: Setup pnpm
3524
uses: pnpm/action-setup@v4
3625
with:
3726
version: 10.14.0
3827

39-
- name: 获取 pnpm store 目录
40-
shell: bash
41-
run: |
42-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
43-
44-
- name: 设置 pnpm 缓存
45-
uses: actions/cache@v4
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
4630
with:
47-
path: ${{ env.STORE_PATH }}
48-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
49-
restore-keys: |
50-
${{ runner.os }}-pnpm-store-
31+
node-version: 22.20.0
32+
registry-url: 'https://registry.npmjs.org'
33+
scope: '@winner-fed'
34+
always-auth: true
5135

52-
- name: 安装依赖
53-
run: |
54-
# 尝试使用 frozen lockfile,如果失败则更新 lockfile
55-
pnpm install --frozen-lockfile || {
56-
echo "⚠️ Lockfile 不匹配,正在更新..."
57-
pnpm install --no-frozen-lockfile
58-
}
36+
- name: Update npm to latest
37+
run: npm install -g npm@latest
5938

60-
- name: 格式检查
61-
run: pnpm run lint
39+
- name: Install Dependencies
40+
run: pnpm install --frozen-lockfile
6241

63-
- name: 构建项目
42+
- name: Build
6443
run: pnpm run build
6544

66-
- name: 获取版本号
67-
id: get_version
68-
run: |
69-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
70-
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
71-
echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
72-
else
73-
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
74-
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
75-
fi
76-
77-
- name: 更新版本号 (手动触发时)
78-
if: github.event_name == 'workflow_dispatch'
79-
run: |
80-
# 检查 tag 是否已经存在
81-
if git show-ref --tags --verify --quiet "refs/tags/${{ steps.get_version.outputs.tag_name }}"; then
82-
echo "⚠️ Tag ${{ steps.get_version.outputs.tag_name }} 已存在,跳过创建"
83-
else
84-
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
85-
git config --local user.email "action@github.com"
86-
git config --local user.name "GitHub Action"
87-
git add package.json
88-
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
89-
git tag ${{ steps.get_version.outputs.tag_name }}
90-
git push origin HEAD:${{ github.ref_name }}
91-
git push origin ${{ steps.get_version.outputs.tag_name }}
92-
fi
93-
94-
- name: 生成变更日志
95-
id: changelog
96-
run: npx changelogithub
97-
continue-on-error: true
98-
env:
99-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
100-
101-
- name: 发布到 npm
102-
run: |
103-
# 检查版本是否已经发布到 npm
104-
PACKAGE_NAME=$(node -p "require('./package.json').name")
105-
CURRENT_VERSION=$(node -p "require('./package.json').version")
106-
107-
# 尝试获取 npm 上的版本信息
108-
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version 2>/dev/null; then
109-
echo "⚠️ 版本 ${CURRENT_VERSION} 已存在于 npm,跳过发布"
110-
else
111-
echo "📦 发布版本 ${CURRENT_VERSION} 到 npm..."
112-
pnpm publish --no-git-checks
113-
fi
114-
env:
115-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
- name: Publish to npm
46+
run: npm publish --access public --provenance
11647

11748
- name: Create GitHub Release
11849
uses: ncipollo/release-action@v1
11950
with:
12051
generateReleaseNotes: "true"
121-
allowUpdates: true
122-
skipIfReleaseExists: false
123-
omitBodyDuringUpdate: false
12452

12553
- name: 通知发布成功
12654
run: |
55+
PACKAGE_NAME=$(node -p "require('./package.json').name")
12756
echo "🎉 发布成功!"
12857
echo "📦 版本: ${{ steps.get_version.outputs.version }}"
12958
echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}"
130-
echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-request"
59+
echo "📝 npm: https://www.npmjs.com/package/${PACKAGE_NAME}"

0 commit comments

Comments
 (0)