-
Notifications
You must be signed in to change notification settings - Fork 44
187 lines (173 loc) · 5.1 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
# 在主分支上构建
name: build
on:
push: # push 触发
branches:
- next
jobs:
# ========================= 准备项目 =========================
init:
name: 初始化构建
runs-on: ubuntu-latest
outputs:
build_web: ${{ steps.step_init.outputs.BUILD_WEB }}
build_electron: ${{ steps.step_init.outputs.BUILD_ELECTRON }}
version: ${{ steps.step_init.outputs.VERSION }}
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 初始化一些流程需要的环境变量
- 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
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 18.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
# ==================== 构建 Github Pages 版本 =====================
build-pages:
name: 构建 Github Pages 版本
runs-on: ubuntu-latest
needs: init
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
# 更新依赖
- name: Install
run: yarn
# 构建
- name: Build
run: yarn build
env:
NODEJS_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
persist-credentials: false
# 设置 Node.js 版本
- name: Load Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
# 更新依赖
- name: Install
run: yarn
# 构建 electron 版本(Windows)
- name: Build Electron (Windows)
if: matrix.os == 'windows-2019'
run: yarn electron:build --win
env:
NODEJS_ENV: github-actions
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 构建 electron 版本(Linux)
- name: Build Electron (Linux)
if: matrix.os == 'ubuntu-latest'
run: yarn electron:build --linux
env:
NODEJS_ENV: github-actions
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# 上传构建结果
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ needs.init.outputs.version }}-${{ matrix.os }}
path: dist_electron/out
# ========================= 发布构建结果 =========================
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 }}