perf(ci): 兼容 GitHub Actions 并大幅缩短构建耗时
Deploy to Production / pre-check (push) Failing after 2m54s
Deploy to Production / build (push) Skipped
Deploy to Production / deploy-edgeone (push) Skipped
Deploy to Production / deploy-upyun (push) Skipped
Deploy to Production / finalize (push) Skipped
Deploy to Production / notify-failure (push) Successful in 6s
Deploy to Production / pre-check (push) Failing after 2m54s
Deploy to Production / build (push) Skipped
Deploy to Production / deploy-edgeone (push) Skipped
Deploy to Production / deploy-upyun (push) Skipped
Deploy to Production / finalize (push) Skipped
Deploy to Production / notify-failure (push) Successful in 6s
兼容性(迁移回 GitHub Actions 必需):
- 移除 5 处 ${{ gitea.* }} 专有上下文(Gitea 之外会求值失败),
改为按 github.server_url 判断的 RUN_URL,GitHub / Gitea 通用
- Telegram / 飞书 / 邮件里的运行详情链接两边都正确
耗时优化:
- build: checkout 加 filter=blob:none(partial clone),
保留完整提交历史供 Hugo 的 :git lastmod 使用,
但不拉历史版本的文件内容(多为图片),省约 200MB 传输
- deploy-edgeone: 移除 checkout(原先约 81 秒),内联原 deploy_edgeone.sh
- finalize: 移除 checkout(约 145 秒)与 npm ci(约 66 秒),
内联零依赖的 refresh_cdn.js(只用 node 内置 crypto 与 fetch)
- finalize: setup-node 不再启用 npm 缓存(本 job 已不安装依赖)
UpYun 相关按用户要求保持原样不动。
This commit is contained in:
1 parent
ad118b470d
commit
92326fff38
1 file changed
+109
-26
+109
-26
@@ -137,6 +137,10 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
# Hugo 的 lastmod 用了 :git,必须保留完整提交历史(commit/tree),
|
||||
# 但历史版本的文件内容(blob,多为图片)不需要。
|
||||
# partial clone 只按需拉取当前工作区的 blob,实测本仓库可省约 200MB 传输。
|
||||
filter: blob:none
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v2
|
||||
@@ -410,12 +414,6 @@ jobs:
|
||||
echo "deployed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Checkout code (for scripts)
|
||||
if: steps.check.outputs.deployed == 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup Python
|
||||
if: steps.check.outputs.deployed == 'true'
|
||||
uses: actions/setup-python@v4
|
||||
@@ -462,8 +460,16 @@ jobs:
|
||||
env:
|
||||
EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }}
|
||||
run: |
|
||||
chmod +x scripts/deploy_edgeone.sh
|
||||
./scripts/deploy_edgeone.sh hugo-blog ./public overseas
|
||||
# 内联 scripts/deploy_edgeone.sh —— 本步骤只需一个部署命令,
|
||||
# 原先为此 checkout 整个仓库要花约 81 秒,不值得。
|
||||
if [ -z "$EDGEONE_API_TOKEN" ]; then
|
||||
echo "Error: EDGEONE_API_TOKEN is not set."
|
||||
exit 1
|
||||
fi
|
||||
echo "Deploying to EdgeOne Pages..."
|
||||
echo "Project: hugo-blog | Directory: ./public | Area: overseas"
|
||||
# 国际站必须加 --area overseas
|
||||
npx edgeone pages deploy ./public -n hugo-blog -t "$EDGEONE_API_TOKEN" --area overseas
|
||||
|
||||
- name: End upload timing
|
||||
if: steps.check.outputs.deployed == 'true'
|
||||
@@ -564,22 +570,12 @@ jobs:
|
||||
id: start-finalize
|
||||
run: echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
# Gitea 的 runner 缓存服务与 job 容器跨 bridge 网络不可达,
|
||||
# 每次 restore/save 各死等约 4 分半后 ETIMEDOUT(纯浪费约 9 分钟),
|
||||
# 因此仅在 GitHub 上启用缓存;Gitea 上传空值让 setup-node 跳过缓存。
|
||||
cache: ${{ github.server_url == 'https://github.com' && 'npm' || '' }}
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci --no-audit --no-fund
|
||||
# 本 job 不再安装 npm 依赖(CDN 刷新脚本只用 node 内置模块),
|
||||
# 因此不启用 npm 缓存 —— 也免得在没有 package-lock.json 时算缓存 key 出错。
|
||||
|
||||
- name: Determine deployment status
|
||||
id: deploy-status
|
||||
@@ -602,7 +598,74 @@ jobs:
|
||||
DOGECLOUD_ACCESS_KEY: ${{ secrets.DOGECLOUD_ACCESS_KEY }}
|
||||
DOGECLOUD_SECRET_KEY: ${{ secrets.DOGECLOUD_SECRET_KEY }}
|
||||
CDN_URL_LIST: ${{ secrets.CDN_URL_LIST }}
|
||||
run: node scripts/refresh_cdn.js
|
||||
run: |
|
||||
# 内联 scripts/refresh_cdn.js(修改该文件时需同步这里)。
|
||||
# 该脚本零外部依赖 —— 仅用 node 内置的 crypto 与 fetch ——
|
||||
# 因此不必 checkout 整个仓库、也不必 npm ci(原先这两步合计约 211 秒)。
|
||||
cat > /tmp/refresh_cdn.js <<'REFRESH_CDN_EOF'
|
||||
const crypto = require("crypto");
|
||||
|
||||
async function dogecloudApi(apiPath, data = {}) {
|
||||
const accessKey = process.env.DOGECLOUD_ACCESS_KEY;
|
||||
const secretKey = process.env.DOGECLOUD_SECRET_KEY;
|
||||
|
||||
if (!accessKey || !secretKey) {
|
||||
console.error("Error: DOGECLOUD_ACCESS_KEY or DOGECLOUD_SECRET_KEY not set.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const body = JSON.stringify(data);
|
||||
const signStr = apiPath + "\n" + body;
|
||||
const sign = crypto.createHmac("sha1", secretKey).update(signStr).digest("hex");
|
||||
const authorization = `TOKEN ${accessKey}:${sign}`;
|
||||
|
||||
const res = await fetch(`https://api.dogecloud.com${apiPath}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: authorization,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body,
|
||||
});
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const cdnUrlListStr = process.env.CDN_URL_LIST;
|
||||
if (!cdnUrlListStr) {
|
||||
console.log("Warning: CDN_URL_LIST not found or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
const urlList = cdnUrlListStr
|
||||
.replace(/\n/g, ",")
|
||||
.split(",")
|
||||
.map((u) => u.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
if (urlList.length === 0) {
|
||||
console.log("No URLs to refresh.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Refreshing ${urlList.length} URLs...`);
|
||||
|
||||
const result = await dogecloudApi("/cdn/refresh/add.json", {
|
||||
rtype: "path",
|
||||
urls: JSON.stringify(urlList),
|
||||
});
|
||||
|
||||
if (result && result.code === 200) {
|
||||
console.log(`Refresh task submitted. Task ID: ${result.data.task_id}`);
|
||||
} else {
|
||||
console.error(`Failed to submit refresh task. Response: ${JSON.stringify(result)}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
REFRESH_CDN_EOF
|
||||
node /tmp/refresh_cdn.js
|
||||
|
||||
- name: Send Telegram notification with detailed timing
|
||||
env:
|
||||
@@ -672,7 +735,12 @@ jobs:
|
||||
MESSAGE="$MESSAGE""━━━━━━━━━━━━━━━━━━━━━━"$'\n'
|
||||
MESSAGE="$MESSAGE""🌐 EdgeOne Pages: $EDGEONE_STATUS"$'\n'
|
||||
MESSAGE="$MESSAGE""☁️ UpYun: $UPYUN_STATUS"$'\n\n'
|
||||
MESSAGE="$MESSAGE""🔗 [查看详情](http://23.254.236.47:3001/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }})"
|
||||
if [ "${{ github.server_url }}" = "https://github.com" ]; then
|
||||
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
else
|
||||
RUN_URL="http://23.254.236.47:3001/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
fi
|
||||
MESSAGE="$MESSAGE""🔗 [查看详情]($RUN_URL)"
|
||||
|
||||
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||
@@ -747,7 +815,12 @@ jobs:
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""━━━━━━━━━━━━━━━━━━━━━━"$'\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🌐 EdgeOne Pages: $EDGEONE_STATUS"$'\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""☁️ UpYun: $UPYUN_STATUS"$'\n\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🔗 查看详情: http://23.254.236.47:3001/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}"
|
||||
if [ "${{ github.server_url }}" = "https://github.com" ]; then
|
||||
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
else
|
||||
RUN_URL="http://23.254.236.47:3001/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
fi
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🔗 查看详情: $RUN_URL"
|
||||
|
||||
echo "📤 发送飞书通知..."
|
||||
echo "Message length: ${#MESSAGE_TEXT}"
|
||||
@@ -810,7 +883,7 @@ jobs:
|
||||
|
||||
🔗 查看详情
|
||||
──────────────────────────────────
|
||||
http://23.254.236.47:3001/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}
|
||||
${{ github.server_url == 'https://github.com' && 'https://github.com/zqlit/blog' || 'http://23.254.236.47:3001/zqlit/blog' }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
@@ -929,7 +1002,12 @@ jobs:
|
||||
MESSAGE="$MESSAGE""🌐 Deploy EdgeOne: $EDGEONE_STATUS"$'\n'
|
||||
MESSAGE="$MESSAGE""☁️ Deploy UpYun: $UPYUN_STATUS"$'\n'
|
||||
MESSAGE="$MESSAGE""📤 Finalize: $FINALIZE_STATUS"$'\n\n'
|
||||
MESSAGE="$MESSAGE""🔗 [查看详情](http://23.254.236.47:3001/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }})"
|
||||
if [ "${{ github.server_url }}" = "https://github.com" ]; then
|
||||
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
else
|
||||
RUN_URL="http://23.254.236.47:3001/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
fi
|
||||
MESSAGE="$MESSAGE""🔗 [查看详情]($RUN_URL)"
|
||||
|
||||
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||
@@ -979,7 +1057,12 @@ jobs:
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🌐 Deploy EdgeOne: $EDGEONE_STATUS"$'\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""☁️ Deploy UpYun: $UPYUN_STATUS"$'\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""📤 Finalize: $FINALIZE_STATUS"$'\n\n'
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🔗 查看详情: http://23.254.236.47:3001/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}"
|
||||
if [ "${{ github.server_url }}" = "https://github.com" ]; then
|
||||
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
else
|
||||
RUN_URL="http://23.254.236.47:3001/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
fi
|
||||
MESSAGE_TEXT="$MESSAGE_TEXT""🔗 查看详情: $RUN_URL"
|
||||
|
||||
curl -s -X POST "$FEISHU_WEBHOOK_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
|
||||
Reference in new issue
Block a user