From 160d46a16b4d6ee71e5833b8a4aba9b75fe31269 Mon Sep 17 00:00:00 2001 From: g1obalworlds <77709487+g1obalworlds@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:08:05 -0700 Subject: [PATCH 1/2] ci: run the unit tests when any workflow or action they cover changes test-freebsd.yml is the only workflow that runs tests/, but its path filter still lists the FreeBSD-era files. A change to sonarcloud.yml, supply-chain.yml, nix.yml, ast-grep.yml, or to actions such as arch-package, resolve-version, ast-grep or checkout-craft-fonts ran none of their tests: #86 (sonarcloud.yml and the README) and #90 (sonarcloud.yml) merged without test_sonarcloud.py running. Match every workflow, action and test file, and test that the filter does, with GitHub's glob rules. --- .github/workflows/test-freebsd.yml | 21 ++++----------- tests/test_unit_test_triggers.py | 41 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 tests/test_unit_test_triggers.py diff --git a/.github/workflows/test-freebsd.yml b/.github/workflows/test-freebsd.yml index 805dcf0..c6f9879 100644 --- a/.github/workflows/test-freebsd.yml +++ b/.github/workflows/test-freebsd.yml @@ -1,28 +1,17 @@ name: Shared FreeBSD workflow tests +# The suite covers every workflow and action, not only FreeBSD, so a change to any of them runs it. on: pull_request: paths: - - .github/workflows/freebsd.yml - - .github/workflows/release.yml - - .github/workflows/gate.yml - - actions/freebsd-cargo-cache/** - - actions/checkout-craft-i18n/** - - .github/workflows/windows-arm64.yml - - .github/workflows/test-freebsd.yml - - actions/install-apt-packages/** + - .github/workflows/** + - actions/** - tests/** push: branches: [main] paths: - - .github/workflows/freebsd.yml - - .github/workflows/release.yml - - .github/workflows/gate.yml - - actions/freebsd-cargo-cache/** - - actions/checkout-craft-i18n/** - - .github/workflows/windows-arm64.yml - - .github/workflows/test-freebsd.yml - - actions/install-apt-packages/** + - .github/workflows/** + - actions/** - tests/** workflow_dispatch: diff --git a/tests/test_unit_test_triggers.py b/tests/test_unit_test_triggers.py new file mode 100644 index 0000000..8480a83 --- /dev/null +++ b/tests/test_unit_test_triggers.py @@ -0,0 +1,41 @@ +"""The workflow that runs these tests must start for a change to anything they test.""" + +from pathlib import Path +import re +import unittest + +import yaml + + +ROOT = Path(__file__).resolve().parents[1] +WORKFLOW = yaml.load((ROOT / ".github/workflows/test-freebsd.yml").read_text(), Loader=yaml.BaseLoader) + + +def matches(path, pattern): + # GitHub path filters: * stops at /, ** crosses it. + regex = "".join(".*" if part == "**" else "[^/]*" if part == "*" else re.escape(part) + for part in re.split(r"(\*\*|\*)", pattern)) + return re.fullmatch(regex, path) is not None + + +class UnitTestTriggerTests(unittest.TestCase): + def test_every_workflow_action_and_test_file_triggers_the_tests(self): + files = [path.relative_to(ROOT).as_posix() + for directory in (".github/workflows", "actions", "tests") + for path in (ROOT / directory).rglob("*") + if path.is_file() and "__pycache__" not in path.parts] + self.assertIn(".github/workflows/sonarcloud.yml", files) + for event in ("pull_request", "push"): + patterns = WORKFLOW["on"][event]["paths"] + for file in files: + with self.subTest(event=event, file=file): + self.assertTrue(any(matches(file, pattern) for pattern in patterns)) + + def test_matches_follows_github_globs(self): + self.assertTrue(matches("actions/ast-grep/action.yml", "actions/**")) + self.assertFalse(matches("actions/ast-grep/action.yml", "actions/*")) + self.assertTrue(matches(".github/workflows/nix.yml", ".github/workflows/*.yml")) + + +if __name__ == "__main__": + unittest.main() From 539b28997cedc540697db94ed6634a3c4ecb4d87 Mon Sep 17 00:00:00 2001 From: g1obalworlds <77709487+g1obalworlds@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:47:48 -0700 Subject: [PATCH 2/2] ci: honor negated path patterns in the trigger test GitHub applies path filters in order, so a later !pattern excludes a file an earlier pattern matched. The test now does the same, instead of passing a file any one pattern matches. --- tests/test_unit_test_triggers.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_unit_test_triggers.py b/tests/test_unit_test_triggers.py index 8480a83..eb3af40 100644 --- a/tests/test_unit_test_triggers.py +++ b/tests/test_unit_test_triggers.py @@ -18,6 +18,16 @@ def matches(path, pattern): return re.fullmatch(regex, path) is not None +def triggers(path, patterns): + # In order: a later !pattern excludes a matched path, a later pattern includes it again. + included = False + for pattern in patterns: + negative = pattern.startswith("!") + if matches(path, pattern.removeprefix("!")): + included = not negative + return included + + class UnitTestTriggerTests(unittest.TestCase): def test_every_workflow_action_and_test_file_triggers_the_tests(self): files = [path.relative_to(ROOT).as_posix() @@ -29,12 +39,14 @@ class UnitTestTriggerTests(unittest.TestCase): patterns = WORKFLOW["on"][event]["paths"] for file in files: with self.subTest(event=event, file=file): - self.assertTrue(any(matches(file, pattern) for pattern in patterns)) + self.assertTrue(triggers(file, patterns)) def test_matches_follows_github_globs(self): self.assertTrue(matches("actions/ast-grep/action.yml", "actions/**")) self.assertFalse(matches("actions/ast-grep/action.yml", "actions/*")) self.assertTrue(matches(".github/workflows/nix.yml", ".github/workflows/*.yml")) + self.assertFalse(triggers("actions/ast-grep/action.yml", ["actions/**", "!actions/ast-grep/**"])) + self.assertTrue(triggers("actions/ast-grep/action.yml", ["actions/**", "!actions/**", "actions/ast-grep/*"])) if __name__ == "__main__":