forked from PKM-er/Pkmer-Math
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (112 loc) · 5.73 KB
/
Copy pathstatic.yml
File metadata and controls
124 lines (112 loc) · 5.73 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
name: 部署文档
on:
push:
branches: ["main"] # 确保这是你正在使用的分支名称
workflow_dispatch:
permissions:
contents: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy-gh-pages:
runs-on: ubuntu-latest
steps:
- name: 环境 - 构建库
uses: actions/checkout@v4
with:
fetch-depth: 1
repository: LincZero/LincZero.github.io
# 固定到最近成功构建实际使用的版本,避免外部 main 漂移。
ref: '54cdc975bfad38ccd60244430afecc511d4592e1'
- name: 环境 - 安装 pnpm
uses: pnpm/action-setup@v4
with:
run_install: true
version: 9
- name: 环境 - 设置 Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
# 获取仓库的相关配置
# https://docs.github.com/zh/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
# TODO:若 “仓库无前缀名” 是.github.io结尾,则设置为"/"
- name: 配置 - 获取仓库配置
id: config1 # 用于给其他步骤引用
working-directory: ./scripts/
run: |
> git_config.json # 先清空
echo "{" >> git_config.json
echo " \"GITHUB_WORKSPACE\": \"${GITHUB_WORKSPACE}\"," >> git_config.json # 工作路径
echo " \"GITHUB_ACTION_PATH\": \"${GITHUB_ACTION_PATH}\"," >> git_config.json # action路径
echo " \"GITHUB_ACTION_REPOSITORY\": \"${GITHUB_ACTION_REPOSITORY}\"," >> git_config.json # action仓库
echo " \"GITHUB_REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\"," >> git_config.json # 仓库所属(格式: 可以是组织)
echo " \"GITHUB_ACTOR\": \"${GITHUB_ACTOR}\"," >> git_config.json # 仓库作者(格式: 不会是组织)
echo " \"GITHUB_REPOSITORY\": \"${GITHUB_REPOSITORY}\"," >> git_config.json # 仓库标识(格式: 个人或组织/仓库名)
echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d"/" -f2)
echo " \"CALC_REPO_NAME\": \"${REPO_NAME}\"" >> git_config.json # 仓库无前缀名
echo "}" >> git_config.json
echo "::set-output name=REPO_NAME::$REPO_NAME"
# [!code] 根据实际情况修改
- name: 配置 - 设置
working-directory: ./
run: |
# sed -i 's/base: \"\/\"/base: \"\/${{steps.config1.outputs.REPO_NAME}}\/\"/g' ./src/.vuepress/config.ts
cat ./scripts/git_config.json
rm -f ./src/.vuepress/config_cover.js
rm -f ./src/.vuepress/theme_cover.js
# generate_config.cjs 只读取这两个文件并打印可选插件提示。
# 使用 CI 临时空配置消除误导性 ENOENT;不复用或发布个人 Obsidian 配置。
mkdir -p ./src/.obsidian
printf '{}\n' > ./src/.obsidian/core-plugins.json
printf '[]\n' > ./src/.obsidian/community-plugins.json
pnpm run gen-config
rm -f ./src/.obsidian/core-plugins.json ./src/.obsidian/community-plugins.json
rmdir ./src/.obsidian
# 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间
- name: 文档 - 文档库克隆
working-directory: ./src/
run: |
# --depth 1 选项会损失git历史,但能加速编译。可自行启用/关闭
# 注意若使用该选项,必须要删除 .git 文件夹,避免时间和贡献者错乱
git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo
rm -rf temp_repo/.git
rsync -a temp_repo/ .
rm -rf temp_repo
# git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突
# 构建峰值已超过标准 runner 的物理内存;使用一次性磁盘交换空间,
# 不改变 VuePress 配置或网页功能。runner 销毁时该文件会一并消失。
- name: 环境 - 扩展构建交换空间
run: |
swap_path=/mnt/pkmer-build.swap
available_kb=$(df --output=avail -k /mnt | tail -n 1)
required_kb=$((12 * 1024 * 1024))
if (( available_kb < required_kb )); then
echo "::error::可用磁盘不足 12 GiB,拒绝创建 8 GiB 构建交换文件。"
exit 1
fi
sudo fallocate -l 8G "$swap_path"
sudo chmod 600 "$swap_path"
sudo mkswap "$swap_path"
sudo swapon "$swap_path"
df -h /mnt
free -h
- name: 文档 - 构建
env:
# 实测 13 GiB 会在 Vite 编译阶段触发 V8 heap OOM;暂时恢复原上限。
# 这不能突破 runner 的物理内存,长期仍需更大 runner 或上游构建优化。
NODE_OPTIONS: --max_old_space_size=20480
run: |-
node -e 'console.log(v8.getHeapStatistics())'
/usr/bin/time -v pnpm run docs:build
> src/.vuepress/dist/.nojekyll
- name: 文档 - 部署
uses: JamesIves/github-pages-deploy-action@v4
with:
# 这是文档部署到的分支名称
branch: gh-pages
folder: src/.vuepress/dist