Skip to content

Commit 8c33a7d

Browse files
committed
feat(spider): update GitHub Action for Spider Data Collection
- Changed application name to "Spider Data Collection" - Updated cron schedule comment for clarity - Enhanced branch specification and added manual workflow dispatch - Elevated permissions for explicit access requirements - Upgraded to the latest versions of actions/checkout and actions/setup-python - Added caching for pip dependencies to improve build speed - Translated comments to Chinese for better understanding - Revised logging setup to ensure Python outputs are not buffered - Added functionality to commit and push changes if modifications are detected - Included artifact upload of logs for failure analysis > GENERATE BY https://aicommit.app
1 parent e5b21f0 commit 8c33a7d

1 file changed

Lines changed: 58 additions & 21 deletions

File tree

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,86 @@
1-
name: Python application
1+
name: Spider Data Collection
22

33
on:
44
schedule:
5-
- cron: '0 2 * * 5'
5+
- cron: '0 2 * * 5' # 每周五 UTC 2:00 运行
66
push:
7-
branches: master
7+
branches:
8+
- master
9+
workflow_dispatch: # 允许手动触发
10+
811
jobs:
912
build:
10-
1113
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write # 明确声明需要的权限
1216

1317
steps:
14-
- uses : actions/checkout@v2
15-
- name: Set up Python 3.7
16-
uses: actions/setup-python@v1
18+
- name: Checkout code
19+
uses: actions/checkout@v4 # 升级到最新版本
20+
with:
21+
fetch-depth: 0 # 获取完整历史以确保正确的提交
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5 # 升级到最新版本
1725
with:
18-
python-version: 3.7
26+
python-version: '3.10' # 使用更新的 Python 版本
27+
28+
- name: Cache pip dependencies
29+
uses: actions/cache@v4 # 添加缓存以加速构建
30+
with:
31+
path: ~/.cache/pip
32+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
33+
restore-keys: |
34+
${{ runner.os }}-pip-
35+
1936
- name: Install dependencies
2037
run: |
2138
python -m pip install --upgrade pip
2239
pip install -r requirements.txt
40+
2341
- name: Lint with flake8
2442
run: |
2543
pip install flake8
26-
# stop the build if there are Python syntax errors or undefined names
44+
# 检查 Python 语法错误或未定义的变量名
2745
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
28-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
46+
# 将所有错误作为警告处理
2947
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
3049
- name: Run Spider 🤖
3150
run: |
3251
python spider.py
33-
- name: logging
52+
env:
53+
PYTHONUNBUFFERED: 1 # 确保 Python 输出不被缓冲
54+
55+
- name: Add timestamp to log
3456
run: |
3557
echo -e "\n==================$( date +%Y-%m-%d_%H:%M:%S)====================\n" >> change_log.txt
36-
- name: Commit files
58+
59+
- name: Commit and push changes
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3762
run: |
38-
git show-ref
39-
git config --local user.email "action@github.com"
40-
git config --local user.name "GitHub Action"
63+
# 检查是否有更改需要提交
64+
if [[ -z $(git status -s) ]]; then
65+
echo "No changes to commit"
66+
exit 0
67+
fi
68+
69+
# 设置 Git 用户信息
70+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
71+
git config --local user.name "github-actions[bot]"
72+
73+
# 添加文件、提交并推送
4174
git add .
42-
git commit -m "Update assets"
75+
git commit -m "Update assets [skip ci]" -m "Automated update via GitHub Actions"
4376
echo -e "\n==================$(git status)====================\n" >> change_log.txt
77+
4478
git push
45-
# - name: Push changes
46-
# uses: ad-m/github-push-action@master
47-
# with:
48-
# github_token: ${{ secrets.GITHUB_TOKEN }}
49-
# branch: 'dev'
79+
80+
- name: Upload logs as artifacts
81+
uses: actions/upload-artifact@v4
82+
if: always() # 即使任务失败也上传日志
83+
with:
84+
name: logs
85+
path: change_log.txt
86+
retention-days: 14 # 保留两周

0 commit comments

Comments
 (0)