Skip to content
Draft
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
140 changes: 96 additions & 44 deletions .github/workflows/thesis-facts-append.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,62 @@ jobs:

git clone --no-checkout "$repository_url" "$base_gate"
git -C "$base_gate" fetch --no-tags origin "$BASE_SHA"
git -C "$base_gate" checkout --detach "$BASE_SHA"
# Check the base gate out with an empty attribute tree, so the files
# it runs from, its trust anchors included, are the committed bytes.
# (The runner's own git config still applies; GitHub's ubuntu
# runners set no core.autocrlf or core.attributesFile.)
# A .gitattributes anywhere in the base, on the gate surface or off
# it, then can neither rewrite them (working-tree-encoding, ident, a
# filter, eol=crlf) nor stop the checkout (a boolean
# working-tree-encoding, a required filter whose smudge fails). A
# stopped checkout would fail this job on every later pull request,
# the one that removes the file included. Two pull requests that
# each pass alone can merge into such a base. The candidate above
# keeps its attributes: if they stop its checkout, that refuses the
# candidate.
empty_tree="$(git -C "$base_gate" hash-object -t tree /dev/null)"
git -C "$base_gate" --attr-source="$empty_tree" \
checkout --detach "$BASE_SHA"
test "$(git -C "$base_gate" rev-parse HEAD)" = "$BASE_SHA"

# Provision the BASE commit's own hash-locked environment and run
# the base gate with it: the gate scripts may import packaged
# dependencies, and installing from the base's uv.lock
# keeps the PR unable to influence what code judges it.
uv sync --locked --no-dev --project "$base_gate"
#
# Every start of the base gate, the --help question included, uses
# `python -I` and sets no PYTHONPATH, and the environment does not
# install this project. -I keeps the script's own directory off
# sys.path and ignores PYTHON* variables; without the project, no
# editable .pth puts the base checkout's root on sys.path, and the
# sync builds nothing from the checkout (no README.md, hatch.toml or
# hatch_build.py). Most of scripts/ and the root are off the gate
# surface, so an earlier data proposal can add a module there (a
# scripts/tempfile.py, a scripts/receipt/ package, a root
# sitecustomize/ package); started this way, the gate never imports
# it. `uv run --no-sync` keeps uv from installing the project again.
#
# A base gate that still imports its pins by name finds them only
# as scripts.receipt_pins, through that root, so for such a base
# alone the project is installed as before. -I still keeps scripts/
# off sys.path, but the root is on it, last, so a module there that
# the old gate looks up and finds nowhere earlier (a root
# receipt_pins.py, a scripts/__init__.py or a scripts/receipt_pins/
# package) still reaches it. The check reads the base checkout's
# copy of the gate, which the candidate cannot change. Delete the
# first branch below once no pull request into this branch can
# still have a base from before the gate loaded its pins by path. A
# gate older than the pins imports its sibling scripts by name,
# cannot start this way, and stops the step.
base_gate_script="$base_gate/scripts/check_thesis_facts_append.py"
if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \
"$base_gate_script"; then
uv sync --locked --no-dev --project "$base_gate"
base_gate_python=(uv run --locked --no-dev --project "$base_gate" python -I)
else
uv sync --locked --no-dev --no-install-project --project "$base_gate"
base_gate_python=(uv run --no-sync --project "$base_gate" python -I)
fi

# Receipt 0.6 reads and rehashes the named commit's objects; the shim
# prints the commit and tree from that verdict. --root only locates
Expand All @@ -118,33 +166,24 @@ jobs:
# cannot run at all stops the step instead of being read as an old
# one. Delete the second branch below once no base reachable from
# this branch predates --commit.
base_gate_help="$(
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" --help
)"
base_gate_help="$("${base_gate_python[@]}" "$base_gate_script" --help)"

cd "$RUNNER_TEMP"
case "$base_gate_help" in
*--commit*)
PYTHONPATH="$base_gate/scripts" \
PYTHONNOUSERSITE=1 \
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" \
--root "$candidate" \
--commit "$MERGE_SHA" \
--base-ref "$BASE_SHA"
"${base_gate_python[@]}" "$base_gate_script" \
--root "$candidate" \
--commit "$MERGE_SHA" \
--base-ref "$BASE_SHA"
;;
*)
echo "note: the base gate at $BASE_SHA predates --commit, so it" \
"judges the working tree at $candidate, without binding its" \
"verdict to $MERGE_SHA. This is the base's own guarantee and" \
"the only one available against that base." >&2
PYTHONPATH="$base_gate/scripts" \
PYTHONNOUSERSITE=1 \
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" \
--root "$candidate" \
--base-ref "$BASE_SHA"
"${base_gate_python[@]}" "$base_gate_script" \
--root "$candidate" \
--base-ref "$BASE_SHA"
;;
esac

Expand Down Expand Up @@ -174,54 +213,66 @@ jobs:
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" \
"$base_gate"
git -C "$base_gate" fetch --no-tags --depth 1 origin "$base_sha"
git -C "$base_gate" checkout --detach "$base_sha"
# As in the trusted job: an empty attribute tree, so the base
# gate runs from the committed bytes and no .gitattributes can
# stop its checkout.
empty_tree="$(git -C "$base_gate" hash-object -t tree /dev/null)"
git -C "$base_gate" --attr-source="$empty_tree" \
checkout --detach "$base_sha"
test "$(git -C "$base_gate" rev-parse HEAD)" = "$base_sha"

# Base gate runs from the BASE commit's own hash-locked env so
# gate dependencies resolve without the PR influencing them.
uv sync --locked --no-dev --project "$base_gate"
# gate dependencies resolve without the PR influencing them. As
# in the trusted job above, the env does not install this
# project and every start uses `python -I` with no PYTHONPATH,
# so no module in the base's scripts/ or at its root can stand in
# for one the gate imports, except in a base whose gate still
# imports its pins by name (see the trusted job above). Delete
# the first branch below when the trusted job's goes.
base_gate_script="$base_gate/scripts/check_thesis_facts_append.py"
if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \
"$base_gate_script"; then
uv sync --locked --no-dev --project "$base_gate"
base_gate_python=(uv run --locked --no-dev --project "$base_gate" python -I)
else
uv sync --locked --no-dev --no-install-project --project "$base_gate"
base_gate_python=(uv run --no-sync --project "$base_gate" python -I)
fi

workspace_sha="$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)"
[[ "$workspace_sha" =~ ^[0-9a-f]{40,64}$ ]]

# As in the trusted job above: the commit is named, not inferred,
# and the base gate is asked what it accepts for the same reason.
base_gate_help="$(
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" --help
)"
base_gate_help="$("${base_gate_python[@]}" "$base_gate_script" --help)"

cd "$RUNNER_TEMP"
case "$base_gate_help" in
*--commit*)
PYTHONPATH="$base_gate/scripts" \
PYTHONNOUSERSITE=1 \
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" \
--root "$GITHUB_WORKSPACE" \
--commit "$workspace_sha" \
--base-ref "$base_sha"
"${base_gate_python[@]}" "$base_gate_script" \
--root "$GITHUB_WORKSPACE" \
--commit "$workspace_sha" \
--base-ref "$base_sha"
;;
*)
echo "note: the base gate at $base_sha predates --commit, so" \
"it judges the workspace, without binding its verdict to" \
"$workspace_sha." >&2
PYTHONPATH="$base_gate/scripts" \
PYTHONNOUSERSITE=1 \
uv run --locked --no-dev --project "$base_gate" \
python "$base_gate/scripts/check_thesis_facts_append.py" \
--root "$GITHUB_WORKSPACE" \
--base-ref "$base_sha"
"${base_gate_python[@]}" "$base_gate_script" \
--root "$GITHUB_WORKSPACE" \
--base-ref "$base_sha"
;;
esac
else
# The push path names the pushed commit explicitly too. The
# argument is required, so there is no spelling of this run in
# which the commit is taken from the checkout instead.
uv sync --locked --no-dev
uv run --locked --no-dev \
python scripts/check_thesis_facts_append.py \
--commit "$GITHUB_SHA"
# which the commit is taken from the checkout instead. It runs
# the pushed commit's own gate, which loads its pins by path, so
# it starts it isolated, as the jobs above do, with no project
# install to undo.
uv sync --locked --no-dev --no-install-project
uv run --no-sync python -I scripts/check_thesis_facts_append.py \
--commit "$GITHUB_SHA"
fi

- name: Install uv
Expand All @@ -246,4 +297,5 @@ jobs:
tests/test_thesis_append_adversarial.py \
tests/test_thesis_append_shim_isolation.py \
tests/test_receipt_shim_transparency.py \
tests/test_production_tsa_pins.py \
-q
Loading