Skip to content

Commit 94adbc4

Browse files
committed
update
1 parent 2e0612f commit 94adbc4

1 file changed

Lines changed: 56 additions & 19 deletions

File tree

.github/workflows/static.yml

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# take from https://github.com/LincDocs/Workflow
2+
13
name: 部署文档
24

35
on:
46
push:
57
branches: ["main"] # 确保这是你正在使用的分支名称
8+
schedule:
9+
# 定时任务。建议多个仓库错开,避免多个仓库同一时间一起坏掉。我个人用键盘阵列映射周1~5。特别是代理仓库比较需要这个
10+
- cron: '30 10 * * 1' # 每周一10:30触发工作流
611
workflow_dispatch:
712

813
permissions:
@@ -26,15 +31,15 @@ jobs:
2631
ref: 'main' # 分支,旧raw
2732

2833
- name: 环境 - 安装 pnpm
29-
uses: pnpm/action-setup@v2
34+
uses: pnpm/action-setup@v4
3035
with:
3136
run_install: true
32-
version: 8
37+
version: 9
3338

3439
- name: 环境 - 设置 Node.js
35-
uses: actions/setup-node@v3
40+
uses: actions/setup-node@v4
3641
with:
37-
node-version: 20
42+
node-version: 22
3843
cache: pnpm
3944

4045
# 获取仓库的相关配置
@@ -52,13 +57,57 @@ jobs:
5257
echo " \"GITHUB_REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\"," >> git_config.json # 仓库所属(格式: 可以是组织)
5358
echo " \"GITHUB_ACTOR\": \"${GITHUB_ACTOR}\"," >> git_config.json # 仓库作者(格式: 不会是组织)
5459
echo " \"GITHUB_REPOSITORY\": \"${GITHUB_REPOSITORY}\"," >> git_config.json # 仓库标识(格式: 个人或组织/仓库名)
55-
echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url
60+
echo " \"CALC_URL\": \"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/\"," >> git_config.json # 仓库url
5661
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d"/" -f2)
5762
echo " \"CALC_REPO_NAME\": \"${REPO_NAME}\"" >> git_config.json # 仓库无前缀名
5863
echo "}" >> git_config.json
5964
echo "::set-output name=REPO_NAME::$REPO_NAME"
6065
61-
# [!code] 根据实际情况修改
66+
- name: 文档 - 文档克隆1 # 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间
67+
working-directory: ./src/
68+
run: |
69+
rm README.md
70+
71+
# git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突
72+
# --depth 1 选项会损失git历史,但能加速编译。可自行启用/关闭
73+
# 注意若使用该选项,必须要删除 .git 文件夹,避免时间和贡献者错乱
74+
git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo
75+
rm -rf temp_repo/.git
76+
77+
- name: 文档 - 文档克隆2, 允许使用代理仓库/指定文件夹
78+
working-directory: ./src/
79+
run: |
80+
# step1. 克隆被代理仓库
81+
# 该仓库为代理仓库时,使用链接仓库而非此仓库
82+
# TODO 支持agency多个仓库。如果想更通用,干脆支持直接运行agency里的命令组
83+
if [ -f temp_repo/agency ]; then
84+
echo "with agency"
85+
GIT_LINK=$(sed -n '1p' temp_repo/agency | tr -d '\r')
86+
DIR=$(sed -n '2p' temp_repo/agency | tr -d '\r')
87+
rm -rf temp_repo
88+
git clone --depth 1 $GIT_LINK temp_repo
89+
rm -rf temp_repo/.git
90+
else
91+
echo "without agency"
92+
DIR="docs/"
93+
fi
94+
95+
# 使用指定文件夹
96+
if [ -d "temp_repo/${DIR}" ]; then
97+
echo "with docs folder: temp_repo/${DIR}"
98+
# find temp_repo/* -maxdepth 0 -name docs -prune -o -exec rm -rf {} \;
99+
# ls -l temp_repo/website/docs/ # debug
100+
mv "temp_repo/${DIR}"/* .
101+
rm -rf temp_repo
102+
else
103+
echo "without docs folder: temp_repo/${DIR}"
104+
rsync -a temp_repo/ .
105+
rm -rf temp_repo
106+
fi
107+
echo "---"
108+
ls
109+
110+
# [!code] 根据实际情况修改 (需要在仓库配置写入以及和文档仓库clone这两个步骤的后面)
62111
- name: 配置 - 设置
63112
working-directory: ./
64113
run: |
@@ -68,18 +117,6 @@ jobs:
68117
rm -f ./src/.vuepress/theme_cover.js
69118
pnpm run gen-config
70119
71-
# 文档的克隆、构建、部署。注意 `clone --depth 1` 只拉最近一次提交,减少时间
72-
- name: 文档 - 文档库克隆
73-
working-directory: ./src/
74-
run: |
75-
# --depth 1 选项会损失git历史,但能加速编译。可自行启用/关闭
76-
# 注意若使用该选项,必须要删除 .git 文件夹,避免时间和贡献者错乱
77-
git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git temp_repo
78-
rm -rf temp_repo/.git
79-
rsync -a temp_repo/ .
80-
rm -rf temp_repo
81-
# git clone --depth 1 https://github.com/${GITHUB_REPOSITORY}.git # 如果有多个clone项则替换成这个,避免冲突
82-
83120
- name: 文档 - 构建
84121
env:
85122
NODE_OPTIONS: --max_old_space_size=20480
@@ -89,7 +126,7 @@ jobs:
89126
> src/.vuepress/dist/.nojekyll
90127
91128
- name: 文档 - 部署
92-
uses: JamesIves/github-pages-deploy-action@v4
129+
uses: JamesIves/github-pages-deploy-action@v4.7.3
93130
with:
94131
# 这是文档部署到的分支名称
95132
branch: gh-pages

0 commit comments

Comments
 (0)