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
13 changes: 10 additions & 3 deletions .github/workflows/changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

Expand Down
6 changes: 6 additions & 0 deletions docs/adr/0021-select-tests-from-changed-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 15 additions & 1 deletion scripts/dev/ci-changes.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 28 additions & 2 deletions tests/bats/ci-changes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"* ]]
Expand Down
Loading