Skip to content

Commit 2bf58be

Browse files
committed
chore: 将版本号降级至1.0.1,并更新 GitHub Actions 工作流配置
1 parent b79b8f8 commit 2bf58be

File tree

2 files changed

+108
-30
lines changed

2 files changed

+108
-30
lines changed

.github/workflows/release.yml

Lines changed: 107 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,128 @@
1-
# This action will publish the package to npm and create a GitHub release.
2-
# Ref: https://docs.npmjs.com/trusted-publishers/
31
name: Release
42

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

1714
jobs:
18-
publish:
15+
release:
1916
runs-on: ubuntu-latest
20-
environment: npm
17+
permissions:
18+
contents: write
19+
packages: write
20+
id-token: write
21+
2122
steps:
22-
- name: Checkout
23+
- name: 检出代码
2324
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
2427

25-
- name: Setup Node.js
28+
- name: 设置 Node.js
2629
uses: actions/setup-node@v4
2730
with:
2831
node-version: 22
32+
registry-url: 'https://registry.npmjs.org'
2933

30-
# Update npm to the latest version to enable OIDC
31-
# Use corepack to install pnpm
32-
- name: Setup Package Managers
33-
run: |
34-
npm install -g npm@latest
35-
npm --version
36-
npm install -g corepack@latest --force
37-
corepack enable
34+
- name: 安装 pnpm
35+
uses: pnpm/action-setup@v4
36+
with:
37+
version: 10
3838

39-
- name: Install Dependencies
40-
run: pnpm install
39+
- name: 获取 pnpm store 目录
40+
shell: bash
41+
run: |
42+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
4143
42-
- name: Publish
43-
uses: JS-DevTools/npm-publish@v3
44+
- name: 设置 pnpm 缓存
45+
uses: actions/cache@v4
4446
with:
45-
token: empty
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 lint
4662

47-
- name: Create GitHub Release
48-
uses: ncipollo/release-action@v1
63+
- name: 构建项目
64+
run: pnpm run build
65+
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+
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
81+
git config --local user.email "action@github.com"
82+
git config --local user.name "GitHub Action"
83+
git add package.json
84+
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
85+
git tag ${{ steps.get_version.outputs.tag_name }}
86+
git push origin HEAD:${{ github.ref_name }}
87+
git push origin ${{ steps.get_version.outputs.tag_name }}
88+
89+
- name: 生成变更日志
90+
id: changelog
91+
run: |
92+
# 获取上一个标签
93+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
94+
95+
if [ -z "$PREV_TAG" ]; then
96+
# 如果没有上一个标签,获取所有提交
97+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
98+
else
99+
# 获取两个标签之间的提交
100+
CHANGELOG=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
101+
fi
102+
103+
# 保存到文件以避免特殊字符问题
104+
echo "$CHANGELOG" > changelog.txt
105+
echo "changelog_file=changelog.txt" >> $GITHUB_OUTPUT
106+
107+
- name: 发布到 npm
108+
run: pnpm publish --no-git-checks
109+
env:
110+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
111+
112+
- name: 创建 GitHub Release
113+
uses: actions/create-release@v1
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49116
with:
50-
generateReleaseNotes: "true"
117+
tag_name: ${{ steps.get_version.outputs.tag_name }}
118+
release_name: Release ${{ steps.get_version.outputs.tag_name }}
119+
body_path: ${{ steps.changelog.outputs.changelog_file }}
120+
draft: false
121+
prerelease: false
122+
123+
- name: 通知发布成功
124+
run: |
125+
echo "🎉 发布成功!"
126+
echo "📦 版本: ${{ steps.get_version.outputs.version }}"
127+
echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}"
128+
echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-unocss"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"frontend",
1919
"styling"
2020
],
21-
"version": "1.0.2",
21+
"version": "1.0.1",
2222
"repository": {
2323
"type": "git",
2424
"url": "git+https://github.com/winjs-dev/winjs-plugin-unocss.git"

0 commit comments

Comments
 (0)