-
Notifications
You must be signed in to change notification settings - Fork 47
211 lines (194 loc) · 7.15 KB
/
build-app.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# 在主分支上构建
name: build-app
on:
push: # push 触发
branches:
- next
jobs:
# ========================= 准备项目 =========================
init:
name: 初始化构建
runs-on: ubuntu-latest
outputs:
version: ${{ steps.step_init.outputs.VERSION }}
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
# 初始化一些流程需要的环境变量
- name: Init Env
id: step_init
run: echo VERSION=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT
# ========================= 构建 Web 版本 =========================
build-root-web:
name: 构建 Web 版本(根目录)
runs-on: ubuntu-latest
needs: init
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
# 更新依赖
- name: Install
run: yarn
# 构建
- name: Build
run: yarn build
# 将 dist 目录压缩为 zip
- name: Zip
run: zip -r Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip dist
# 上传构建结果
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ needs.init.outputs.version }}-web
path: Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip
# ======================= 构建 Docker 版本 ========================
build-docker:
name: 构建 Docker 版本
runs-on: ubuntu-latest
needs:
- init
- build-root-web
steps:
# 拉取代码(不需要子模块,只是获取 dockerfile)
- name: Checkout
uses: actions/checkout@v4
# 下载上一步构建的结果
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ needs.init.outputs.version }}-web
# 解压(不输出细节)
- name: Unzip
run: unzip -q Stapxs.QQ.Lite-${{ needs.init.outputs.version }}-web.zip
# 登录到 Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: stapxs
password: ${{ secrets.DOCKER_PASSWORD }}
# 使用 buildx 构建 amd64 和 arm64 架构的镜像
# 推送到 Docker Hub;不保留历史版本直接推送 latest
- name: Build Docker Image
run: |
docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 -t stapxs/qq-web:latest --push .
# ==================== 构建 Github Pages 版本 =====================
build-pages:
name: 构建 Github Pages 版本
runs-on: ubuntu-latest
needs: init
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
# 更新依赖
- name: Install
run: yarn
# 构建
- name: Build
run: yarn build
env:
BUILD_ENV: github-actions
# 部署 Web 版本
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages
folder: dist
# ========================= 构建 Electron 版本 =========================
build-electron:
name: 构建 Electron 版本
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2019, ubuntu-latest]
outputs:
version: ${{ needs.init.outputs.version }}
needs: init
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
# 更新依赖
- name: Install
run: yarn
# 构建 electron 版本(Windows)
- name: Build Electron (Windows)
if: matrix.os == 'windows-2019'
run: yarn build:win
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 构建 electron 版本(Linux)
- name: Build Electron (Linux)
if: matrix.os == 'ubuntu-latest'
run: yarn build:linux
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 上传构建结果
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ needs.init.outputs.version }}-${{ matrix.os }}
path: dist_electron
# ========================= 发布构建结果 =========================
release:
name: 发布构建结果
runs-on: ubuntu-latest
needs:
- build-root-web
- build-electron
steps:
# 下载构建结果
- name: Download Artifacts
id: download-artifact
uses: actions/download-artifact@v4
with:
path: ${{ needs.build-electron.outputs.version }}
pattern: ${{ needs.build-electron.outputs.version }}-*
merge-multiple: true
- name: Artifacts List
run: ls -R
# 发布构建结果
- name: Publish Release
uses: softprops/action-gh-release@v2
with:
files: ./${{ needs.build-electron.outputs.version }}/*
tag_name: v${{ needs.build-electron.outputs.version }}
body: |
# Release 自动构建
`这是一个自动构建版本,由 GitHub Actions 自动构建并发布。`
## 更新内容
${{ github.event.head_commit.message }}
## 自动构建信息
- 构建时间:${{ github.event.head_commit.timestamp }}
- 构建提交:${{ github.event.head_commit.id }}
- 构建分支:${{ github.event.head_commit.tree_id }}
draft: false
prerelease: false
token: ${{ secrets.ACCESS_TOKEN }}