Daily Anime Data Update #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.` | |
}) |