Files
Kamino/scripts/check_tarball.py
T
Defame1297andClaude Sonnet 5.5 e3acab9ca2
Build / build (pull_request) Failing after 9s
Lint / lint (pull_request) Successful in 6s
Molecule / molecule (pull_request) Successful in 28s
fix(build): keep repository tooling and molecule scenarios out of the Collection archive
Extend galaxy.yml build_ignore (extensions, role molecule scenarios, CLAUDE.md, tool
directories, tests/scripts) and add scripts/check_tarball.py, an allow-list check run
by the Build workflow after the Collection build and before galaxy-importer.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-10-25 18:23:42 +00:00

61 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
"""Assert that a built Collection tarball holds only files meant for consumers.
scripts/check_tarball.py dist/mortis-kamino-X.Y.Z.tar.gz
galaxy.yml `build_ignore` is a deny list: a new file at the repository root (a tool's
cache, an editor's directory, an agent's settings) ships silently. This check is the
allow list. A top-level entry that is not in ALLOWED_TOP, or a path under an entry that
matches FORBIDDEN, fails the build. When the Collection gains a plugin type or a
directory consumers should get, add it to ALLOWED_TOP in the same change.
"""
import fnmatch
import sys
import tarfile
ALLOWED_TOP = {
"COPYING", "FILES.json", "LICENSES", "MANIFEST.json", "NOTICE", "README.md",
"REUSE.toml", "changelogs", "docs", "meta", "plugins", "roles", "tests",
}
# Checked on every member, whatever its top-level directory.
FORBIDDEN = [
"*/molecule/*", "*/molecule", "tests/scripts*", "*.pyc", "*__pycache__*", "*.tar.gz",
"*.pem", "*.key", "*.vault*", "*vault-pass*", "*/.git/*", "*.env", "*importer_result.json",
]
def problems(names):
found = []
for name in sorted(names):
path = name.rstrip("/")
if path.startswith("./"):
path = path[2:]
if not path:
continue
top = path.split("/", 1)[0]
if top not in ALLOWED_TOP:
found.append(f"{path}: top-level entry '{top}' is not allowed in the Collection archive")
elif any(fnmatch.fnmatch(path, pat) for pat in FORBIDDEN):
found.append(f"{path}: matches a forbidden pattern")
return found
def main(argv):
if len(argv) != 2:
sys.stderr.write(__doc__)
return 2
with tarfile.open(argv[1]) as tar:
names = tar.getnames()
bad = problems(names)
if bad:
sys.stderr.write("Unexpected files in the Collection archive:\n " + "\n ".join(bad) + "\n")
return 1
print(f"{argv[1]}: {len(names)} entries, all allowed")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))