Skip to content

Commit 13cf0ad

Browse files
committed
chore: 🤖 同步发布脚本
1 parent ff3d2e5 commit 13cf0ad

File tree

1 file changed

+28
-96
lines changed

1 file changed

+28
-96
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +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
27-
28-
- name: 设置 Node.js
29-
uses: actions/setup-node@v5
30-
with:
31-
node-version: 22
32-
registry-url: 'https://registry.npmjs.org'
3322

34-
- name: 安装 pnpm
23+
- name: Setup pnpm
3524
uses: pnpm/action-setup@v4
3625
with:
37-
version: 10
26+
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-
51-
52-
- name: 安装依赖
53-
run: |
54-
# 尝试使用 frozen lockfile,如果失败则更新 lockfile
55-
pnpm install --frozen-lockfile || {
56-
echo "⚠️ Lockfile 不匹配,正在更新..."
57-
pnpm install --no-frozen-lockfile
58-
}
59-
60-
- name: 构建项目
61-
run: pnpm run build
31+
node-version: 22.20.0
32+
registry-url: 'https://registry.npmjs.org'
33+
scope: '@winner-fed'
34+
always-auth: true
6235

63-
- name: 获取版本号
64-
id: get_version
65-
run: |
66-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
67-
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
68-
echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
69-
else
70-
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
71-
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
72-
fi
36+
- name: Update npm to latest
37+
run: npm install -g npm@latest
7338

74-
- name: 更新版本号 (手动触发时)
75-
if: github.event_name == 'workflow_dispatch'
76-
run: |
77-
# 检查 tag 是否已经存在
78-
if git show-ref --tags --verify --quiet "refs/tags/${{ steps.get_version.outputs.tag_name }}"; then
79-
echo "⚠️ Tag ${{ steps.get_version.outputs.tag_name }} 已存在,跳过创建"
80-
else
81-
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
82-
git config --local user.email "action@github.com"
83-
git config --local user.name "GitHub Action"
84-
git add package.json
85-
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
86-
git tag ${{ steps.get_version.outputs.tag_name }}
87-
git push origin HEAD:${{ github.ref_name }}
88-
git push origin ${{ steps.get_version.outputs.tag_name }}
89-
fi
39+
- name: Install Dependencies
40+
run: pnpm install --frozen-lockfile
9041

91-
- name: 生成变更日志
92-
id: changelog
93-
run: npx changelogithub
94-
continue-on-error: true
95-
env:
96-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
42+
- name: Build
43+
run: pnpm run build
9744

98-
- name: 发布到 npm
99-
run: |
100-
# 检查版本是否已经发布到 npm
101-
PACKAGE_NAME=$(node -p "require('./package.json').name")
102-
CURRENT_VERSION=$(node -p "require('./package.json').version")
103-
104-
# 尝试获取 npm 上的版本信息
105-
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version 2>/dev/null; then
106-
echo "⚠️ 版本 ${CURRENT_VERSION} 已存在于 npm,跳过发布"
107-
else
108-
echo "📦 发布版本 ${CURRENT_VERSION} 到 npm..."
109-
pnpm publish --no-git-checks
110-
fi
111-
env:
112-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
- name: Publish to npm
46+
run: npm publish --access public --provenance
11347

11448
- name: Create GitHub Release
11549
uses: ncipollo/release-action@v1
11650
with:
11751
generateReleaseNotes: "true"
118-
allowUpdates: true
119-
skipIfReleaseExists: false
120-
omitBodyDuringUpdate: false
12152

12253
- name: 通知发布成功
12354
run: |
55+
PACKAGE_NAME=$(node -p "require('./package.json').name")
12456
echo "🎉 发布成功!"
12557
echo "📦 版本: ${{ steps.get_version.outputs.version }}"
12658
echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}"
127-
echo "📝 npm: https://www.npmjs.com/package/@winner-fed/cloud-utils"
59+
echo "📝 npm: https://www.npmjs.com/package/${PACKAGE_NAME}"

0 commit comments

Comments
 (0)