-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (76 loc) · 2.8 KB
/
daily_update.yml
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Daily Anime Data Update
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
issues: write
jobs:
update-data:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set current date
run: |
echo "CURRENT_DATE=$(date -u +'%Y%m%d')" >> $GITHUB_ENV
echo "Using UTC date: ${{ env.CURRENT_DATE }}"
- name: Clean old files
run: |
echo "Cleaning old CSV files..."
rm -f data/raw/anime_seasonal_*.csv
echo "Current contents of data/raw:"
ls -la data/raw/ || echo "Directory is empty"
- name: Run data collection
id: update_attempt
env:
MAL_CLIENT_ID: ${{ secrets.MAL_CLIENT_ID }}
run: |
echo "Starting data collection..."
python -u src/mal_api.py
echo "Running check missing..."
python -u src/check_missing.py
- name: Debug After Collection
run: |
echo "Files in data/raw after collection:"
ls -la data/raw/
expected_file="data/raw/anime_seasonal_${{ env.CURRENT_DATE }}.csv"
if [ -f "$expected_file" ]; then
echo "Found new file: $expected_file"
wc -l "$expected_file"
fi
- name: Commit Changes
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
# Stage all changes in data/raw and missing_data_report.txt
git add data/raw/*.csv data/missing_data_report.txt
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
else
echo "Changes detected, committing..."
git commit -m "data: Update anime data for $(date +'%Y-%m-%d')"
git push origin ${GITHUB_REF#refs/heads/}
fi
- name: Create Issue on Failure
if: failure()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Data Update Failed',
body: `The anime data update workflow failed on ${new Date().toISOString()}\n\nPlease check the [workflow logs](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for more details.`
})