|
7 | 7 | - cron: "0 14 * * *" |
8 | 8 | workflow_dispatch: |
9 | 9 |
|
10 | | -permissions: |
11 | | - contents: write |
12 | | - |
13 | 10 | jobs: |
14 | 11 | check: |
15 | | - runs-on: ubuntu-latest |
16 | | - timeout-minutes: 180 |
17 | | - |
18 | | - steps: |
19 | | - - uses: actions/checkout@v4 |
20 | | - |
21 | | - - name: Set up Python |
22 | | - uses: actions/setup-python@v5 |
23 | | - with: |
24 | | - python-version: "3.12" |
25 | | - |
26 | | - - name: Cache Python packages |
27 | | - id: cache-pip |
28 | | - uses: actions/cache@v4 |
29 | | - with: |
30 | | - path: ${{ env.pythonLocation }}/lib/python*/site-packages |
31 | | - key: pip-${{ hashFiles('requirements.txt') }} |
32 | | - |
33 | | - - name: Install Python dependencies |
34 | | - if: steps.cache-pip.outputs.cache-hit != 'true' |
35 | | - run: pip install -r requirements.txt |
36 | | - |
37 | | - - name: Install ffmpeg |
38 | | - run: sudo apt-get install -y ffmpeg |
39 | | - |
40 | | - # Cache ASR models (fixed key — only re-download if model version changes) |
41 | | - - name: Cache ASR models |
42 | | - id: cache-models |
43 | | - uses: actions/cache@v4 |
44 | | - with: |
45 | | - path: | |
46 | | - sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/ |
47 | | - silero_vad.onnx |
48 | | - key: asr-models-sensevoice-2024-07-17 |
49 | | - |
50 | | - - name: Download ASR models |
51 | | - if: steps.cache-models.outputs.cache-hit != 'true' |
52 | | - run: | |
53 | | - wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17.tar.bz2 |
54 | | - tar xf sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17.tar.bz2 |
55 | | - rm sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17.tar.bz2 |
56 | | - wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx |
57 | | -
|
58 | | - # 核心新增步骤 1:尝试从 data 分支拉取最新数据库(实现平稳过渡与 Fork 兼容) |
59 | | - - name: Fetch database from data branch |
60 | | - run: | |
61 | | - mkdir -p data |
62 | | - # 尝试通过 GitHub Raw API 下载 data 分支上的数据库 |
63 | | - curl -fL -o data/icourse.db.enc.tmp "https://raw.githubusercontent.com/${{ github.repository }}/data/data/icourse.db.enc" || echo "Fetch from data branch failed, falling back." |
64 | | - if [ -f data/icourse.db.enc.tmp ]; then |
65 | | - mv data/icourse.db.enc.tmp data/icourse.db.enc |
66 | | - echo "Successfully loaded latest database from data branch." |
67 | | - else |
68 | | - echo "Using fallback database from main branch or starting fresh." |
69 | | - fi |
70 | | -
|
71 | | - # Decrypt database from repo (handles fork: different secrets = decrypt fails = start fresh) |
72 | | - - name: Decrypt database |
73 | | - if: hashFiles('data/icourse.db.enc') != '' |
74 | | - env: |
75 | | - DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }} |
76 | | - run: | |
77 | | - if openssl enc -aes-256-cbc -d -pbkdf2 \ |
78 | | - -in data/icourse.db.enc -out data/icourse.db \ |
79 | | - -pass env:DB_KEY 2>/dev/null; then |
80 | | - echo "Database decrypted successfully." |
81 | | - else |
82 | | - echo "::warning::Decryption failed (new fork or changed secrets). Starting with fresh database." |
83 | | - rm -f data/icourse.db |
84 | | - fi |
85 | | -
|
86 | | - - name: Record database state |
87 | | - id: db-before |
88 | | - run: | |
89 | | - if [ -f data/icourse.db ]; then |
90 | | - echo "hash=$(md5sum data/icourse.db | cut -d' ' -f1)" >> $GITHUB_OUTPUT |
91 | | - else |
92 | | - echo "hash=none" >> $GITHUB_OUTPUT |
93 | | - fi |
94 | | -
|
95 | | - - name: Run |
96 | | - env: |
97 | | - StuId: ${{ secrets.STUID }} |
98 | | - UISPsw: ${{ secrets.UISPSW }} |
99 | | - COURSE_IDS: ${{ secrets.COURSE_IDS }} |
100 | | - DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }} |
101 | | - SMTP_EMAIL: ${{ secrets.SMTP_EMAIL }} |
102 | | - SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }} |
103 | | - RECEIVER_EMAIL: ${{ secrets.RECEIVER_EMAIL }} |
104 | | - run: python -u main.py |
105 | | - |
106 | | - # 核心修改步骤 2:加密并强制推送到隔离的 data 分支 |
107 | | - - name: Deploy database to data branch |
108 | | - if: always() |
109 | | - env: |
110 | | - DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }} |
111 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
112 | | - run: | |
113 | | - if [ ! -f data/icourse.db ]; then |
114 | | - echo "No database file, skipping." |
115 | | - exit 0 |
116 | | - fi |
117 | | -
|
118 | | - AFTER=$(md5sum data/icourse.db | cut -d' ' -f1) |
119 | | - if [ "$AFTER" = "${{ steps.db-before.outputs.hash }}" ]; then |
120 | | - echo "Database unchanged, skipping commit." |
121 | | - exit 0 |
122 | | - fi |
123 | | -
|
124 | | - # 加密数据库 |
125 | | - openssl enc -aes-256-cbc -salt -pbkdf2 \ |
126 | | - -in data/icourse.db -out data/icourse.db.enc \ |
127 | | - -pass env:DB_KEY |
128 | | -
|
129 | | - echo "Deploying to data branch..." |
130 | | - # 创建全新的临时目录以隔离 git 历史 |
131 | | - mkdir -p /tmp/db_deploy/data |
132 | | - cp data/icourse.db.enc /tmp/db_deploy/data/ |
133 | | - cd /tmp/db_deploy |
134 | | - |
135 | | - # 初始化干净的 git 仓库并切换到 data 分支 |
136 | | - git init |
137 | | - git checkout -b data |
138 | | - |
139 | | - # 配置 Bot 身份 |
140 | | - git config user.name "github-actions[bot]" |
141 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
142 | | - |
143 | | - # 提交并强制推送 |
144 | | - git add data/icourse.db.enc |
145 | | - git commit -m "chore: update encrypted database" |
146 | | - git push --force "https://${{ github.actor }}:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" data |
| 12 | + uses: ./.github/workflows/_pipeline.yml |
| 13 | + with: |
| 14 | + course_ids: ${{ secrets.COURSE_IDS }} |
| 15 | + secrets: inherit |
0 commit comments