-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (128 loc) · 4.91 KB
/
Copy pathrelease.yml
File metadata and controls
162 lines (128 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Release Extension
on:
push:
tags:
- 'v*.*.*' # 触发条件:推送版本标签,如 v1.0.0
workflow_dispatch: # 允许手动触发
# 显式设置权限,遵循最小权限原则
permissions:
contents: write # 需要写入权限以创建 Release
actions: read # 只需读取权限
checks: read # 只需读取权限
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10.19.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.21.0'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build Chrome Extension
run: pnpm build:chrome
- name: Build Firefox Extension
run: pnpm build:firefox
- name: Build Edge Extension
run: pnpm build:edge
- name: Create distribution packages
run: |
# 进入构建目录
cd build
# 打包 Chrome 版本
cd chrome-mv3-prod
zip -r ../../88code-cost-chrome-${{ github.ref_name }}.zip .
cd ..
# 打包 Firefox 版本
cd firefox-mv2-prod
zip -r ../../88code-cost-firefox-${{ github.ref_name }}.zip .
cd ..
# 打包 Edge 版本
cd edge-mv3-prod
zip -r ../../88code-cost-edge-${{ github.ref_name }}.zip .
cd ..
- name: Extract version from package.json
id: package_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Extract changelog for version
id: changelog
run: |
VERSION="${{ github.ref_name }}"
# 移除 v 前缀,例如 v1.0.0 -> 1.0.0
VERSION_NUMBER="${VERSION#v}"
# 使用 awk 提取对应版本的 CHANGELOG 内容
CHANGELOG_CONTENT=$(awk -v version="$VERSION_NUMBER" '
/^## \[/ {
if (found) exit
if ($0 ~ "\\[" version "\\]") {
found=1
next
}
}
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md)
# 如果没有找到对应版本的 CHANGELOG,使用默认描述
if [ -z "$CHANGELOG_CONTENT" ]; then
CHANGELOG_CONTENT="## 📦 88Code Cost ${VERSION}
感谢使用 88Code Cost!本次发布包含以下浏览器版本:
- 🟦 Chrome / Edge (Manifest V3)
- 🟧 Firefox (Manifest V2)
详细更新内容请查看 [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/CHANGELOG.md)。"
fi
# 使用 heredoc 保存多行内容
{
echo 'CONTENT<<EOF'
echo "$CHANGELOG_CONTENT"
echo EOF
} >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ github.ref_name }}
body: |
${{ steps.changelog.outputs.CONTENT }}
---
## 📥 下载说明
请根据您的浏览器选择对应的版本下载:
- **Chrome / Edge**:下载 `88code-cost-chrome-${{ github.ref_name }}.zip`
- **Firefox**:下载 `88code-cost-firefox-${{ github.ref_name }}.zip`
## 📖 安装指南
详细安装步骤请查看 [README.md](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/README.md#安装方式)。
## 🔗 相关链接
- [完整更新日志](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/CHANGELOG.md)
- [使用文档](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/README.md)
- [问题反馈](https://github.com/${{ github.repository }}/issues)
files: |
88code-cost-chrome-${{ github.ref_name }}.zip
88code-cost-firefox-${{ github.ref_name }}.zip
88code-cost-edge-${{ github.ref_name }}.zip
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Chrome artifact
uses: actions/upload-artifact@v4
with:
name: chrome-extension
path: 88code-cost-chrome-${{ github.ref_name }}.zip
retention-days: 90
- name: Upload Firefox artifact
uses: actions/upload-artifact@v4
with:
name: firefox-extension
path: 88code-cost-firefox-${{ github.ref_name }}.zip
retention-days: 90
- name: Upload Edge artifact
uses: actions/upload-artifact@v4
with:
name: edge-extension
path: 88code-cost-edge-${{ github.ref_name }}.zip
retention-days: 90