Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name: 維基百科每日統計自動更新
- on:
- schedule:
- # 每天多個時間點執行,確保至少有一次成功
- - cron: '15 1 * * *' # UTC 01:15
- - cron: '15 5 * * *' # UTC 05:15
- - cron: '15 9 * * *' # UTC 09:15
- - cron: '15 13 * * *' # UTC 13:15
- # 允許手動觸發
- workflow_dispatch:
- jobs:
- update-stats:
- runs-on: ubuntu-latest
- timeout-minutes: 15
- steps:
- - name: 檢出代碼
- uses: actions/checkout@v4
- with:
- fetch-depth: 1
- - name: 設置 Python 環境
- uses: actions/setup-python@v5
- with:
- python-version: '3.11'
- cache: 'pip'
- - name: 安裝依賴
- working-directory: python-scripts/stat_updater
- run: |
- python -m pip install --upgrade pip
- pip install -r requirements.txt
- - name: 檢查今日是否已更新
- id: check_updated
- working-directory: python-scripts/stat_updater
- run: |
- if python check_if_updated_today.py; then
- echo "already_updated=true" >> $GITHUB_OUTPUT
- echo "今日統計已更新,跳過執行"
- else
- echo "already_updated=false" >> $GITHUB_OUTPUT
- echo "今日尚未更新,開始執行"
- fi
- continue-on-error: true
- - name: 執行統計更新
- if: steps.check_updated.outputs.already_updated != 'true'
- working-directory: python-scripts/stat_updater
- # 使用 GitHub Secrets 傳遞憑證(更安全)
- env:
- WIKI_USERNAME: ${{ secrets.WIKI_USERNAME }}
- WIKI_PASSWORD: ${{ secrets.WIKI_PASSWORD }}
- run: |
- max_attempts=3
- attempt=1
- while [ $attempt -le $max_attempts ]; do
- echo "=== 第 $attempt 次嘗試執行維基百科統計更新 ==="
- if python wikipedia_stats_updater.py; then
- echo "維基百科統計更新成功!"
- exit 0
- else
- echo "第 $attempt 次嘗試失敗"
- if [ $attempt -lt $max_attempts ]; then
- wait_time=$((attempt * 60))
- echo "等待 $wait_time 秒後重試..."
- sleep $wait_time
- fi
- fi
- attempt=$((attempt + 1))
- done
- echo "所有重試都失敗了,將在下一個排程時間再次嘗試"
- exit 1
- - name: 上傳日誌文件
- if: always()
- uses: actions/upload-artifact@v4
- with:
- name: wikipedia-bot-logs-${{ github.run_number }}
- path: python-scripts/stat_updater/wikipedia_bot.log
- retention-days: 30
- continue-on-error: true
- - name: 記錄執行結果
- if: always()
- run: |
- if [ "${{ steps.check_updated.outputs.already_updated }}" == "true" ]; then
- echo "今日已更新,任務跳過"
- elif [ $? -eq 0 ]; then
- echo "維基百科統計更新成功"
- else
- echo "本次更新失敗,將在下一個時段重試"
- echo "下次執行時間: 4 小時後"
- fi
- echo "查看詳細日誌: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
Advertisement
Add Comment
Please, Sign In to add comment