Skip to content

每日数据更新 · Daily Update #51

每日数据更新 · Daily Update

每日数据更新 · Daily Update #51

Workflow file for this run

name: 每日数据更新 · Daily Update
on:
schedule:
# 北京时间 20:07 + 20:27 (= UTC 12:07 + 12:27),周一到周五 (1-5)。
# 为何两个窗口:GitHub cron 在繁忙时段经常跳过单次触发(实测从未自动跑过),
# 错峰非整点 + 加一个 20 min 后的兜底窗口让"任一被触发"即可工作。
# concurrency group 防重复跑、git diff 防重复 commit,所以两次都触发也无害。
- cron: '7 12 * * 1-5'
- cron: '27 12 * * 1-5'
workflow_dispatch: # 允许手动触发
permissions:
contents: write # 让 Action 能 commit + push 回 main
concurrency:
group: daily-update
cancel-in-progress: false
jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# 增量模式:仓库内已 commit panel/preds/csi300/basic 作为"状态",
# 每天只 fetch 新增日子 (~3-5 个 ticker × 1-2 个新交易日,几秒内完成)。
# BaoStock 走自家 TCP (data.baostock.com:31322),不被 GitHub runner 防火墙拦。
# 如需全量回填,本地跑 python build/init.py 并 commit 产物。
- name: 1️⃣ Fetch A-share data (BaoStock incremental)
# fetch_data.py 内部已设 socket 超时 (BAOSTOCK_SOCKET_TIMEOUT=30) + 单只重试,
# 单次 query 不会再无限挂死;这里给 8min 余量覆盖偶发重试。
run: python build/fetch_data.py --incremental
env:
BAOSTOCK_SOCKET_TIMEOUT: '30'
timeout-minutes: 8
- name: 2️⃣ Run model inference (m2alpha.pt)
run: python build/inference.py
timeout-minutes: 5
- name: 3️⃣ Rebuild data.json (行业分散 top-10 + 滞后带)
run: python build/update_daily.py
- name: 4️⃣ Commit + push if changed
env:
GH_USER: ${{ github.actor }}
run: |
git config user.name "M²-Alpha Bot"
git config user.email "actions@users.noreply.github.com"
git add build/cache/panel.parquet build/cache/preds.parquet \
build/cache/csi300.parquet build/cache/basic.csv \
docs/data/data.json
if git diff --cached --quiet; then
echo "no changes."
exit 0
fi
STAMP=$(date -u +%Y-%m-%d)
git commit -m "data: 每日更新 ${STAMP}"
git push