Add complete CI validation pipeline, test entry, GitHub Pages site, a… #1
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: Validate entries | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'entries/**' | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - 'entries/**' | |
| permissions: | |
| contents: write | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pip install -r ci/requirements.txt | |
| - name: Identify modified entries | |
| id: entries | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| # For PRs, diff against the base branch | |
| git fetch origin ${{ github.base_ref }} --depth=1 | |
| CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- entries/ \ | |
| | cut -d/ -f2 | sort -u | grep -v '^$' || true) | |
| else | |
| CHANGED=$(git diff --name-only HEAD~1 HEAD -- entries/ \ | |
| | cut -d/ -f2 | sort -u | grep -v '^$' || true) | |
| fi | |
| echo "entries=$CHANGED" >> "$GITHUB_OUTPUT" | |
| echo "Modified entries: $CHANGED" | |
| - name: Remove scores for deleted entries | |
| if: github.event_name == 'push' && steps.entries.outputs.entries != '' | |
| run: | | |
| for TEAM in ${{ steps.entries.outputs.entries }}; do | |
| if [ ! -d "entries/$TEAM" ]; then | |
| echo "=== Entry $TEAM was deleted, removing score ===" | |
| rm -f "scores/$TEAM.json" | |
| rm -f "docs/scores/$TEAM.json" | |
| fi | |
| done | |
| - name: Validate entries | |
| if: steps.entries.outputs.entries != '' | |
| run: | | |
| COMMIT=$(git rev-parse --short HEAD) | |
| EXIT=0 | |
| for TEAM in ${{ steps.entries.outputs.entries }}; do | |
| if [ ! -d "entries/$TEAM" ]; then | |
| echo "=== Skipping deleted entry $TEAM ===" | |
| continue | |
| fi | |
| echo "=== Validating $TEAM ===" | |
| python ci/validate.py \ | |
| --entry "entries/$TEAM" \ | |
| --commit "$COMMIT" \ | |
| --scores-dir scores \ | |
| --leaderboard leaderboard.json || EXIT=1 | |
| done | |
| # Rebuild leaderboard to reflect any deletions | |
| python -c " | |
| from pathlib import Path; import sys; sys.path.insert(0, 'ci') | |
| from validate import update_leaderboard | |
| update_leaderboard(Path('scores'), Path('leaderboard.json')) | |
| " | |
| exit $EXIT | |
| - name: Update GitHub Pages data | |
| if: always() && github.event_name == 'push' && steps.entries.outputs.entries != '' | |
| run: | | |
| mkdir -p docs/scores | |
| cp leaderboard.json docs/ 2>/dev/null || true | |
| cp scores/*.json docs/scores/ 2>/dev/null || true | |
| - name: Commit results | |
| if: always() && github.event_name == 'push' && steps.entries.outputs.entries != '' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add scores/ leaderboard.json docs/ | |
| git diff --cached --quiet || \ | |
| git commit -m "Update scores and leaderboard [skip ci]" | |
| git push |