Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AUDIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ Run [`WORKFLOW.md`][workflow]'s methodology against the repo's **own** Actions:

```sh
# Anchor to the line start (optional list dash) so a commented-out '# package-ecosystem:' is not counted.
decl=$(gh api "repos/<owner>/<repo>/contents/.github/dependabot.yml?ref=<ground>" --jq '.content' | base64 -d | grep -oE '^[[:space:]]*-?[[:space:]]*package-ecosystem:[[:space:]]*"?[a-z-]+' | grep -oE '[a-z-]+$' | sort -u)
dependabot_content=$(gh api "repos/<owner>/<repo>/contents/.github/dependabot.yml?ref=<ground>" --jq '.content') || exit 1
dependabot_yaml=$(base64 -d <<<"$dependabot_content") || exit 1
decl=$(grep -oE '^[[:space:]]*-?[[:space:]]*package-ecosystem:[[:space:]]*"?[a-z-]+' <<<"$dependabot_yaml" | grep -oE '[a-z-]+$' | sort -u)
root_paths=$(gh api "repos/<owner>/<repo>/contents?ref=<ground>" --jq '.[].path') || exit 1
github_paths=$(gh api "repos/<owner>/<repo>/contents/.github?ref=<ground>" --jq '.[].path') || exit 1
has() { grep -Fxq "$1" <<<"$root_paths"$'\n'"$github_paths"; }
Expand Down
12 changes: 9 additions & 3 deletions scripts/tests/test_release_guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def test_publish_requires_successful_validation(self) -> None:
)
self.assertIn("\"needs.validate.result == 'success'\"", files_spec)

def test_audit_root_probe_fails_before_local_path_checks(self) -> None:
def test_audit_probes_fail_before_local_path_checks(self) -> None:
audit = (REPO / "AUDIT.md").read_text(encoding="utf-8")
lines = audit.splitlines()
start = next(i for i, line in enumerate(lines) if line.startswith(" root_paths="))
probe = "\n".join(line.removeprefix(" ") for line in lines[start : start + 3])
start = next(i for i, line in enumerate(lines) if line.startswith(" dependabot_content="))
probe = "\n".join(line.removeprefix(" ") for line in lines[start : start + 6])
fake_api = r"""
gh() {
case "$2" in
repos/*/contents/.github/dependabot.yml\?*) printf '%s\n' '- package-ecosystem: github-actions' '- package-ecosystem: devcontainers' | base64 ;;
repos/*/contents/.github\?*) printf '%s\n' .github/dependabot.yml .github/workflows ;;
repos/*/contents\?*) printf '%s\n' .devcontainer .github ;;
*) return 17 ;;
Expand All @@ -45,9 +46,14 @@ def test_audit_root_probe_fails_before_local_path_checks(self) -> None:
["bash", "-c", f"gh() {{ return 17; }}\n{probe}\nexit 0"],
check=False,
)
decode_failure = run(
["bash", "-c", f"gh() {{ printf invalid; }}\n{probe}\nexit 0"],
check=False,
)

self.assertEqual(0, success.returncode)
self.assertNotEqual(0, failure.returncode)
self.assertNotEqual(0, decode_failure.returncode)
self.assertNotIn(
'gh api "repos/<owner>/<repo>/contents/$1?ref=<ground>" >/dev/null 2>&1',
audit,
Expand Down