This commit is contained in:
Vaica committed 2026-06-29 17:15:56 +08:00
1 parent cb952e6c96
commit 9a9dbb264f
3 files changed
+91 -83

No files matched your search

+72 -81
View File
@@ -60,7 +60,7 @@ jobs:
if echo "$COMMIT_MESSAGE" | grep -qE "^(feat|fix|chore|docs|style|refactor|test): "; then
echo "✅ 提交信息符合规范"
else
echo "⚠️ 提交信息格式建议: feat/fix/chore/docs/style/refactor/test: description"
echo "⚠️ 提交信息格式建议: feat/fix/chore/docs/style/refactor/test: description"
fi
- name: Check for new commits (only for cron)
@@ -201,6 +201,29 @@ jobs:
path: public/
retention-days: 1
- name: Upload build hash to UpYun
env:
UPYUN_SERVICE: ${{ secrets.UPYUN_BUCKET }}
UPYUN_OPERATOR: ${{ secrets.UPYUN_OPERATOR }}
UPYUN_PASSWORD: ${{ secrets.UPYUN_PASSWORD }}
run: |
echo "📤 上传 build_hash 到 UpYun..."
UPX_VERSION="0.4.9"
UPX_URL="https://collection.b0.upaiyun.com/softwares/upx/upx_${UPX_VERSION}_linux_amd64.tar.gz"
UPX_BIN="/tmp/upyun-upx"
if [ ! -x "$UPX_BIN" ]; then
curl -sL "$UPX_URL" -o /tmp/upx.tar.gz
tar -xzf /tmp/upx.tar.gz -C /tmp
mv /tmp/upx "$UPX_BIN"
chmod +x "$UPX_BIN"
fi
"$UPX_BIN" login "$UPYUN_SERVICE" "$UPYUN_OPERATOR" "$UPYUN_PASSWORD"
"$UPX_BIN" put public/.build_hash /__build_hash
echo "✅ build_hash 已上传到 UpYun"
- name: Push Image Optimizations
continue-on-error: true
run: |
@@ -238,7 +261,6 @@ jobs:
timeout-minutes: 10
permissions:
contents: read
actions: read
needs: build
outputs:
deployed: ${{ steps.check.outputs.deployed }}
@@ -251,49 +273,35 @@ jobs:
id: start-edgeone
run: echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT
- name: Get last successful run info
id: last-run
run: |
echo "🔍 查找上一次成功部署的 hash..."
# 获取上一个成功的 workflow run(排除当前 run)
LAST_RUN=$(gh api repos/${{ github.repository }}/actions/runs \
--jq '.workflow_runs[] | select(.conclusion == "success") | select(.id != $RUN_ID) | {id: .id, head_sha: .head_sha}' \
--paginate \
--limit 10 \
-F run_id=${{ github.run_id }} 2>/dev/null | head -2)
if [ -z "$LAST_RUN" ]; then
echo "没有找到上一次成功运行的记录"
echo "last_run_id=" >> $GITHUB_OUTPUT
echo "last_hash=" >> $GITHUB_OUTPUT
else
LAST_RUN_ID=$(echo "$LAST_RUN" | jq -r '.id')
LAST_SHA=$(echo "$LAST_RUN" | jq -r '.head_sha')
echo "上次成功运行 ID: $LAST_RUN_ID"
echo "上次成功运行 SHA: $LAST_SHA"
echo "last_run_id=${LAST_RUN_ID}" >> $GITHUB_OUTPUT
fi
- name: Download last artifact and get hash
- name: Get last build hash from UpYun
id: last-hash
if: steps.last-run.outputs.last_run_id != ''
env:
UPYUN_SERVICE: ${{ secrets.UPYUN_BUCKET }}
UPYUN_OPERATOR: ${{ secrets.UPYUN_OPERATOR }}
UPYUN_PASSWORD: ${{ secrets.UPYUN_PASSWORD }}
run: |
LAST_RUN_ID="${{ steps.last-run.outputs.last_run_id }}"
echo "🔍 从 UpYun 获取上次部署的 hash..."
echo "� 下载上次成功的 artifact..."
gh api repos/${{ github.repository }}/actions/runs/$LAST_RUN_ID/artifacts \
--jq '.artifacts[] | select(.name == "hugo-public") | .id' > /tmp/last_artifact_id.txt
UPX_VERSION="0.4.9"
UPX_URL="https://collection.b0.upaiyun.com/softwares/upx/upx_${UPX_VERSION}_linux_amd64.tar.gz"
UPX_BIN="/tmp/upyun-upx"
LAST_ARTIFACT_ID=$(cat /tmp/last_artifact_id.txt)
if [ -n "$LAST_ARTIFACT_ID" ]; then
gh api repos/${{ github.repository }}/actions/artifacts/$LAST_ARTIFACT_ID/archive --output /tmp/last_artifact.zip
unzip -p /tmp/last_artifact.zip .build_hash 2>/dev/null || echo ""
LAST_HASH=$(unzip -p /tmp/last_artifact.zip .build_hash 2>/dev/null)
echo "上次部署 hash: $LAST_HASH"
echo "last_hash=${LAST_HASH}" >> $GITHUB_OUTPUT
if [ ! -x "$UPX_BIN" ]; then
curl -sL "$UPX_URL" -o /tmp/upx.tar.gz
tar -xzf /tmp/upx.tar.gz -C /tmp
mv /tmp/upx "$UPX_BIN"
chmod +x "$UPX_BIN"
fi
"$UPX_BIN" login "$UPYUN_SERVICE" "$UPYUN_OPERATOR" "$UPYUN_PASSWORD"
LAST_HASH=$("$UPX_BIN" get /__build_hash 2>/dev/null || echo "")
if [ -z "$LAST_HASH" ]; then
echo "⚠️ 没有找到上次部署的 hash(首次部署)"
else
echo "上次部署 hash: $LAST_HASH"
fi
echo "last_hash=${LAST_HASH}" >> $GITHUB_OUTPUT
- name: Checkout code (for scripts)
uses: actions/checkout@v4
@@ -372,7 +380,6 @@ jobs:
timeout-minutes: 20
permissions:
contents: read
actions: read
needs: build
outputs:
deployed: ${{ steps.check.outputs.deployed }}
@@ -385,49 +392,35 @@ jobs:
id: start-upyun
run: echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT
- name: Get last successful run info
id: last-run
run: |
echo "🔍 查找上一次成功部署的 hash..."
# 获取上一个成功的 workflow run(排除当前 run)
LAST_RUN=$(gh api repos/${{ github.repository }}/actions/runs \
--jq '.workflow_runs[] | select(.conclusion == "success") | select(.id != $RUN_ID) | {id: .id, head_sha: .head_sha}' \
--paginate \
--limit 10 \
-F run_id=${{ github.run_id }} 2>/dev/null | head -2)
if [ -z "$LAST_RUN" ]; then
echo "没有找到上一次成功运行的记录"
echo "last_run_id=" >> $GITHUB_OUTPUT
echo "last_hash=" >> $GITHUB_OUTPUT
else
LAST_RUN_ID=$(echo "$LAST_RUN" | jq -r '.id')
LAST_SHA=$(echo "$LAST_RUN" | jq -r '.head_sha')
echo "上次成功运行 ID: $LAST_RUN_ID"
echo "上次成功运行 SHA: $LAST_SHA"
echo "last_run_id=${LAST_RUN_ID}" >> $GITHUB_OUTPUT
fi
- name: Download last artifact and get hash
- name: Get last build hash from UpYun
id: last-hash
if: steps.last-run.outputs.last_run_id != ''
env:
UPYUN_SERVICE: ${{ secrets.UPYUN_BUCKET }}
UPYUN_OPERATOR: ${{ secrets.UPYUN_OPERATOR }}
UPYUN_PASSWORD: ${{ secrets.UPYUN_PASSWORD }}
run: |
LAST_RUN_ID="${{ steps.last-run.outputs.last_run_id }}"
echo "🔍 从 UpYun 获取上次部署的 hash..."
echo "� 下载上次成功的 artifact..."
gh api repos/${{ github.repository }}/actions/runs/$LAST_RUN_ID/artifacts \
--jq '.artifacts[] | select(.name == "hugo-public") | .id' > /tmp/last_artifact_id.txt
UPX_VERSION="0.4.9"
UPX_URL="https://collection.b0.upaiyun.com/softwares/upx/upx_${UPX_VERSION}_linux_amd64.tar.gz"
UPX_BIN="/tmp/upyun-upx"
LAST_ARTIFACT_ID=$(cat /tmp/last_artifact_id.txt)
if [ -n "$LAST_ARTIFACT_ID" ]; then
gh api repos/${{ github.repository }}/actions/artifacts/$LAST_ARTIFACT_ID/archive --output /tmp/last_artifact.zip
unzip -p /tmp/last_artifact.zip .build_hash 2>/dev/null || echo ""
LAST_HASH=$(unzip -p /tmp/last_artifact.zip .build_hash 2>/dev/null)
echo "上次部署 hash: $LAST_HASH"
echo "last_hash=${LAST_HASH}" >> $GITHUB_OUTPUT
if [ ! -x "$UPX_BIN" ]; then
curl -sL "$UPX_URL" -o /tmp/upx.tar.gz
tar -xzf /tmp/upx.tar.gz -C /tmp
mv /tmp/upx "$UPX_BIN"
chmod +x "$UPX_BIN"
fi
"$UPX_BIN" login "$UPYUN_SERVICE" "$UPYUN_OPERATOR" "$UPYUN_PASSWORD"
LAST_HASH=$("$UPX_BIN" get /__build_hash 2>/dev/null || echo "")
if [ -z "$LAST_HASH" ]; then
echo "⚠️ 没有找到上次部署的 hash(首次部署)"
else
echo "上次部署 hash: $LAST_HASH"
fi
echo "last_hash=${LAST_HASH}" >> $GITHUB_OUTPUT
- name: Checkout code (for scripts)
uses: actions/checkout@v4
@@ -864,7 +857,6 @@ jobs:
if [ "${{ needs.deploy-upyun.result }}" = "failure" ]; then FAILURES=$(printf "%s\n 🔴 Deploy UpYun" "$FAILURES"); fi
if [ "${{ needs.finalize.result }}" = "failure" ]; then FAILURES=$(printf "%s\n 🔴 Finalize" "$FAILURES"); fi
# 检查每个阶段的状态
PRECHECK_STATUS=$([ "${{ needs.pre-check.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.pre-check.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
BUILD_STATUS=$([ "${{ needs.build.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.build.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
EDGEONE_STATUS=$([ "${{ needs.deploy-edgeone.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.deploy-edgeone.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
@@ -915,7 +907,6 @@ jobs:
if [ "${{ needs.deploy-upyun.result }}" = "failure" ]; then FAILURES=$(printf "%s\n 🔴 Deploy UpYun" "$FAILURES"); fi
if [ "${{ needs.finalize.result }}" = "failure" ]; then FAILURES=$(printf "%s\n 🔴 Finalize" "$FAILURES"); fi
# 检查每个阶段的状态
PRECHECK_STATUS=$([ "${{ needs.pre-check.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.pre-check.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
BUILD_STATUS=$([ "${{ needs.build.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.build.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
EDGEONE_STATUS=$([ "${{ needs.deploy-edgeone.result }}" = "success" ] && echo "✅ 成功" || ([ "${{ needs.deploy-edgeone.result }}" = "failure" ] && echo "❌ 失败" || echo "⏭️ 跳过"))
+17 -1
View File
@@ -11,7 +11,8 @@
"js-yaml": "^4.1.1",
"marked": "^18.0.4",
"rss-parser": "^3.13.0",
"sqlite3": "^5.1.7"
"sqlite3": "^5.1.7",
"yaml": "^2.9.0"
},
"devDependencies": {
"edgeone": "^1.2.29",
@@ -14111,6 +14112,21 @@
"resolved": "https://registry.npmmirror.com/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/yaml": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
"integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14.6"
},
"funding": {
"url": "https://github.com/sponsors/eemeli"
}
},
"node_modules/yargs": {
"version": "17.7.2",
"resolved": "https://registry.npmmirror.com/yargs/-/yargs-17.7.2.tgz",
+2 -1
View File
@@ -6,7 +6,8 @@
"js-yaml": "^4.1.1",
"marked": "^18.0.4",
"rss-parser": "^3.13.0",
"sqlite3": "^5.1.7"
"sqlite3": "^5.1.7",
"yaml": "^2.9.0"
},
"devDependencies": {
"edgeone": "^1.2.29",