Repository navigation
128 lines (114 loc) · 4.37 KB
/
Copy pathci.yml
File metadata and controls
128 lines (114 loc) · 4.37 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
# 单一工作流:一次构建,两条发布路径。
# build —— 所有 push(develop-builds 除外)与 PR:装依赖、构建、出文档、上传产物
# publish-develop-builds —— 仅 develop 推送:把 dist 推到 develop-builds 分支,供下游
# scratch-vm / scratch-gui 以 github:...#develop-builds 方式引用
# deploy-pages —— develop 推送或手动触发:把 playground(含 jsdoc 文档)发到 GitHub Pages
name: CI
on:
push:
# develop-builds 是本工作流自己推的,忽略它以免每次发布再触发一轮构建。
branches-ignore:
- develop-builds
pull_request:
workflow_dispatch:
# 默认只读,需要写权限的 job 再单独授予。
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# PR 上中断旧构建没有副作用;分支推送要排队,避免连续两次 develop 推送的
# develop-builds 提交互相覆盖(后完成的覆盖先完成的)。
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
# package-lock.json 中的 git 依赖以 git+ssh:// 形式记录,统一改写为 HTTPS,
# 保证依赖克隆不依赖 runner 的 SSH 配置。
- name: Use HTTPS for git dependencies
run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
- name: Install dependencies
run: npm ci --no-audit --no-fund --loglevel verbose
- name: Build
run: npm run build
# 暂时不跑测试:`npm test` 是 lint + build + tap,会重复上面的构建。
# - name: Test
# run: npm run tap
- name: Build docs
run: npm run docs
# 老版 jsdoc cli 不认识部分新语法,会报语法错误但仍然生成能用的文档,
# 所以允许失败,不让它挡住 Pages 发布。
continue-on-error: true
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
- name: Upload playground (Pages artifact)
uses: actions/upload-pages-artifact@v3
with:
path: ./playground/
publish-develop-builds:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
permissions:
contents: write
steps:
- name: Checkout repo (with push access)
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Download dist
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Publish dist to develop-builds
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 备份刚下载的 dist,后面切分支会覆盖工作区
rm -rf /tmp/dist
cp -a dist /tmp/dist
git fetch origin
# develop-builds 已存在就接上它,不存在就从 develop 新建
if git show-ref --verify --quiet refs/remotes/origin/develop-builds; then
git checkout -B develop-builds origin/develop-builds
git merge origin/develop --no-edit
else
git checkout -B develop-builds origin/develop
fi
# 只替换 dist,其余源码与 develop 保持一致
rm -rf dist
mkdir dist
cp -a /tmp/dist/. dist/
# dist 在 .gitignore 里,必须 -f
git add -f dist
git commit -m "chore: update dist from develop" || echo "No changes"
git push origin develop-builds
deploy-pages:
runs-on: ubuntu-latest
needs: build
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && github.ref == 'refs/heads/develop')
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4