-
Notifications
You must be signed in to change notification settings - Fork 4
378 lines (332 loc) · 12.5 KB
/
node.js.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [ 18.x ]
os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
arch: [ x64, arm64 ]
exclude:
# https://github.com/xuxiaowei-com-cn/electron-tools/actions/runs/5128498312/jobs/9225241332
# https://github.com/xuxiaowei-com-cn/electron-tools/actions/runs/5128523146/jobs/9225286730
- arch: arm64
os: ubuntu-latest
# https://github.com/xuxiaowei-com-cn/electron-tools/actions/runs/5128523146/jobs/9225286883
# https://github.com/xuxiaowei-com-cn/electron-tools/actions/runs/5128534557/jobs/9225307705
- arch: arm64
os: windows-latest
env:
# npm 缓存路径
NPM_CONFIG_CACHE: ~/.cache
# electron 缓存路径
ELECTRON_CACHE: ~/.electron/cache
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print Environment Variables
run: |
echo $NPM_CONFIG_CACHE
echo $ELECTRON_CACHE
- name: Use Node.js ${{ matrix.node-version }} !(macos-latest arm64)
uses: actions/setup-node@v3
if: ${{ !(matrix.os == 'macos-latest' && matrix.arch == 'arm64') }}
with:
node-version: ${{ matrix.node-version }}
architecture: ${{ matrix.arch }}
# macos、arm64 默认为 node v18.16.0(不能设置 node-version 否则无法执行)
- name: Use Node.js ${{ matrix.node-version }} macos-latest arm64
uses: actions/setup-node@v3
if: ${{ matrix.os == 'macos-latest' && matrix.arch == 'arm64' }}
with:
architecture: ${{ matrix.arch }}
- name: Cache modules
uses: actions/cache@v3
id: cache-modules
with:
path: |
~/.npm
~/.cache
~/.electron/cache
key: ${{ matrix.os }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ matrix.os }}-
- run: node -v
- run: echo '' > .npmrc
- run: npm i
- run: npm run build
- name: electron:build (macos-latest x64)
if: ${{ matrix.os == 'macos-latest' && matrix.arch == 'x64' }}
run: |
npm run electron:build
- name: electron:build (macos-latest arm64)
if: ${{ matrix.os == 'macos-latest' && matrix.arch == 'arm64' }}
run: |
# 刪除特殊字符
sed -i '' 's/\r$//' electron-builder.json5
# 准备打包的文件命名方式
echo 's/${productName}_${version}-${arch}.${ext}/${productName}_${version}-arm64.${ext}/'
# 修改为准备打包的文件命名方式
sed -i '' 's/${productName}_${version}-${arch}.${ext}/${productName}_${version}-arm64.${ext}/' electron-builder.json5
# 查看修改结果
cat electron-builder.json5
npm run electron:build
- name: electron:build (windows-latest)
if: ${{ matrix.os == 'windows-latest' }}
run: |
npm run electron:build
- name: electron:build (ubuntu-latest)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
cat electron-builder.json5
# 增加 .rpm 产物
sed -i '/"AppImage",/i \ \ \ \ \ \ "rpm",' electron-builder.json5
# 增加 .deb 产物
sed -i '/"AppImage",/i \ \ \ \ \ \ "deb",' electron-builder.json5
cat electron-builder.json5
npm run electron:build
- run: ls release
- name: Ubuntu ls release
if: ${{ matrix.os == 'ubuntu-latest' }}
run: ls release/*.*.*
- name: macOS ls release
if: ${{ matrix.os == 'macos-latest' }}
run: ls release/*.*.*
- name: Windows ls release
if: ${{ matrix.os == 'windows-latest' }}
shell: pwsh
run: Get-ChildItem -Path ./release/*/ -Directory | ForEach-Object { Get-ChildItem -Path $_.FullName }
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: electron-tools-${{ matrix.os }}-${{ matrix.arch }}
path: |
release/*/*.exe
release/*/*.exe.blockmap
release/*/*.dmg
release/*/*.dmg.blockmap
release/*/*.rpm
release/*/*.rpm.blockmap
release/*/*.deb
release/*/*.deb.blockmap
release/*/*.AppImage
release/*/*.AppImage.blockmap
release/*/*.tar.gz
release/*/*.tar.gz.blockmap
release/*/*.tar.xz
release/*/*.tar.xz.blockmap
release/*/alpha.yml
release/*/beta.yml
release/*/dev.yml
release/*/rc.yml
release/*/stable.yml
release/*/latest.yml
release/*/alpha-*.yml
release/*/beta-*.yml
release/*/dev-*.yml
release/*/rc-*.yml
release/*/stable-*.yml
release/*/latest-*.yml
publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
# if: startsWith(github.ref, 'refs/heads/main')
steps:
- name: Get current date
id: date
# bash, sh, cmd, powershell, pwsh
# shell 类型必须为 sh,否则:
# $GITHUB_ENV:仅支持 ubuntu、macos
# $env:GITHUB_ENV:仅支持 windows
shell: sh
run: |
echo "YEAR_MONTH_DAY=$(date +'%Y-%m-%dZ')" >> $GITHUB_ENV
echo "YEAR_MONTH_DAY_HOUR=$(date +'%Y-%m-%dT%HZ')" >> $GITHUB_ENV
echo "YEAR_MONTH_DAY_HOUR_MINUTE=$(date +'%Y-%m-%dT%H-%MZ')" >> $GITHUB_ENV
- name: Download Artifacts electron-tools-ubuntu-latest-x64
uses: actions/download-artifact@v4.1.7
with:
name: electron-tools-ubuntu-latest-x64
path: .
- run: ls *.*.*
- name: Download Artifacts electron-tools-windows-latest-x64
uses: actions/download-artifact@v4.1.7
with:
name: electron-tools-windows-latest-x64
path: .
- run: ls *.*.*
- name: Download Artifacts electron-tools-macos-latest-arm64
uses: actions/download-artifact@v4.1.7
with:
name: electron-tools-macos-latest-arm64
path: ./arm64
- run: ls ./arm64/*.*.*
- run: cat ./arm64/*.*.*/latest-mac.yml
- run: ls *.*.*
- name: Download Artifacts electron-tools-macos-latest-x64
uses: actions/download-artifact@v4.1.7
with:
name: electron-tools-macos-latest-x64
path: ./x64
- run: ls ./x64/*.*.*
- run: cat ./x64/*.*.*/latest-mac.yml
- run: ls *.*.*
- run: (cat x64/*.*.*/latest-mac.yml | sed '/files:/q') > latest-mac.yml && cat arm64/*.*.*/latest-mac.yml | grep ' - url\| sha512\| size' >> latest-mac.yml && cat x64/*.*.*/latest-mac.yml | sed -n '/files:/,$p' | tail -n +2 >> latest-mac.yml
- run: cat latest-mac.yml
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: |
*/*.exe
*/*.exe.blockmap
*/*.dmg
*/*.dmg.blockmap
arm64/*/*.dmg
arm64/*/*.dmg.blockmap
x64/*/*.dmg
x64/*/*.dmg.blockmap
*/*.rpm
*/*.rpm.blockmap
*/*.deb
*/*.deb.blockmap
*/*.AppImage
*/*.AppImage.blockmap
*/*.tar.gz
*/*.tar.gz.blockmap
*/*.tar.xz
*/*.tar.xz.blockmap
*/alpha.yml
*/beta.yml
*/dev.yml
*/rc.yml
*/stable.yml
*/latest.yml
*/alpha-*.yml
*/beta-*.yml
*/dev-*.yml
*/rc-*.yml
*/stable-*.yml
*/latest-*.yml
latest-mac.yml
body:
自动推送时的发布
# draft: 草稿状态,为 true 时,不创建标签,默认为 false
# draft: true
# prerelease:是否发布预发布版,默认为 false
prerelease: true
name: 1.0.0-${{ env.YEAR_MONTH_DAY_HOUR_MINUTE }}
tag: v1.0.0-${{ env.YEAR_MONTH_DAY_HOUR_MINUTE }}
token: ${{ secrets.GITHUB_TOKEN }}
# https://docs.github.com/zh/enterprise-cloud@latest/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
dependabot:
name: Dependabot
# 需要所有 build 完成后,才运行
needs: build
runs-on: ${{ matrix.os }}
permissions:
# 可以修改仓库中的文件内容
contents: write
# # 可以新建或修改 Pull Request
pull-requests: write
# 依赖机器人 && 仅PR
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
strategy:
matrix:
os: [ "ubuntu-latest" ]
steps:
# 检出代码
- name: Checkout repository
uses: actions/checkout@v3
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: echo
run: |
echo ${{ github.event.pull_request.html_url }}
echo ${{ steps.metadata.outputs.dependency-names }}
echo ${{ steps.metadata.outputs.update-type }}
echo ${{ 'version-update:semver-patch' }}
- name: Enable auto-merge for Dependabot PRs
# if: ${{contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 将 main 分支代码同步到 极狐GitLab
- name: Sync JihuLab
run: |
git config --global user.email "xuxiaowei@xuxiaowei.com.cn"
git config --global user.name "徐晓伟"
# 设置 SSH 秘钥
mkdir -p ~/.ssh
echo "${{ secrets.JIHULAB_ID_RSA }}" >> ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
# 信任域名
ssh-keyscan -H jihulab.com >> ~/.ssh/known_hosts
# 切换 main 分支
git checkout main
# 拉取 main 分支
git pull origin main
# 查看远端 极狐GitLab
echo git@jihulab.com:$GITHUB_REPOSITORY.git
# 添加远端 极狐GitLab
git remote add jihulab git@jihulab.com:$GITHUB_REPOSITORY.git
# 拉取 main 分支
git pull --progress -v --no-rebase jihulab main
# 推送 main 分支
git push --progress jihulab main:main
sync:
name: Sync
# 需要所有 build 完成后,才运行
needs: build
# 仅在推送代码时执行
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ "ubuntu-latest" ]
steps:
# 检出代码
- name: Checkout repository
uses: actions/checkout@v3
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
# 将代码同步到 极狐GitLab
- name: Sync JihuLab
run: |
git config --global user.email "xuxiaowei@xuxiaowei.com.cn"
git config --global user.name "徐晓伟"
# 设置 SSH 秘钥
mkdir -p ~/.ssh
echo "${{ secrets.JIHULAB_ID_RSA }}" >> ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
# 信任域名
ssh-keyscan -H jihulab.com >> ~/.ssh/known_hosts
# 查看当前分支
echo 当前分支:$GITHUB_REF_NAME
# 查看远端 极狐GitLab
echo git@jihulab.com:$GITHUB_REPOSITORY.git
# 添加远端 极狐GitLab
git remote add jihulab git@jihulab.com:$GITHUB_REPOSITORY.git
# 拉取
git pull --progress -v --no-rebase jihulab $GITHUB_REF_NAME
# 推送当前分支
git push --progress jihulab $GITHUB_REF_NAME:$GITHUB_REF_NAME