Skip to content

Update Problem Solving Statistics #39

Update Problem Solving Statistics

Update Problem Solving Statistics #39

Workflow file for this run

name: Update Problem Solving Statistics
on:
schedule:
# Run every day at 11:40 PM BDT (17:40 UTC), then add random delay (0-7 minutes)
- cron: '40 17 * * *'
workflow_dispatch: # Allow manual trigger
jobs:
update-stats:
runs-on: ubuntu-latest
permissions:
contents: write # Required to push changes to repository
steps:
- name: Random delay (0-7 minutes)
run: |
RANDOM_SECONDS=$((RANDOM % 420))
echo "Waiting for $RANDOM_SECONDS seconds to randomize execution time..."
sleep $RANDOM_SECONDS
- 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 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' README.md || ls -l README.md
python3 update_stats.py 2>&1 | tee stats_output.txt
echo "After update - README last modified:"
stat -c '%y' README.md || ls -l README.md
echo "Checking if README was modified:"
git diff README.md | head -20
- name: Commit and push if changed
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
echo "Checking for changes..."
git status
git add README.md 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