Update Problem Solving Statistics #48
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 Problem Solving Statistics | |
| on: | |
| schedule: | |
| # Run every day at 11:00 PM BDT (17:00 UTC) | |
| - cron: '0 17 * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| update-stats: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required to push changes to repository | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python3 -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Check and adjust schedule based on activity | |
| run: | | |
| python3 scripts/check_and_adjust_schedule.py | |
| - name: Fetch latest statistics and update README | |
| id: fetch_stats | |
| run: | | |
| echo "Before update - README last modified:" | |
| stat -c '%y' docs/README.md || ls -l docs/README.md | |
| python3 scripts/auto_update.py 2>&1 | tee stats_output.txt | |
| echo "After update - README last modified:" | |
| stat -c '%y' docs/README.md || ls -l docs/README.md | |
| echo "Checking if README was modified:" | |
| git diff docs/README.md | head -20 | |
| - name: Extract user info from config | |
| id: user_info | |
| run: | | |
| if [ -f "src/config.json" ]; then | |
| USER_NAME=$(python3 -c "import json, sys; data=json.load(open('src/config.json')); print(data.get('USER_INFO', {}).get('name', '${{ github.actor }}'))" 2>/dev/null || echo "${{ github.actor }}") | |
| USER_EMAIL=$(python3 -c "import json, sys; data=json.load(open('src/config.json')); print(data.get('USER_INFO', {}).get('email', '${{ github.actor }}@users.noreply.github.com'))" 2>/dev/null || echo "${{ github.actor }}@users.noreply.github.com") | |
| else | |
| USER_NAME="${{ github.actor }}" | |
| USER_EMAIL="${{ github.actor }}@users.noreply.github.com" | |
| fi | |
| echo "user_name=$USER_NAME" >> $GITHUB_OUTPUT | |
| echo "user_email=$USER_EMAIL" >> $GITHUB_OUTPUT | |
| - name: Commit and push if changed | |
| run: | | |
| git config --global user.name '${{ steps.user_info.outputs.user_name }}' | |
| git config --global user.email '${{ steps.user_info.outputs.user_email }}' | |
| echo "Checking for changes..." | |
| git status | |
| git add docs/README.md data/last_known_counts.json .github/workflows/update-stats.yml | |
| echo "Files staged. Checking diff..." | |
| git diff --staged --stat | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| echo "Changes detected, committing..." | |
| git commit -m "Auto-update: Problem solving statistics ($(date +'%Y-%m-%d'))" | |
| git push | |
| fi |