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
This commit is contained in:
1 parent
32018e27f0
commit
e3acab9ca2
5 files changed
+113
No files matched your search
@@ -91,6 +91,12 @@ jobs:
|
||||
ls -l /tmp/dist
|
||||
sha256sum /tmp/dist/*.tar.gz
|
||||
|
||||
# The archive is what consumers get: only the allow list of scripts/check_tarball.py.
|
||||
- name: Check the archive contents
|
||||
run: |
|
||||
export PATH="/opt/venv/bin:$PATH"
|
||||
python3 scripts/check_tarball.py /tmp/dist/mortis-kamino-*.tar.gz
|
||||
|
||||
# galaxy-importer without ansible-test and without Docker (ADR 0004, Collection
|
||||
# repo gates). The importer reads its configuration from this file.
|
||||
- name: Run galaxy-importer
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
minor_changes:
|
||||
- >-
|
||||
The Collection archive no longer contains extensions/ (the image-smoke molecule scenario),
|
||||
the roles' molecule scenarios, CLAUDE.md or other repository tooling; the Build workflow
|
||||
now fails when the archive holds anything outside an allow list.
|
||||
+14
@@ -19,13 +19,27 @@ homepage: https://git.rkdr.net/mortis/kamino
|
||||
issues: https://git.rkdr.net/mortis/kamino/issues
|
||||
dependencies: {}
|
||||
build_ignore:
|
||||
# Repository tooling that is not part of the Collection. scripts/check_tarball.py fails
|
||||
# the build if anything outside its allowlist ends up in the archive, so a new top-level
|
||||
# file is a decision: ignore it here or allow it there.
|
||||
- .ansible
|
||||
- .claude
|
||||
- .gitea
|
||||
- .gitignore
|
||||
- .pre-commit-config.yaml
|
||||
- .reuse
|
||||
- .venv
|
||||
- .yamllint
|
||||
- .ansible-lint
|
||||
- CLAUDE.md
|
||||
- CONTRIBUTING.md
|
||||
- HANDOFF.md
|
||||
- extensions
|
||||
- images
|
||||
- scripts
|
||||
- requirements-dev.txt
|
||||
- gitleaks-report.json
|
||||
- importer_result.json
|
||||
- tests/scripts
|
||||
- 'roles/*/molecule'
|
||||
- '*.tar.gz'
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/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))
|
||||
@@ -0,0 +1,28 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Run with: python3 -m unittest discover -s tests/scripts"""
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "scripts"))
|
||||
import check_tarball # noqa: E402
|
||||
|
||||
|
||||
class TarballTest(unittest.TestCase):
|
||||
def test_clean(self):
|
||||
self.assertEqual(check_tarball.problems(
|
||||
["README.md", "roles/", "roles/a/tasks/main.yml", "LICENSES/MIT.txt", "tests/sanity/x.txt"]), [])
|
||||
|
||||
def test_stray_top_level(self):
|
||||
for name in (".venv/lib/a.py", "CLAUDE.md", ".claude/settings.json", "importer_result.json", "extensions/m.yml"):
|
||||
self.assertEqual(len(check_tarball.problems([name])), 1, name)
|
||||
|
||||
def test_forbidden_inside_allowed(self):
|
||||
self.assertEqual(len(check_tarball.problems(["roles/a/molecule/default/molecule.yml"])), 1)
|
||||
self.assertEqual(len(check_tarball.problems(["roles/a/files/k.pem"])), 1)
|
||||
self.assertEqual(len(check_tarball.problems(["tests/scripts/t.py"])), 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user