Skip to content

fix(website): don't write an empty star cache when the first fetch fails - #3409

Open
divya0795 wants to merge 1 commit into
vinta:masterfrom
divya0795:fix/empty-star-cache
Open

divya0795 wants to merge 1 commit into
vinta:masterfrom
divya0795:fix/empty-star-cache

Conversation

@divya0795

Copy link
Copy Markdown

When the first star fetch fails with no restored cache, the deploy goes out with zero stars instead of failing. The workflow's guard is meant to catch exactly this case:

      - name: Verify star data exists
        run: |
          if [ ! -f website/data/github_stars.json ]; then
            echo "::error::github_stars.json not found. No cache and fetch failed or was skipped."
            exit 1
          fi
          python -m json.tool website/data/github_stars.json > /dev/null

On any non-401 HTTP error, fetch_github_stars.py prints "Saving partial cache and exiting." and calls save_cache(cache) before sys.exit(1). With no cache restored (a first deploy, or an evicted cache), cache is still {}. The fetch step is continue-on-error, the file now exists and is valid JSON, so the guard passes. build.py then renders every entry without stars or last-commit dates and drops the stars figure from the homepage.

This change saves only a non-empty cache. A restored cache plus a failed batch is still saved as before. With nothing fetched and nothing restored, no file is written, so the verify step fails with its own error message. The 401 path already behaved this way.

Before and after, with a mocked 502 on the first batch and no prior cache, then the verify step's shell run as written:

== unchanged base
HTTP error 502
Saving partial cache and exiting.
fetch exit 1
-- verify: VERIFY PASSED (contents: {})   rc=0
== this branch
HTTP error 502
fetch exit 1
-- verify: ::error::github_stars.json not found. No cache and fetch failed or was skipped.   rc=1

Two tests drive main() with a 502. The first (no cache, so no file must be written) fails on the unchanged base. The second (a restored cache must be kept) passes on both and guards the existing partial-save behavior.

Validation, on Python 3.14.10 (macOS):

  • pytest website/tests/: 172 passed (170 on the base, plus the 2 new cases).
  • Ruff lint and format check, and ty check website, all pass.
  • Full site build passes.

This fixes the website tooling and does not add a project listing, so the project-admission template does not apply.

On a non-401 HTTP error, fetch_github_stars saved whatever it had and
exited 1. With no restored cache that is {}, which still passes the
deploy workflow's "Verify star data exists" step (file exists, valid
JSON), so the site deployed with no stars. Only save a non-empty cache,
so the verify step fails as intended; a restored cache is still saved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant