Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 6 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ concurrency:
# GITHUB_TOKEN reads the repository and nothing else in every job without
# its own block. The repository's default is write, which the pytest job
# would otherwise hold (persisted by checkout) while it runs PyPI packages
# on pushes to main. Uploading the built database and publish-db's download
# of it from this run use the Actions runtime token, not GITHUB_TOKEN, so
# neither needs the actions scope (tests/test_ci_gates.py pins all of this).
# on pushes to main. Uploading the built database uses the Actions runtime
# token, not GITHUB_TOKEN, so it needs no actions scope. publish-db.yml
# publishes it after this workflow completes on a push to main: it holds the
# Supabase secrets, and no workflow that runs on pull requests names any
# secret (tests/test_ci_gates.py pins all of this).
permissions:
contents: read

Expand Down Expand Up @@ -65,6 +67,7 @@ jobs:
PYTHONPATH: .
run: bash .github/scripts/uk_replay_regenerate.sh
- run: test -z "$(git status --porcelain)"
# publish-db.yml downloads it from this run by this name.
- name: Upload built database
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -398,52 +401,3 @@ jobs:
- run: bun run lint
- run: bun test src
- run: bun run build

publish-db:
name: publish db to supabase storage
needs: python
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: scorecard-db-${{ github.sha }}
# Storage bucket `scorecard-artifacts` on the PE Supabase project:
# every main commit's built DB (gzipped ~6 MB from ~58 MB — the
# project is on the free plan, 50 MB per-object cap) at <sha>.db.gz
# plus a moving latest.db.gz, so consumers fetch + gunzip instead
# of rebuilding. Skips with a notice until the
# SUPABASE_SCORECARD_URL/KEY secrets are set.
#
# A failed upload is a warning, not a failed run: nothing in this
# repository reads the published copy, and the built database is
# already attached to the run as an artifact. Every main run from
# 6 October 2026 failed here with curl exit 6 (the storage host no
# longer resolves; the last upload that worked was 28 September),
# which hid whether main was otherwise green. curl stays silent so
# the host name in the secret URL is never printed.
- run: |
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_KEY" ]; then
echo "::notice::Supabase secrets not set — skipping publish"
exit 0
fi
gzip -9 -c scorecard.db > scorecard.db.gz
for name in "${GITHUB_SHA}.db.gz" "latest.db.gz"; do
status=0
curl -sf -X POST \
"$SUPABASE_URL/storage/v1/object/scorecard-artifacts/$name" \
-H "Authorization: Bearer $SUPABASE_KEY" \
-H "Content-Type: application/gzip" \
-H "x-upsert: true" \
--data-binary @scorecard.db.gz > /dev/null || status=$?
if [ "$status" -ne 0 ]; then
message="curl exit $status uploading scorecard-artifacts/$name: the published database was not updated. This run's built database is its scorecard-db artifact."
echo "::warning title=Supabase publish failed::$message"
echo "**Supabase publish failed.** $message" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "uploaded scorecard-artifacts/$name"
done
env:
SUPABASE_URL: ${{ secrets.SUPABASE_SCORECARD_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_SCORECARD_KEY }}
167 changes: 167 additions & 0 deletions .github/workflows/publish-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: publish db

# Publishes the database CI built for each push to main to the
# `scorecard-artifacts` bucket on the PE Supabase project, as <sha>.db.gz
# (gzipped ~14 MB from ~196 MB: the project is on the free plan, 50 MB
# per-object cap) and a moving latest.db.gz, so consumers fetch and gunzip
# instead of rebuilding.
#
# WHY IT IS NOT IN ci.yml
#
# This is the only workflow that names SUPABASE_SCORECARD_URL and
# SUPABASE_SCORECARD_KEY. ci.yml runs on pull requests and installs and runs
# PyPI packages and each certified variant's pins, as a runner user with
# passwordless sudo. A debug re-run of #215's pull-request CI showed a job's
# runner receiving a secret the job named only in a skipped step, and GitHub
# scrubs only the secrets "not referenced in the workflow". So while
# publish-db was a push-only job of ci.yml, the pull-request runners there may
# have held the key. No workflow that runs on pull requests names a secret
# now (tests/test_ci_gates.py).
#
# WHY workflow_run, NOT A REBUILD
#
# It publishes the bytes CI built and tested, once CI's pytest job has
# passed, as `needs: python` did inside ci.yml. A push workflow that rebuilt
# the database would run the project's PyPI packages in the job that holds
# the key, or in a sibling job of the workflow that names it, and would
# publish a database whose suite had not run. This job runs no package code:
# no checkout, no uv, no Python, only actions/download-artifact and the
# runner image's gh, gzip and curl.
#
# workflow_run runs main's copy of this file with the repository's secrets,
# whatever started the CI run, a fork's pull request included, and the
# `branches` filter names a branch, not an event or a repository. So the
# job runs only for ci.yml on a push to main of this repository, and no
# script interpolates the triggering run's fields: the run id and commit go
# to the scripts as environment variables (tests/test_publish_db.py).
#
# It reads the pytest job's conclusion in the CI attempt that fired it, so a
# run whose pytest job failed or was cancelled publishes nothing, with a
# notice, even if an earlier attempt left an artifact. The upload is that job's
# last step, so whichever artifact of that name the download takes passed the
# job's checks on this commit. Any other CI conclusion still publishes
# <sha>.db.gz, as it did: a newer push cancels the older run, often after its
# pytest job has passed.
#
# latest.db.gz moves only to the commit at main's tip, read from the API as
# the job starts, so neither a cancelled run nor a re-run of an older CI or
# publish run rolls it back. A re-run keeps its original GITHUB_SHA, so
# GITHUB_SHA cannot answer this. It lags main while the tip's pytest job has
# not passed.
#
# One publish runs at a time and the rest wait, so a publish for an older tip
# cannot overwrite latest.db.gz behind a newer one, and each reads the tip once
# its turn comes. Time limits keep a stall from holding the queue: each upload
# has two minutes, which ends in the warning below, and the two steps before
# them five each, which fails the run. The job has no limit of its own, which
# could end it inside an upload, before that warning.
#
# Skips with a notice when the secrets are unset. A failed upload is a
# warning, not a failed run: nothing in this repository reads the published
# copy, and CI's run keeps the built database as an artifact for 30 days.
# Every publish from 6 October 2026 failed with curl exit 6 (the storage host
# no longer resolves; the last upload that worked was 28 September). curl
# stays silent so the host name in the secret URL is never printed.

on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]

permissions:
contents: read

jobs:
publish-db:
name: publish db to supabase storage
if: >-
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
github.event.workflow_run.path == '.github/workflows/ci.yml'
runs-on: ubuntu-latest
# `queue: max` keeps up to 100 waiting publishes: by default GitHub cancels
# a group's pending job when another enters, so an older run's completion
# could drop the publish for main's tip. Checked on a throwaway branch on
# 30 October 2026: runs 41138146103, 41138172124 and 41138195694, pushed 14
# seconds apart, ran one after another and none was cancelled. On the job,
# not the workflow: a workflow-level group would hold every run of this
# file, the ones the guard skips included.
concurrency:
group: publish-db
queue: max
# Reading CI's jobs and artifacts takes actions: read, and main's tip
# contents: read. There is no checkout.
permissions:
actions: read
contents: read
env:
CI_RUN_ID: ${{ github.event.workflow_run.id }}
CI_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
CI_SHA: ${{ github.event.workflow_run.head_sha }}
steps:
- name: Find the database CI built
id: find
timeout-minutes: 5
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
artifact="scorecard-db-$CI_SHA"
pytest=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$CI_RUN_ID/attempts/$CI_ATTEMPT/jobs?per_page=100" \
--jq '.jobs[] | select(.name == "pytest · ruff format") | .conclusion')
count=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$CI_RUN_ID/artifacts?name=$artifact" \
--jq '[.artifacts[] | select(.expired | not)] | length')
main_tip=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq .object.sha)
if [ "$pytest" = "success" ] && [ "$count" -gt 0 ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::CI run $CI_RUN_ID attempt $CI_ATTEMPT has nothing to publish: its pytest job ended ${pytest:-unknown}, with $count $artifact"
echo "found=false" >> "$GITHUB_OUTPUT"
fi
echo "main_tip=$main_tip" >> "$GITHUB_OUTPUT"
# Pinned to a commit, as uk-replay-results.yml's propose job pins its
# actions, because it runs beside the key.
- name: Download it
if: steps.find.outputs.found == 'true'
timeout-minutes: 5
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: scorecard-db-${{ github.event.workflow_run.head_sha }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Publish it
if: steps.find.outputs.found == 'true'
env:
MAIN_TIP: ${{ steps.find.outputs.main_tip }}
SUPABASE_URL: ${{ secrets.SUPABASE_SCORECARD_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_SCORECARD_KEY }}
run: |
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_KEY" ]; then
echo "::notice::Supabase secrets not set — skipping publish"
exit 0
fi
gzip -9 -c scorecard.db > scorecard.db.gz
set -- "${CI_SHA}.db.gz"
if [ "$CI_SHA" = "$MAIN_TIP" ]; then
set -- "$@" latest.db.gz
else
echo "::notice::main is at $MAIN_TIP now, not $CI_SHA: latest.db.gz is left to the run for main's tip"
fi
for name in "$@"; do
status=0
curl -sf --max-time 120 -X POST \
"$SUPABASE_URL/storage/v1/object/scorecard-artifacts/$name" \
-H "Authorization: Bearer $SUPABASE_KEY" \
-H "Content-Type: application/gzip" \
-H "x-upsert: true" \
--data-binary @scorecard.db.gz > /dev/null || status=$?
if [ "$status" -ne 0 ]; then
message="curl exit $status uploading scorecard-artifacts/$name: the published database was not updated. The database CI built is the scorecard-db-$CI_SHA artifact of $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$CI_RUN_ID."
echo "::warning title=Supabase publish failed::$message"
echo "**Supabase publish failed.** $message" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "uploaded scorecard-artifacts/$name"
done
10 changes: 7 additions & 3 deletions scorecard_db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ old file first; nothing is lost, it is derived). Plain `pytest` also
works from a fresh clone: a pytest configuration hook builds the database
before collection when it is absent. Individual ingest modules (`ingest_urban`, `ingest_platform`,
…) remain runnable one at a time against an existing database, in the
dependency order documented in `build_db.py`. Built artifacts for every
main commit are published to the `scorecard-artifacts` Supabase storage
bucket as `<sha>.db.gz` and `latest.db.gz`.
dependency order documented in `build_db.py`. Each main commit's CI run
keeps the database it built and tested as its `scorecard-db-<sha>` artifact
for 30 days, and `.github/workflows/publish-db.yml` then publishes it to the
`scorecard-artifacts` Supabase storage bucket as `<sha>.db.gz` and
`latest.db.gz`. Every publish since 6 October 2026 has failed (the storage
host no longer resolves), which the workflow reports as a warning; the last
upload that worked was on 28 September.

```python
from scorecard_db import ScorecardDB
Expand Down
Loading
Loading