Skip to content

daily-holdings

daily-holdings #604

Workflow file for this run

name: daily-holdings
on:
schedule:
# GitHub 用 UTC。香港时间 = UTC+8,11:00→03:00 UTC,23:00→15:00 UTC。
# 工作日 11:00–23:50(港时)每 10 分钟一次;配合幂等去重,每个交易日最多发一封。
- cron: "*/10 3-15 * * 1-5"
workflow_dispatch: {} # 允许在网页上手动点一下触发(方便测试)
# contents: 把每日快照提交回仓库(供"日间对比");issues: 失败兜底建 Issue
permissions:
contents: write
issues: write
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- run: pip install -r requirements.txt
- name: Run
env:
SMTP_HOST: ${{ secrets.SMTP_HOST }}
SMTP_PORT: ${{ secrets.SMTP_PORT }}
SMTP_USER: ${{ secrets.SMTP_USER }}
SMTP_PASS: ${{ secrets.SMTP_PASS }}
MAIL_FROM: ${{ secrets.MAIL_FROM }}
MAIL_TO: ${{ secrets.MAIL_TO }}
# 非敏感参数,直接写在这里(改基金只需改这两行)
FUND_NAME: "3416.HK"
FUND_URL: "https://www.globalxetfs.com.hk/funds/hscei-covered-call-etf/"
run: python daily_holdings.py
- name: Persist snapshots
if: always()
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add data/holdings_*.csv data/holdings_*.meta.json data/state.json 2>/dev/null || true
git commit -m "data: holdings snapshot [skip ci]" 2>/dev/null || echo "nothing to commit"
git push 2>/dev/null || echo "nothing to push"
# 兜底:任务失败时建 Issue(每天最多一个,避免高频触发刷屏)。
# 覆盖"连告警邮件都发不出去 / Runner 自身挂了"等脚本兜不住的情况。
- name: Notify on failure
if: failure()
env:
GH_TOKEN: ${{ github.token }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
DATE=$(date -u +%F)
TITLE="持仓日报运行失败 $DATE"
NUM=$(gh issue list --state open --search "$TITLE in:title" --json number --jq '.[0].number // empty')
if [ -n "$NUM" ]; then
echo "今日已有失败告警 Issue #$NUM,跳过以防刷屏"
else
gh issue create --title "⚠️ $TITLE" \
--body "$(printf '工作流运行失败,请检查。\n\nRun: %s\n时间(UTC): %s' "$RUN_URL" "$(date -u +%FT%TZ)")"
fi