diff --git a/.github/workflows/changes.yml b/.github/workflows/changes.yml index 47b6531..8a0e9b6 100644 --- a/.github/workflows/changes.yml +++ b/.github/workflows/changes.yml @@ -40,14 +40,21 @@ jobs: EVENT_NAME: ${{ github.event_name }} BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PUSH_BEFORE: ${{ github.event.before }} + PUSH_AFTER: ${{ github.sha }} shell: bash run: | set -euo pipefail - if [[ "$EVENT_NAME" != pull_request ]]; then - bash scripts/dev/ci-changes.bash --all >"$GITHUB_OUTPUT" - else + # A PR is routed by its diff, and a push by the commits it added. A scheduled run, a + # manual run, and a push whose earlier commit is unknown run everything. + if [[ "$EVENT_NAME" == pull_request ]]; then git diff --no-renames --name-only -z "$BASE_SHA...$HEAD_SHA" \ | bash scripts/dev/ci-changes.bash >"$GITHUB_OUTPUT" + elif [[ "$EVENT_NAME" == push ]] && git cat-file -e "${PUSH_BEFORE}^{commit}" 2>/dev/null; then + git diff --no-renames --name-only -z "$PUSH_BEFORE" "$PUSH_AFTER" \ + | bash scripts/dev/ci-changes.bash >"$GITHUB_OUTPUT" + else + bash scripts/dev/ci-changes.bash --all >"$GITHUB_OUTPUT" fi for group in lint bats runtime packaging rules; do grep -Eq "^${group}=(true|false)$" "$GITHUB_OUTPUT" diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index f7fcad1..b8ced87 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -5,6 +5,10 @@ on: pull_request: push: branches: [main] + # A weekly run of every test, because a push now runs only the tests for what it changed. + schedule: + - cron: "17 3 * * 1" + workflow_dispatch: permissions: {} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d05bb7b..fde71d1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,6 +5,10 @@ on: pull_request: push: branches: [main] + # A weekly run of every test, because a push now runs only the tests for what it changed. + schedule: + - cron: "17 3 * * 1" + workflow_dispatch: permissions: {} diff --git a/docs/adr/0021-select-tests-from-changed-files.md b/docs/adr/0021-select-tests-from-changed-files.md index 7db4784..d6eddbf 100644 --- a/docs/adr/0021-select-tests-from-changed-files.md +++ b/docs/adr/0021-select-tests-from-changed-files.md @@ -52,3 +52,9 @@ Existing required check names stay the same. Documentation changes avoid host tests. Mixed changes run the union of their test groups. New file types run all tests until we add a narrower rule and a regression test for it. Local validation commands remain unchanged. + +Note, 2026-11-12: a push to `main` no longer runs the full suite. It is routed by the files that +the push changed, like a PR, because every merge is a squash of a PR that already ran those +tests. The integration and lint workflows run everything once a week and when started by hand. +A workflow file now selects only the tests it runs, and only `changes.yml` and the routing script +select the full suite. `.gitignore`, the ruleset files, and `config/wazuh/` select no kernel tests. diff --git a/scripts/dev/ci-changes.bash b/scripts/dev/ci-changes.bash index 8f94d98..42175a1 100644 --- a/scripts/dev/ci-changes.bash +++ b/scripts/dev/ci-changes.bash @@ -15,14 +15,28 @@ elif [[ $# != 0 ]]; then else while IFS= read -r -d '' path; do case "$path" in - .github/workflows/* | scripts/dev/ci-changes.bash | tests/bats/ci-changes.bats) + .github/workflows/changes.yml | scripts/dev/ci-changes.bash | tests/bats/ci-changes.bats) full=true ;; + .github/workflows/integration.yml) + lint=true; runtime=true ;; + .github/workflows/lint.yml) + lint=true; bats=true; packaging=true; rules=true ;; + .github/workflows/release.yml) + lint=true; packaging=true ;; + .github/workflows/*) + lint=true ;; + .github/rulesets/* | .gitignore | .gitattributes) + ;; + tests/lint.sh) + lint=true ;; tests/ci/real-kernel.sh | tests/ci/container-install.sh | tests/ci/vm-run.sh) lint=true; runtime=true ;; tests/bats/* | tests/fixtures/*) lint=true; bats=true ;; scripts/dev/*) lint=true; bats=true; packaging=true ;; + config/wazuh/*) + lint=true; bats=true; packaging=true ;; scripts/* | config/*) full=true ;; rules/README.md) diff --git a/tests/bats/ci-changes.bats b/tests/bats/ci-changes.bats index 2c7c032..e893601 100644 --- a/tests/bats/ci-changes.bats +++ b/tests/bats/ci-changes.bats @@ -45,13 +45,39 @@ route() { [[ "$output" == *"runtime=true"* ]] } -@test "workflow and routing changes select all tests" { - for path in .github/workflows/lint.yml scripts/dev/ci-changes.bash tests/bats/ci-changes.bats; do +@test "routing changes select all tests" { + for path in .github/workflows/changes.yml scripts/dev/ci-changes.bash tests/bats/ci-changes.bats; do run route "$path" [[ "$output" != *"=false"* ]] done } +@test "a workflow selects the tests it runs" { + run route .github/workflows/integration.yml + [[ "$output" == *"runtime=true"* ]] + [[ "$output" == *"bats=false"* ]] + run route .github/workflows/lint.yml + [[ "$output" == *"bats=true"* ]] + [[ "$output" == *"runtime=false"* ]] + run route .github/workflows/release.yml + [[ "$output" == *"packaging=true"* ]] + [[ "$output" == *"runtime=false"* ]] + run route .github/workflows/security.yml + [[ "$output" == *"lint=true"* ]] + [[ "$output" == *"runtime=false"* ]] +} + +@test "repo settings files and Wazuh content select no VM tests" { + run route .gitignore .github/rulesets/main.json + [[ "$output" != *"=true"* ]] + run route config/wazuh/auditd-kit-rules.xml + [[ "$output" == *"bats=true"* ]] + [[ "$output" == *"runtime=false"* ]] + run route tests/lint.sh + [[ "$output" == *"lint=true"* ]] + [[ "$output" == *"runtime=false"* ]] +} + @test "YAML extensions select lint outside known directories" { run route new/settings.yaml .github/ISSUE_TEMPLATE/bug.yml [[ "$output" == *"lint=true"* ]]