-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (55 loc) · 1.83 KB
/
api.yml
File metadata and controls
66 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Run API and Auto-commit
on:
schedule:
# 每2小时运行一次,使用UTC时间
- cron: '0 */2 * * *'
# 允许手动触发
workflow_dispatch:
jobs:
run-api-and-commit:
runs-on: ubuntu-latest
permissions:
contents: write # 需要写入权限来推送更改
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取所有历史记录,方便后续操作
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies (如果有requirements.txt)
run: |
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
fi
- name: Run API script
run: python3 api.py
- name: Check for changes
id: check_changes
run: |
# 检查是否有文件被修改
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "没有检测到更改"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "检测到更改"
fi
- name: Configure Git
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Add and commit changes
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git add -A
git commit -m "自动更新: $(date +'%Y-%m-%d %H:%M:%S UTC')" || echo "没有需要提交的更改"
- name: Push changes
if: steps.check_changes.outputs.has_changes == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}