Skip to content

Update Main Scoreboard #790

Update Main Scoreboard

Update Main Scoreboard #790

name: Update Main Scoreboard
on:
workflow_run:
workflows: ["Update Scoreboards"]
types:
- completed
branches:
- main
schedule:
# Run daily at 00:00 UTC to catch any missed updates
- cron: '0 0 * * *'
workflow_dispatch:
# Allow manual triggering
permissions:
contents: write
concurrency:
group: update-main-scoreboard
cancel-in-progress: false
jobs:
update-main-scoreboard:
runs-on: ubuntu-latest
# Only run if workflow_run was successful, or if triggered by other events, AND only on main repo
if: ${{ github.repository == 'RezaSi/go-interview-practice' && (github.event.workflow_run.conclusion == 'success' || github.event_name != 'workflow_run') }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Create scripts directory if it doesn't exist
run: mkdir -p scripts
- name: Generate Main Scoreboard
run: |
echo "🏆 Generating main scoreboard from all challenge scoreboards..."
python3 scripts/generate_main_scoreboard.py
- name: Check for changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Detected changes in scoreboard data"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "No changes detected in scoreboard data"
fi
- name: Commit and push changes
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Auto-update main scoreboard
- Updated leaderboard rankings
- Refreshed completion statistics
- Synchronized with latest challenge scoreboards"
# Robust push with retry logic for concurrent workflows
MAX_RETRIES=5
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Push attempt $((RETRY_COUNT + 1))/$MAX_RETRIES"
# Pull latest changes before pushing
git fetch origin main
# Check if we need to rebase
if ! git diff --quiet HEAD origin/main; then
echo "Remote has new changes, rebasing..."
git rebase origin/main || {
echo "Rebase failed, trying merge strategy..."
git rebase --abort 2>/dev/null || true
git merge origin/main -m "Merge remote changes before main scoreboard update"
}
fi
# Try to push
if git push origin main; then
echo "✅ Successfully pushed changes"
break
else
echo "❌ Push failed, retrying in $((RETRY_COUNT + 1)) seconds..."
sleep $((RETRY_COUNT + 1))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
done
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "🚨 Failed to push after $MAX_RETRIES attempts"
exit 1
fi
- name: Create summary
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
echo "## 🏆 Main Scoreboard Updated" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The main leaderboard in README.md has been automatically updated with the latest challenge completion data." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📊 Update Details" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Processed all challenge scoreboards" >> $GITHUB_STEP_SUMMARY
echo "- 🔄 Updated completion statistics" >> $GITHUB_STEP_SUMMARY
echo "- 🏅 Refreshed achievement badges" >> $GITHUB_STEP_SUMMARY
echo "- 📈 Calculated new completion rates" >> $GITHUB_STEP_SUMMARY
- name: No changes summary
if: steps.verify-changed-files.outputs.changed == 'false'
run: |
echo "## ✅ Main Scoreboard Current" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The main leaderboard is already up-to-date with the latest challenge completion data." >> $GITHUB_STEP_SUMMARY