From 2e2ac366c3d886a2430365e4f3b6474f5bbf77fd Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 12 Nov 2026 11:27:57 +0200 Subject: [PATCH] Copy search under --since takes CE sources of every type a full run takes; a restored cache marker no longer re-saves the cache --- .github/workflows/check-license-headers.yml | 2 + .../src/main/python/license-headers/README.md | 4 +- .../license-headers/check_license_headers.py | 10 +++-- .../test_check_license_headers.py | 44 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-license-headers.yml b/.github/workflows/check-license-headers.yml index 66d7b295f2..54da6cea99 100644 --- a/.github/workflows/check-license-headers.yml +++ b/.github/workflows/check-license-headers.yml @@ -63,6 +63,8 @@ jobs: SINCE: ${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || '' }} run: | mkdir -p target/license-provenance + # A restored cache carries the marker of the run that saved it; only this run's additions may set it. + rm -f target/license-headers-cache/.updated # The runner does nothing else: use every CPU, not all but one as on a workstation. LICENSE_HEADERS_JOBS="$(nproc)" export LICENSE_HEADERS_JOBS diff --git a/tools/src/main/python/license-headers/README.md b/tools/src/main/python/license-headers/README.md index 0c6fb3300f..9f854b548a 100644 --- a/tools/src/main/python/license-headers/README.md +++ b/tools/src/main/python/license-headers/README.md @@ -67,7 +67,9 @@ are still reported for the whole repository. The check falls back to every file when a change can move the verdict of an unchanged file: new CE commits merged into the branch, a changed Mycila -configuration in the root `pom.xml`, or a change to the check itself. +configuration in the root `pom.xml`, or a change to the check itself. Other +changes to the Mycila scope, such as a module added to ``, do not +trigger it: the files they bring into scope are checked by the next push. ## Fix automatically diff --git a/tools/src/main/python/license-headers/check_license_headers.py b/tools/src/main/python/license-headers/check_license_headers.py index ec024f470d..8839a59f8d 100644 --- a/tools/src/main/python/license-headers/check_license_headers.py +++ b/tools/src/main/python/license-headers/check_license_headers.py @@ -1024,15 +1024,19 @@ def could_shrink_to_copy(raw_size, destinations): return 2 * raw_size >= min(destinations) -def compare(repo, plugin, lineage, contents, cache): +def compare(repo, plugin, lineage, contents, cache, in_scope): names = list(contents) new_paths = {name for name in names if not lineage.versions(name)} + # Copy sources follow every path in scope that CE lacks, not only the checked ones: with --since they would + # otherwise depend on the files a pull request changes and miss copies that a full run finds. Without new paths + # nothing is searched for copies, so no CE file needs to be read for it. + copy_source_types = {name for name in in_scope if not lineage.versions(name)} if new_paths else set() sources = {} for base, files in lineage.trees.items(): for name in names: if name in files: sources.setdefault((name, files[name]), base) - for key in comparable_ce_files(files, new_paths).items(): + for key in comparable_ce_files(files, copy_source_types).items(): sources.setdefault(key, base) versions = {(name, oid) for name in names for _, oid in lineage.versions(name)} # Every input keeps the slot it has among all inputs, so the copy search sees the same paths, and Git breaks @@ -1468,7 +1472,7 @@ def check(args): cache = (NoCache() if args.no_cache else NormalizationCache((repo / args.cache).resolve(), cache_signature(repo, plugin))) try: - comparison = compare(repo, plugin, lineage, contents, cache) + comparison = compare(repo, plugin, lineage, contents, cache, scope.eligible) finally: cache.close() rows = [comparison.classify(name, curations.get(name)) for name in checked] diff --git a/tools/src/main/python/license-headers/test_check_license_headers.py b/tools/src/main/python/license-headers/test_check_license_headers.py index 7eb94b401c..72e21499be 100644 --- a/tools/src/main/python/license-headers/test_check_license_headers.py +++ b/tools/src/main/python/license-headers/test_check_license_headers.py @@ -985,6 +985,50 @@ class CheckCommandTests(unittest.TestCase): self.assertEqual(["New.java"], self.checked(report)) self.assertEqual([], report["curationIssues"]) + def test_since_finds_a_copy_of_a_ce_file_with_another_extension_as_a_full_run_does(self): + # CE sources of the copy search follow the extensions of every path CE lacks: New.java brings .java in. + self.pull_request() + self.git.write("Copy.kt", fixture(p.NON_CE) + self.body) + self.git.commit("copy a CE file into another language") + scope = self.scope + ["Copy.kt"] + _, full, _ = self.check(scope=scope) + code, since, _ = self.check("--since", "master", scope=scope) + self.assertEqual(1, code) + self.assertEqual(["Copy.kt"], self.checked(since)) + row = self.rows(since)["Copy.kt"] + self.assertEqual(self.rows(full)["Copy.kt"], row) + self.assertEqual(("unresolved", ["Source.java"]), + (row["status"], [copy["path"] for copy in row["copyCandidates"]])) + + def test_since_checks_every_file_when_the_merge_base_has_no_ce_bases(self): + self.pull_request() + _, report, output = self.check("--since", "lts-4.3") + self.assertEqual(sorted(self.scope), self.checked(report)) + self.assertEqual("the CE commits merged at the merge base cannot be resolved", report["selection"]["reason"]) + + def test_since_checks_every_curated_file_when_the_target_curations_cannot_be_read(self): + self.git.write(p.CURATIONS, "not JSON") + self.git.commit("damage curations.json") + self.pull_request() + curation = dict(path="Source.java", header="apache", reason="Reviewed", + contentHash=p.raw_hash((self.repo / "Source.java").read_bytes())) + self.git.write(p.CURATIONS, json.dumps(dict(schemaVersion=1, curations=[curation]))) + self.git.commit("repair curations.json") + code, report, _ = self.check("--since", "master") + self.assertEqual(0, code) + self.assertEqual(["Source.java"], self.checked(report)) + self.assertEqual(["Source.java"], report["redundantCurations"]) + + def test_since_does_not_check_every_file_when_only_the_readme_or_curations_of_the_check_change(self): + self.pull_request() + self.git.write(p.README, "notes\n") + self.git.write(p.CURATIONS, '{"schemaVersion": 1, "curations": [] }') + self.git.commit("document the check") + code, report, _ = self.check("--since", "master") + self.assertEqual((0, []), (code, report["files"])) + self.assertEqual({"since": "master", "mergeBase": self.git("rev-parse", "master"), "full": False, + "reason": "2 changed paths"}, report["selection"]) + def test_since_needs_shared_history(self): self.git("checkout", "-q", "--orphan", "unrelated") self.git.write("Other.java", "other\n")