增量更新 #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 增量更新 | |
| on: | |
| schedule: | |
| - cron: '0 2 * * 0' | |
| workflow_dispatch: | |
| jobs: | |
| update-html-image: | |
| name: 增量 HTML+图片 | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 360 | |
| env: | |
| TWITTER_PROXY_BASE: ${{ secrets.TWITTER_PROXY_BASE }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: 检出仓库 | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 读取账号列表 | |
| id: info | |
| run: | | |
| # 扫描 accounts/ 目录,取所有含 wayback_snapshots 的子目录 = 真实账号列表 | |
| # 支持单账号 / 多账号 / 仓库名≠账号名;不依赖 accounts.txt | |
| ACCOUNTS=$(ls -1 accounts 2>/dev/null | while IFS= read -r name; do | |
| [ -d "accounts/${name}/wayback_snapshots" ] && echo "$name" | |
| done) | |
| # 兜底:扫不到(首次建档前)则用仓库名 | |
| if [ -z "$ACCOUNTS" ]; then | |
| ACCOUNTS=$(echo "${{ github.repository }}" | cut -d'/' -f2) | |
| fi | |
| echo "accounts<<EOF" >> $GITHUB_OUTPUT | |
| echo "$ACCOUNTS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 检查数据目录 | |
| id: check | |
| run: | | |
| SKIP=true | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ -d "accounts/${U}/wayback_snapshots" ]; then | |
| SKIP=false | |
| break | |
| fi | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| echo "skip=$SKIP" >> $GITHUB_OUTPUT | |
| if [ "$SKIP" = "true" ]; then echo "⚠️ 请先运行首次建档"; fi | |
| - name: 安装依赖 | |
| if: steps.check.outputs.skip == 'false' | |
| run: pip install requests beautifulsoup4 lxml | |
| - name: 拉取最新 archive.py 和前端文件 | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| curl -fsSL "https://raw.githubusercontent.com/sjshb57/Test/main/archive.py" \ | |
| -o /tmp/archive.py | |
| curl -fsSL "https://raw.githubusercontent.com/sjshb57/Test/main/index.html" \ | |
| -o index.html || true | |
| ACCOUNTS="${{ steps.info.outputs.accounts }}" | |
| ACCOUNTS_JSON=$(echo "$ACCOUNTS" | awk '{printf "'\''%s'\'', ", $0}' | sed "s/, $//") | |
| sed -i "s/const ACCOUNTS_HARDCODED = \[.*\]/const ACCOUNTS_HARDCODED = [${ACCOUNTS_JSON}]/" index.html || true | |
| echo "✅ archive.py ($(wc -l < /tmp/archive.py) 行)" | |
| - name: fetch-cdx | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py fetch-cdx "$U" || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: fetch-html | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py fetch-html || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: fetch-image | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py fetch-image || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: retry --image-failed | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py retry --image-failed || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: clean-html --force | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py clean-html --force || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: 推送 | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git diff --cached --name-only | while IFS= read -r f; do | |
| if [ ! -f "$f" ]; then continue; fi | |
| size=$(stat -c%s "$f" 2>/dev/null || echo 0) | |
| if [ "$size" -gt 104857600 ]; then git rm --cached "$f"; fi | |
| done | |
| git diff --cached --quiet && echo "无新内容" && exit 0 | |
| COUNT=$(git diff --cached --name-only | grep -v -e "/_log/" -e "/archive_index\.json$" -e "/index\.json$" -e "/media_index\.json$" | wc -l) | |
| [ "$COUNT" -eq 0 ] && COUNT=$(git diff --cached --numstat | wc -l) | |
| git commit -m "🔄 增量 HTML+图片 (+${COUNT} 文件) $(date -u +%Y-%m-%d) [skip ci]" | |
| git push | |
| update-video: | |
| name: 增量 视频 | |
| needs: update-html-image | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 360 | |
| env: | |
| TWITTER_PROXY_BASE: ${{ secrets.TWITTER_PROXY_BASE }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: 检出仓库(拉最新) | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: 读取账号列表 | |
| id: info | |
| run: | | |
| # 扫描 accounts/ 目录,取所有含 wayback_snapshots 的子目录 = 真实账号列表 | |
| # 支持单账号 / 多账号 / 仓库名≠账号名;不依赖 accounts.txt | |
| ACCOUNTS=$(ls -1 accounts 2>/dev/null | while IFS= read -r name; do | |
| [ -d "accounts/${name}/wayback_snapshots" ] && echo "$name" | |
| done) | |
| # 兜底:扫不到(首次建档前)则用仓库名 | |
| if [ -z "$ACCOUNTS" ]; then | |
| ACCOUNTS=$(echo "${{ github.repository }}" | cut -d'/' -f2) | |
| fi | |
| echo "accounts<<EOF" >> $GITHUB_OUTPUT | |
| echo "$ACCOUNTS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 安装依赖 | |
| run: pip install requests beautifulsoup4 lxml | |
| - name: 拉取最新 archive.py | |
| run: curl -fsSL "https://raw.githubusercontent.com/sjshb57/Test/main/archive.py" -o /tmp/archive.py | |
| - name: fetch-video | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py fetch-video || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: retry --video-failed | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py retry --video-failed || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: clean-html --force | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py clean-html --force || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: 推送 | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git diff --cached --name-only | while IFS= read -r f; do | |
| if [ ! -f "$f" ]; then continue; fi | |
| size=$(stat -c%s "$f" 2>/dev/null || echo 0) | |
| if [ "$size" -gt 104857600 ]; then git rm --cached "$f"; fi | |
| done | |
| git diff --cached --quiet && echo "无新内容" && exit 0 | |
| COUNT=$(git diff --cached --name-only | grep -v -e "/_log/" -e "/archive_index\.json$" -e "/index\.json$" -e "/media_index\.json$" | wc -l) | |
| [ "$COUNT" -eq 0 ] && COUNT=$(git diff --cached --numstat | wc -l) | |
| git commit -m "🎬 增量 视频 (+${COUNT} 文件) $(date -u +%Y-%m-%d) [skip ci]" | |
| git push | |
| update-avatar: | |
| name: 增量 头像+收尾 | |
| needs: update-video | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 360 | |
| env: | |
| TWITTER_PROXY_BASE: ${{ secrets.TWITTER_PROXY_BASE }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: 检出仓库(拉最新) | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: 读取账号列表 | |
| id: info | |
| run: | | |
| # 扫描 accounts/ 目录,取所有含 wayback_snapshots 的子目录 = 真实账号列表 | |
| # 支持单账号 / 多账号 / 仓库名≠账号名;不依赖 accounts.txt | |
| ACCOUNTS=$(ls -1 accounts 2>/dev/null | while IFS= read -r name; do | |
| [ -d "accounts/${name}/wayback_snapshots" ] && echo "$name" | |
| done) | |
| # 兜底:扫不到(首次建档前)则用仓库名 | |
| if [ -z "$ACCOUNTS" ]; then | |
| ACCOUNTS=$(echo "${{ github.repository }}" | cut -d'/' -f2) | |
| fi | |
| echo "accounts<<EOF" >> $GITHUB_OUTPUT | |
| echo "$ACCOUNTS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 安装依赖 | |
| run: pip install requests beautifulsoup4 lxml | |
| - name: 拉取最新 archive.py | |
| run: curl -fsSL "https://raw.githubusercontent.com/sjshb57/Test/main/archive.py" -o /tmp/archive.py | |
| - name: fetch-avatars | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py fetch-avatars || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: retry --avatar-failed | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py retry --avatar-failed || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: clean-html --force | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py clean-html --force || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: build-index | |
| run: | | |
| while IFS= read -r U; do | |
| if [ -z "$U" ]; then continue; fi | |
| if [ ! -d "accounts/${U}/wayback_snapshots" ]; then continue; fi | |
| cd accounts/${U} && python3 /tmp/archive.py build-index || true | |
| cd ../.. | |
| done <<< "${{ steps.info.outputs.accounts }}" | |
| - name: 推送 | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git diff --cached --name-only | while IFS= read -r f; do | |
| if [ ! -f "$f" ]; then continue; fi | |
| size=$(stat -c%s "$f" 2>/dev/null || echo 0) | |
| if [ "$size" -gt 104857600 ]; then git rm --cached "$f"; fi | |
| done | |
| if git diff --cached --quiet; then echo "✅ 本周无新内容"; exit 0; fi | |
| COUNT=$(git diff --cached --name-only | grep -v -e "/_log/" -e "/archive_index\.json$" -e "/index\.json$" -e "/media_index\.json$" | wc -l) | |
| [ "$COUNT" -eq 0 ] && COUNT=$(git diff --cached --numstat | wc -l) | |
| git commit -m "✅ 增量完成 (+${COUNT} 文件) $(date -u +%Y-%m-%d) [skip ci]" | |
| git push |