Skip to content

Commit ee867aa

Browse files
committed
增加单次运行的task
1 parent 9b7ab04 commit ee867aa

3 files changed

Lines changed: 155 additions & 135 deletions

File tree

.github/workflows/_pipeline.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Run Pipeline
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
course_ids:
7+
description: "Comma-separated course IDs"
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
run:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 180
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Cache Python packages
28+
id: cache-pip
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ env.pythonLocation }}/lib/python*/site-packages
32+
key: pip-${{ hashFiles('requirements.txt') }}
33+
34+
- name: Install Python dependencies
35+
if: steps.cache-pip.outputs.cache-hit != 'true'
36+
run: pip install -r requirements.txt
37+
38+
- name: Install ffmpeg
39+
run: sudo apt-get install -y ffmpeg
40+
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+
- name: Fetch database from data branch
59+
run: |
60+
mkdir -p data
61+
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."
62+
if [ -f data/icourse.db.enc.tmp ]; then
63+
mv data/icourse.db.enc.tmp data/icourse.db.enc
64+
echo "Successfully loaded latest database from data branch."
65+
else
66+
echo "Using fallback database from main branch or starting fresh."
67+
fi
68+
69+
- name: Decrypt database
70+
if: hashFiles('data/icourse.db.enc') != ''
71+
env:
72+
DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }}
73+
run: |
74+
if openssl enc -aes-256-cbc -d -pbkdf2 \
75+
-in data/icourse.db.enc -out data/icourse.db \
76+
-pass env:DB_KEY 2>/dev/null; then
77+
echo "Database decrypted successfully."
78+
else
79+
echo "::warning::Decryption failed (new fork or changed secrets). Starting with fresh database."
80+
rm -f data/icourse.db
81+
fi
82+
83+
- name: Record database state
84+
id: db-before
85+
run: |
86+
if [ -f data/icourse.db ]; then
87+
echo "hash=$(md5sum data/icourse.db | cut -d' ' -f1)" >> $GITHUB_OUTPUT
88+
else
89+
echo "hash=none" >> $GITHUB_OUTPUT
90+
fi
91+
92+
- name: Run
93+
env:
94+
StuId: ${{ secrets.STUID }}
95+
UISPsw: ${{ secrets.UISPSW }}
96+
COURSE_IDS: ${{ inputs.course_ids }}
97+
DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
98+
SMTP_EMAIL: ${{ secrets.SMTP_EMAIL }}
99+
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
100+
RECEIVER_EMAIL: ${{ secrets.RECEIVER_EMAIL }}
101+
run: python -u main.py
102+
103+
- name: Deploy database to data branch
104+
if: always()
105+
env:
106+
DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }}
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
run: |
109+
if [ ! -f data/icourse.db ]; then
110+
echo "No database file, skipping."
111+
exit 0
112+
fi
113+
114+
AFTER=$(md5sum data/icourse.db | cut -d' ' -f1)
115+
if [ "$AFTER" = "${{ steps.db-before.outputs.hash }}" ]; then
116+
echo "Database unchanged, skipping commit."
117+
exit 0
118+
fi
119+
120+
openssl enc -aes-256-cbc -salt -pbkdf2 \
121+
-in data/icourse.db -out data/icourse.db.enc \
122+
-pass env:DB_KEY
123+
124+
echo "Deploying to data branch..."
125+
mkdir -p /tmp/db_deploy/data
126+
cp data/icourse.db.enc /tmp/db_deploy/data/
127+
cd /tmp/db_deploy
128+
129+
git init
130+
git checkout -b data
131+
git config user.name "github-actions[bot]"
132+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
133+
git add data/icourse.db.enc
134+
git commit -m "chore: update encrypted database"
135+
git push --force "https://${{ github.actor }}:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" data

.github/workflows/check.yml

Lines changed: 4 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -7,140 +7,9 @@ on:
77
- cron: "0 14 * * *"
88
workflow_dispatch:
99

10-
permissions:
11-
contents: write
12-
1310
jobs:
1411
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

.github/workflows/single_run.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Single Run
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
course_ids:
7+
description: "Comma-separated course IDs to process (e.g. 30004,30005)"
8+
required: true
9+
type: string
10+
11+
jobs:
12+
run:
13+
uses: ./.github/workflows/_pipeline.yml
14+
with:
15+
course_ids: ${{ inputs.course_ids }}
16+
secrets: inherit

0 commit comments

Comments
 (0)