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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
11 changes: 11 additions & 0 deletions .github/pins/lattices.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tool pins for the project lattices/ (Lean 4.34.1), in place of the defaults.
# leanprover/comparator v4.34.0
COMPARATOR_COMMIT=d03acab154d269c06e60e4de7e4cc85deebff94b
# nanoda_lib 0.4.32
NANODA_REPO=https://github.com/ammkrn/nanoda_lib.git
NANODA_COMMIT=0da9f98feadd3a0a2ef4b3dbcf52a298a6fef929
# One job for the whole build and one for each comparator configuration: together they would come close to
# the six hours that a job may take.
SPLIT_JOBS=1
# The check takes three to four hours, so pull requests and pushes do not run it.
MANUAL_ONLY=1
15 changes: 14 additions & 1 deletion .github/scripts/comparator-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
# Configurations checked, relative to the project directory:
# comparator*.json (Palomar template layout: comparator.json next to the lakefile)
# comparator/config*.json (a comparator/ directory of trusted statement files with per-topic configs)
# or, when COMPARATOR_CONFIGS is set, the configurations it lists (separated by spaces).
#
# Tool pins default to those of the Palomar registry's verifier
# (https://github.com/PalomarRegistry/PalomarSubmission, .github/workflows/submission.yml); lean4export is
# taken at the release tag named after the project's Lean version unless LEAN4EXPORT_COMMIT is set.
# This repository's addition: when a stable patch release (vX.Y.Z, Z > 0) has no tag of its own, the vX.Y.0
# tag is taken and built with the project's toolchain; release candidates do not fall back.
# A project may have pins of its own in .github/pins/<project>.env; they replace the defaults.
set -euo pipefail

# shellcheck source=/dev/null
. "$(dirname "${BASH_SOURCE[0]}")/read-pins.sh"

COMPARATOR_COMMIT="${COMPARATOR_COMMIT:-575674928e239f5bc452aab72d1dd7b0f1326494}"
NANODA_COMMIT="${NANODA_COMMIT:-68d5ca9db226849b41a6fff59d796ff19d0a8840}"
NANODA_REPO="${NANODA_REPO:-https://github.com/robsimmons/nanoda_lib.git}"
LANDRUN_COMMIT="${LANDRUN_COMMIT:-811cfff51ceaf3d9843708aa6d22e9b84ccac8b4}"
TOOLS_DIR="${TOOLS_DIR:-$HOME/.cache/lean-ci-tools}"
LOG_DIR="${LOG_DIR:-$PWD/.lake/comparator-logs}"
Expand Down Expand Up @@ -54,6 +60,12 @@ fi
shopt -s nullglob
configs=(comparator*.json comparator/config*.json)
shopt -u nullglob
if [ -n "${COMPARATOR_CONFIGS:-}" ]; then
read -ra configs <<<"$COMPARATOR_CONFIGS"
for cfg in "${configs[@]}"; do
[ -f "$cfg" ] || die "no such comparator configuration: $cfg"
done
fi
[ "${#configs[@]}" -gt 0 ] || die "no comparator configuration found (comparator*.json or comparator/config*.json)"
echo "project $(pwd), toolchain $toolchain, configurations: ${configs[*]}"

Expand All @@ -64,6 +76,7 @@ checkout_at() { # <url> <dir> <commit>
git clone --quiet --filter=blob:none "$1" "$2"
fi
if [ "$(git -C "$2" rev-parse HEAD)" != "$3" ]; then
git -C "$2" remote set-url origin "$1"
git -C "$2" fetch --quiet --depth 1 origin "$3"
git -C "$2" checkout --quiet --detach "$3"
fi
Expand All @@ -87,7 +100,7 @@ fi
lean4export_bin="$TOOLS_DIR/lean4export/.lake/build/bin/lean4export"

echo "== nanoda_lib @ $NANODA_COMMIT"
checkout_at https://github.com/robsimmons/nanoda_lib.git "$TOOLS_DIR/nanoda" "$NANODA_COMMIT"
checkout_at "$NANODA_REPO" "$TOOLS_DIR/nanoda" "$NANODA_COMMIT"
cargo build --release --locked --quiet --manifest-path "$TOOLS_DIR/nanoda/Cargo.toml"
nanoda_bin="$TOOLS_DIR/nanoda/target/release/nanoda_bin"

Expand Down
18 changes: 18 additions & 0 deletions .github/scripts/read-pins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# shellcheck shell=bash
# Sourced from a project directory: sets the variables that .github/pins/<project>.env names. That file is
# read as data; an unknown key or a malformed value is an error.
pins="$(dirname "${BASH_SOURCE[0]}")/../pins/$(basename "$PWD").env"
if [ -f "$pins" ]; then
echo "project pins: $pins"
while IFS='=' read -r key value || [ -n "$key" ]; do
case "$key" in
'' | '#'*) continue ;;
COMPARATOR_COMMIT | NANODA_COMMIT | LANDRUN_COMMIT) pattern='^[0-9a-f]{40}$' ;;
NANODA_REPO) pattern='^https://[A-Za-z0-9._/-]+$' ;;
SPLIT_JOBS | MANUAL_ONLY) pattern='^[01]$' ;;
*) echo "error: $pins: unknown key $key" >&2; exit 1 ;;
esac
[[ "$value" =~ $pattern ]] || { echo "error: $pins: malformed value of $key" >&2; exit 1; }
printf -v "$key" %s "$value"
done < "$pins"
fi
97 changes: 85 additions & 12 deletions .github/workflows/lean-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ name: Lean projects
# push to main only the projects with changed files are verified. Changes outside the project directories
# (CI configuration under .github/, README.md, LICENSE, .gitignore, ...) do not trigger project
# verification: such a run selects no project and `verify` is skipped. To re-verify everything, start the
# workflow manually (workflow_dispatch) with projects = "all" (the default), or name the projects to run.
# workflow manually (workflow_dispatch) with projects = "all" (the default; it skips projects with MANUAL_ONLY=1),
# or name the projects to run.
# The file .github/pins/<project>.env counts as a file of its project.
# For each selected project the `verify` job
# 1. installs elan (the toolchain comes from the project's own lean-toolchain),
# 2. fetches the Mathlib cache when the project depends on Mathlib and, on pull requests only, restores
Expand All @@ -19,6 +21,9 @@ name: Lean projects
# landrun sandbox, at the tool pins of the registry's verifier
# (https://github.com/PalomarRegistry/PalomarSubmission/blob/main/.github/workflows/submission.yml),
# must accept every comparator configuration the project declares ("Your solution is okay!").
# A project whose file .github/pins/<project>.env has the line SPLIT_JOBS=1 is verified by several jobs side
# by side, each from scratch: one for step 3, and for each configuration one that builds its two modules and
# does step 4 for it.

on:
pull_request:
Expand All @@ -42,6 +47,7 @@ env:
# Tool pins, from PalomarRegistry/PalomarSubmission .github/workflows/submission.yml (commit e215b18).
# lean4export is not pinned here: like the registry, each project uses the lean4export release tag that
# matches its lean-toolchain (resolved in the `pins` step below).
# A project may replace the comparator, nanoda and landrun pins in .github/pins/<project>.env.
ELAN_VERSION: v4.2.3
ELAN_SHA256: df0b2b3a439961ffcbb3985214365ffe40f49bc871df04dff268c7d8e21ca8b2
COMPARATOR_COMMIT: 575674928e239f5bc452aab72d1dd7b0f1326494
Expand All @@ -55,6 +61,7 @@ jobs:
timeout-minutes: 5
outputs:
projects: ${{ steps.select.outputs.projects }}
jobs: ${{ steps.select.outputs.jobs }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -80,7 +87,7 @@ jobs:
done
echo "projects in repository: ${projects[*]:-(none)}"
# Selection rule: a project is verified iff one of its files is in the diff (pull request:
# Selection rule: a project is verified iff one of its files, or its pins file, is in the diff (pull request:
# base...head; push: before...after). CI configuration changes (.github/) and other files outside
# the project directories do not trigger project verification; use workflow_dispatch with
# projects = "all" to re-verify everything. When there is no usable `before` commit (first push of
Expand Down Expand Up @@ -111,7 +118,7 @@ jobs:
selected=()
if [ -n "$range" ]; then
if changed="$(git diff --name-only "$range" --)"; then
tops="$(printf '%s\n' "$changed" | cut -d/ -f1 | sort -u)"
tops="$(printf '%s\n' "$changed" | sed -E 's|^\.github/pins/([^/]+)\.env$|\1|' | cut -d/ -f1 | sort -u)"
echo "changed top-level entries in $range: $(tr '\n' ' ' <<<"$tops")"
for p in "${projects[@]}"; do
if grep -qxF "$p" <<<"$tops"; then selected+=("$p"); fi
Expand All @@ -130,6 +137,19 @@ jobs:
done
fi
# A project whose pins file has the line MANUAL_ONLY=1 is verified only by a manual run that names it.
if [ -n "$range" ] || $all || [ "$GITHUB_EVENT_NAME" != workflow_dispatch ]; then
kept=()
for p in "${selected[@]}"; do
if grep -qsxF MANUAL_ONLY=1 ".github/pins/$p.env"; then
echo "::notice::$p is verified by manual runs only (workflow_dispatch, projects = $p)"
else
kept+=("$p")
fi
done
selected=("${kept[@]}")
fi
if [ "${#selected[@]}" -eq 0 ]; then
json='[]'
else
Expand All @@ -138,8 +158,32 @@ jobs:
echo "selected projects: $json"
echo "projects=$json" >> "$GITHUB_OUTPUT"
# The jobs. A part is "all", or for a split project "build" or one comparator configuration (the
# patterns are those of comparator-check.sh).
shopt -s nullglob
entries=()
for p in "${selected[@]}"; do
parts=(all)
if grep -qsxF SPLIT_JOBS=1 ".github/pins/$p.env"; then
configs=("$p"/comparator*.json "$p"/comparator/config*.json)
if [ "${#configs[@]}" -eq 0 ]; then
echo "::error::$p has no comparator configuration"
exit 1
fi
parts=(build "${configs[@]#"$p/"}")
fi
for part in "${parts[@]}"; do
entries+=("$(jq -nc --arg project "$p" --arg part "$part" '{$project, $part,
name: (if $part == "all" then $project
else $project + "-" + ($part | rtrimstr(".json") | gsub("/"; "_")) end)}')")
done
done
jobs="$(printf '%s\n' "${entries[@]}" | jq -sc .)"
echo "jobs: $jobs"
echo "jobs=$jobs" >> "$GITHUB_OUTPUT"
verify:
name: verify (${{ matrix.project }})
name: verify (${{ matrix.name }})
needs: detect
if: needs.detect.outputs.projects != '[]' && needs.detect.outputs.projects != ''
# Set repository/org variable LEAN_CI_RUNNER to a GitHub larger-runner label (e.g. ubuntu-latest-16-cores)
Expand All @@ -150,7 +194,7 @@ jobs:
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.detect.outputs.projects) }}
include: ${{ fromJSON(needs.detect.outputs.jobs) }}
defaults:
run:
shell: bash
Expand All @@ -166,6 +210,18 @@ jobs:
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL || true
df -h /
- name: Add swap space
if: matrix.part != 'all'
working-directory: .
run: |
# The comparator run on a large project comes close to the 16 GB of the hosted runner.
swap=/swapfile-ci
if sudo fallocate -l 6G "$swap" && sudo chmod 600 "$swap" && sudo mkswap "$swap" && sudo swapon "$swap"; then
free -h
else
echo "::warning::no additional swap space"
fi
- name: Read toolchain and resolve the matching lean4export release
id: pins
run: |
Expand All @@ -189,12 +245,18 @@ jobs:
echo "toolchain=$toolchain lean4export=$tag@$commit"
echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT"
echo "lean4export_commit=$commit" >> "$GITHUB_OUTPUT"
# The pins in force for this project, for the cache keys; comparator-check.sh reads the same file.
. ../.github/scripts/read-pins.sh
echo "comparator=$COMPARATOR_COMMIT nanoda=$NANODA_COMMIT landrun=$LANDRUN_COMMIT"
echo "comparator_commit=$COMPARATOR_COMMIT" >> "$GITHUB_OUTPUT"
echo "nanoda_commit=$NANODA_COMMIT" >> "$GITHUB_OUTPUT"
echo "landrun_commit=$LANDRUN_COMMIT" >> "$GITHUB_OUTPUT"
- name: Cache elan toolchains
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.elan
key: elan-${{ env.ELAN_VERSION }}-${{ steps.pins.outputs.toolchain }}-comparator-${{ env.COMPARATOR_COMMIT }}
key: elan-${{ env.ELAN_VERSION }}-${{ steps.pins.outputs.toolchain }}-comparator-${{ steps.pins.outputs.comparator_commit }}

- name: Install elan
run: |
Expand All @@ -221,9 +283,10 @@ jobs:
# manifest and lakefile, so `lake build` re-elaborates only the modules that changed, and save the
# result under this commit. Pull requests only: pushes to main and manual (workflow_dispatch) runs
# neither restore nor save, so the result of record is always a build from scratch. Only .lake/build
# is cached; .lake/packages (Mathlib) comes from `lake exe cache get` above.
# is cached; .lake/packages (Mathlib) comes from `lake exe cache get` above. Split projects are too
# large for the cache and always build from scratch.
- name: Restore the previous Lake build (pull requests only)
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && matrix.part == 'all'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ matrix.project }}/.lake/build
Expand All @@ -232,24 +295,34 @@ jobs:
lakebuild-${{ runner.os }}-${{ matrix.project }}-${{ hashFiles(format('{0}/lean-toolchain', matrix.project), format('{0}/lake-manifest.json', matrix.project), format('{0}/lakefile.*', matrix.project)) }}-
- name: lake build (no sorry outside the comparator challenge files)
env:
PART: ${{ matrix.part }}
run: |
lake build 2>&1 | tee "$RUNNER_TEMP/lake-build.log"
targets=()
if [ "$PART" != all ] && [ "$PART" != build ]; then
targets=("$(jq -er .challenge_module "$PART")" "$(jq -er .solution_module "$PART")")
fi
lake build "${targets[@]}" 2>&1 | tee "$RUNNER_TEMP/lake-build.log"
# The trusted comparator statement files (Challenge.lean, Challenge/<Topic>.lean) carry placeholder
# proofs by design; a sorry reported for any other file fails the job.
if grep -F "declaration uses 'sorry'" "$RUNNER_TEMP/lake-build.log" \
# Older versions of Lean put the word in apostrophes, newer ones in backticks.
if grep -E 'declaration uses .sorry.' "$RUNNER_TEMP/lake-build.log" \
| grep -v -E '(^|[ /])Challenge(/[^ :]*)?\.lean:'; then
echo "::error::sorry outside the comparator challenge files"
exit 1
fi
- name: Cache comparator tools
if: matrix.part != 'build'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/lean-ci-tools
key: comparator-${{ env.COMPARATOR_COMMIT }}-lean4export-${{ steps.pins.outputs.lean4export_commit }}-${{ steps.pins.outputs.toolchain }}-nanoda-${{ env.NANODA_COMMIT }}-landrun-${{ env.LANDRUN_COMMIT }}
key: comparator-${{ steps.pins.outputs.comparator_commit }}-lean4export-${{ steps.pins.outputs.lean4export_commit }}-${{ steps.pins.outputs.toolchain }}-nanoda-${{ steps.pins.outputs.nanoda_commit }}-landrun-${{ steps.pins.outputs.landrun_commit }}

- name: Palomar bar (comparator accepts every declared configuration)
if: matrix.part != 'build'
env:
COMPARATOR_CONFIGS: ${{ matrix.part != 'all' && matrix.part || '' }}
LEAN4EXPORT_COMMIT: ${{ steps.pins.outputs.lean4export_commit }}
LOG_DIR: ${{ runner.temp }}/comparator-logs
run: bash ../.github/scripts/comparator-check.sh
Expand All @@ -258,7 +331,7 @@ jobs:
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: logs-${{ matrix.project }}
name: logs-${{ matrix.name }}
path: |
${{ runner.temp }}/lake-build.log
${{ runner.temp }}/comparator-logs/
Expand Down
Loading
Loading