From 54864ab37ad3c57a3fa848aeb48dfc609ae789d5 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Fri, 3 Apr 2026 15:55:46 +0800 Subject: [PATCH] ci: merge build/deploy jobs and cache stars by date Collapse the two-job workflow into one, set the github-pages environment on the single job, and key the star-data cache by date (YYYY-MM-DD) so it is shared across same-day runs instead of being per-run-id. Also skip tests on scheduled runs and validate JSON before serving it. Co-Authored-By: Claude --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++ .github/workflows/deploy-website.yml | 26 +++++++++++----------- 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f9ba028 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - name: Install dependencies + run: uv sync --group build + + - name: Run tests + run: make test + + - name: Build website + run: make build diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 2445da1..58e30f3 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -17,8 +17,11 @@ concurrency: cancel-in-progress: false jobs: - build: + deploy: runs-on: ubuntu-latest + environment: + name: github-pages + url: https://awesome-python.com/ steps: - uses: actions/checkout@v6 @@ -31,14 +34,19 @@ jobs: run: uv sync --group build - name: Run tests + if: github.event_name != 'schedule' run: make test + - name: Get date + id: date + run: echo "today=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT" + - name: Restore star data cache id: cache-stars uses: actions/cache/restore@v4 with: path: website/data/github_stars.json - key: github-stars-${{ github.run_id }} + key: github-stars-${{ steps.date.outputs.today }} restore-keys: github-stars- - name: Fetch GitHub stars @@ -53,7 +61,7 @@ jobs: uses: actions/cache/save@v4 with: path: website/data/github_stars.json - key: github-stars-${{ github.run_id }} + key: github-stars-${{ steps.date.outputs.today }} - name: Verify star data exists run: | @@ -61,9 +69,9 @@ jobs: echo "::error::github_stars.json not found. No cache and fetch failed or was skipped." exit 1 fi - echo "Star data found: $(wc -l < website/data/github_stars.json) lines" + python -m json.tool website/data/github_stars.json > /dev/null - - name: Build site + - name: Build website run: make build - name: Upload artifact @@ -71,13 +79,5 @@ jobs: with: path: website/output/ - deploy: - needs: build - runs-on: ubuntu-latest - environment: - name: github-pages - url: https://awesome-python.com/ - steps: - name: Deploy to GitHub Pages - id: deployment uses: actions/deploy-pages@v4