Update Repository Stats #344
This file contains hidden or 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: Update Repository Stats | |
| on: | |
| schedule: | |
| # Run at 01:00 UTC (JST 10:00 AM) to ensure GitHub's traffic data is updated | |
| # GitHub updates traffic stats daily around midnight UTC | |
| - cron: '0 1 * * *' | |
| workflow_dispatch: # Manual trigger only (no automatic triggers on push) | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-stats: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: dev # Use dev branch (default branch) | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install requests matplotlib pandas | |
| - name: Fetch traffic stats | |
| id: fetch_stats | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.STATS_TOKEN }} | |
| GIST_ID: ${{ secrets.GIST_ID }} | |
| run: | | |
| python scripts/fetch_stats.py | |
| - name: Generate stats graph | |
| run: | | |
| python scripts/generate_stats_graph.py | |
| - name: Update README | |
| run: | | |
| python scripts/update_readme_stats.py | |
| - name: Commit and push to dev if changed | |
| id: commit_dev | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| git commit -m "chore: update repository stats [skip ci]" | |
| git push | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Sync stats to main branch | |
| if: steps.commit_dev.outputs.changed == 'true' | |
| run: | | |
| # Fetch main branch | |
| git fetch origin main | |
| git checkout main | |
| # Copy stats files from dev | |
| git checkout dev -- stats_data.json docs/stats_graph_daily.png docs/stats_graph_cumulative.png | |
| # Commit and push to main | |
| git add stats_data.json docs/stats_graph_daily.png docs/stats_graph_cumulative.png | |
| if git diff --staged --quiet; then | |
| echo "No changes to sync to main" | |
| else | |
| git commit -m "chore: sync repository stats from dev [skip ci]" | |
| git push origin main | |
| fi |