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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ jobs:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
mapfile -t changed_files < <(git diff --name-only "$BASE_SHA".."$HEAD_SHA")
MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA")
mapfile -t changed_files < <(git diff --name-only "$MERGE_BASE".."$HEAD_SHA")
if [ "${#changed_files[@]}" -eq 0 ]; then
echo "No changed files; skipping submission diff validation."
exit 0
Expand All @@ -152,7 +153,7 @@ jobs:
exit 0
fi
done
lake exe lean-eval validate-submission --base "$BASE_SHA" --head "$HEAD_SHA"
lake exe lean-eval validate-submission --base "$MERGE_BASE" --head "$HEAD_SHA"

- name: Run Lean unit tests
run: |
Expand Down
16 changes: 14 additions & 2 deletions scripts/select_ci_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,21 @@ def parse_git_changes(output: bytes) -> tuple[Change, ...]:
return tuple(changes)


def git_changes(root: pathlib.Path, base: str, head: str) -> tuple[Change, ...]:
def git_changes(root: pathlib.Path, base: str, head: str, event: str) -> tuple[Change, ...]:
if base == ZERO_SHA:
return (Change("A", ("<initial-push>",)),)
if event == "pull_request":
# The base branch may have advanced after the contributor branched.
# Comparing its tip directly to the PR head treats base-only changes
# as reversions by the PR, triggering unrelated catalog checks.
ancestor = subprocess.run(
["git", "merge-base", base, head],
cwd=root,
check=True,
stdout=subprocess.PIPE,
text=True,
)
base = ancestor.stdout.strip()
result = subprocess.run(
["git", "diff", "--name-status", "-z", "--find-renames", f"{base}..{head}"],
cwd=root,
Expand Down Expand Up @@ -359,7 +371,7 @@ def main(argv: Sequence[str] | None = None) -> int:
parser.error("--shards must be positive")
root = args.root.resolve()
problems = load_problems(root)
changes = git_changes(root, args.base, args.head)
changes = git_changes(root, args.base, args.head, args.event)
graph = load_import_graph(args.import_graph)
selection = select(root, args.event, changes, problems, graph)
matrix = make_matrix(selection, problems, args.shards)
Expand Down
37 changes: 37 additions & 0 deletions tests/python/test_select_ci_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import importlib.util
import json
import os
import pathlib
import subprocess
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -170,6 +172,41 @@ def test_nul_git_changes_reject_truncated_records(self):
with self.assertRaisesRegex(ValueError, "unexpected git diff record"):
SELECTOR.parse_git_changes(b"R100\0LeanEval/Old.lean\0")

def test_pr_changes_exclude_updates_only_on_base_branch(self):
with tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory)
env = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"}

def git(*args: str) -> str:
return subprocess.check_output(
["git", *args], cwd=root, text=True, env=env
).strip()

git("init", "-q")
git("config", "user.name", "CI test")
git("config", "user.email", "ci@example.test")
(root / "README.md").write_text("base\n", encoding="utf-8")
git("add", "README.md")
git("commit", "-qm", "base")
git("branch", "-M", "main")
git("switch", "-qc", "feature")
(root / "LeanEval").mkdir()
(root / "LeanEval" / "New.lean").write_text("-- new\n", encoding="utf-8")
git("add", "LeanEval/New.lean")
git("commit", "-qm", "new problem")
head = git("rev-parse", "HEAD")
git("switch", "-q", "main")
(root / "generated").mkdir()
(root / "generated" / "index.json").write_text("{}\n", encoding="utf-8")
git("add", "generated/index.json")
git("commit", "-qm", "regenerate main")
base = git("rev-parse", "HEAD")

pr_changes = SELECTOR.git_changes(root, base, head, "pull_request")
self.assertEqual(pr_changes, (Change("A", ("LeanEval/New.lean",)),))
push_changes = SELECTOR.git_changes(root, base, head, "push")
self.assertIn(Change("D", ("generated/index.json",)), push_changes)

def test_loads_graph_emitted_by_lean(self):
payload = [
{
Expand Down
Loading