ci(deps): pin hook revisions by SHA and install dev tools from a hashed lock
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:
1 parent
7fa6c6754d
commit
4058978353
20 files changed
+1546
-46
No files matched your search
@@ -7,9 +7,13 @@
|
||||
When <head-ref> starts with `renovate/`, the diff of <base-ref>...HEAD may only touch:
|
||||
|
||||
* requirements-dev.txt: pinned `name==version` lines, the same packages before and after;
|
||||
* requirements-dev.lock (pip-compile --generate-hashes output): `name==version` entries,
|
||||
`--hash=sha256:<64 hex>` lines and plain `# via` or prose comments, nothing else; packages may
|
||||
be added or removed (a transitive dependency), but the `# pip-compile ...` command in the
|
||||
header, which Renovate runs again, must stay as it is;
|
||||
* requirements.yml and extensions/molecule/requirements.yml: `version:` lines (the collection
|
||||
names, and every other line, stay);
|
||||
* .pre-commit-config.yaml: `rev:` lines;
|
||||
* .pre-commit-config.yaml: `rev:` lines (a tag, or a commit SHA with its `# frozen: <tag>` comment);
|
||||
* images/<name>/Dockerfile: the tag and digest of FROM lines (the image name stays), and
|
||||
the `uv==<version>` token of a line that holds one;
|
||||
* .gitea/workflows/image.yml: the matrix `version:` lines, and the tag and digest of the
|
||||
@@ -49,7 +53,9 @@ PREFIX = "renovate/"
|
||||
TAG = r"[A-Za-z0-9._-]+"
|
||||
PIN = re.compile(rf"(git\.rkdr\.net/mortis/[a-z0-9._-]+):{TAG}@sha256:[0-9a-f]{{64}}")
|
||||
REQ_LINE = re.compile(r"^([A-Za-z0-9][A-Za-z0-9._-]*)==[0-9][0-9A-Za-z.+!_-]*$")
|
||||
REV_LINE = re.compile(r"^\s*rev:\s*\S+\s*$")
|
||||
# A hook `rev:` is a tag or a commit SHA; a SHA carries its release in a `# frozen: <tag>` comment.
|
||||
# Nothing else may trail it, so the comment cannot hide a second instruction.
|
||||
REV_LINE = re.compile(r"^\s*rev:\s*\S+(?:\s+#\s*frozen:\s*\S+)?\s*$")
|
||||
VERSION_LINE = re.compile(
|
||||
r"""^\s*(?:-\s*)?version:\s*["']?(?P<v>[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?)["']?\s*(?:#.*)?$"""
|
||||
)
|
||||
@@ -100,6 +106,38 @@ def reduce_version(line):
|
||||
return "version" if VERSION_LINE.match(line) else None
|
||||
|
||||
|
||||
# requirements-dev.lock: an entry (with an optional environment marker), a hash, or a comment.
|
||||
# The marker and the prose comment use a small character set: no backslash, quote of a shell, `$` or `--`.
|
||||
LOCK_ENTRY = re.compile(
|
||||
r"^[A-Za-z0-9][A-Za-z0-9._-]*==[0-9][0-9A-Za-z.+!_-]*"
|
||||
r"(?:\s*;\s*[A-Za-z0-9_.\"' =<>!()~,-]+?)?\s*\\?$"
|
||||
)
|
||||
LOCK_HASH = re.compile(r"^\s+--hash=sha256:[0-9a-f]{64}(?:\s*\\)?$")
|
||||
LOCK_COMMAND = re.compile(r"^#\s+pip-compile\s.*$")
|
||||
LOCK_COMMENT = re.compile(
|
||||
r"^\s*(?:#(?:\s[A-Za-z0-9 ._,:()/'-]*)?)?$"
|
||||
) # a blank line is allowed too
|
||||
|
||||
|
||||
def lock_problem(removed, added):
|
||||
"""None when every changed line of requirements-dev.lock is an entry, a hash or a plain comment and
|
||||
the `# pip-compile ...` command line is the same on both sides."""
|
||||
for line in removed + added:
|
||||
if LOCK_COMMAND.match(line):
|
||||
continue
|
||||
if not (
|
||||
LOCK_ENTRY.match(line) or LOCK_HASH.match(line) or LOCK_COMMENT.match(line)
|
||||
):
|
||||
return (
|
||||
"changes a line that is not an entry, a sha256 hash or a plain comment"
|
||||
)
|
||||
old = sorted(line for line in removed if LOCK_COMMAND.match(line))
|
||||
new = sorted(line for line in added if LOCK_COMMAND.match(line))
|
||||
if old != new:
|
||||
return "changes the pip-compile command of the header"
|
||||
return None
|
||||
|
||||
|
||||
def reduce_rev(line):
|
||||
return "rev" if REV_LINE.match(line) else None
|
||||
|
||||
@@ -134,6 +172,8 @@ def file_problem(path, removed, added):
|
||||
reduce_requirement,
|
||||
"a pinned `name==version` line of the same package",
|
||||
)
|
||||
if path == "requirements-dev.lock":
|
||||
return lock_problem(removed, added)
|
||||
if path in COLLECTION_PINS:
|
||||
return same_shape(removed, added, reduce_version, "a `version:` line")
|
||||
if path == ".pre-commit-config.yaml":
|
||||
|
||||
Reference in new issue
Block a user