Skip to content

Commit 45ee61a

Browse files
committed
creates cluster for tests and removed non testable files from being flagged
1 parent e3458ad commit 45ee61a

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

.github/workflows/affected-tests.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ jobs:
8686
fi;
8787
} | tee -a "$GITHUB_STEP_SUMMARY"
8888
89+
# Provision a Kubernetes cluster for e2e that depend on it (safe no-op for kind-based Go e2e)
90+
- name: Setup K3s
91+
if: steps.affected_e2e.outputs.has_changes == 'true'
92+
uses: replicatedhq/action-k3s@main
93+
with:
94+
version: v1.31.2-k3s1
95+
8996
# 3) Run filtered tests only
9097
- name: Run unit tests for affected packages
9198
if: steps.affected.outputs.has_changes == 'true'
@@ -106,8 +113,12 @@ jobs:
106113
run: |
107114
set -euo pipefail
108115
if [ -s /tmp/preflight-tests.txt ]; then
109-
regex="$(tr '\n' '|' < /tmp/preflight-tests.txt | sed 's/|$//')"
110-
RUN="^((${regex}))$" make support-bundle-e2e-go-test
116+
regex="$(grep -v '^$' /tmp/preflight-tests.txt | tr '\n' '|' | sed 's/|$//')"
117+
if [ -n "$regex" ]; then
118+
RUN="^(${regex})$" make preflight-e2e-go-only-test
119+
else
120+
echo "No valid preflight tests matched after filtering"
121+
fi
111122
else
112123
echo "No preflight e2e changes"
113124
fi
@@ -117,8 +128,12 @@ jobs:
117128
run: |
118129
set -euo pipefail
119130
if [ -s /tmp/support-tests.txt ]; then
120-
regex="$(tr '\n' '|' < /tmp/support-tests.txt | sed 's/|$//')"
121-
RUN="^((${regex}))$" make support-bundle-e2e-go-test
131+
regex="$(grep -v '^$' /tmp/support-tests.txt | tr '\n' '|' | sed 's/|$//')"
132+
if [ -n "$regex" ]; then
133+
RUN="^(${regex})$" make support-bundle-e2e-go-only-test
134+
else
135+
echo "No valid support-bundle tests matched after filtering"
136+
fi
122137
else
123138
echo "No support-bundle e2e changes"
124139
fi

scripts/affected-packages.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,28 @@ func main() {
351351
}
352352
}
353353
}
354-
var list []string
354+
// Normalize and filter import paths:
355+
// - Strip test variant suffixes like "pkg [pkg.test]"
356+
// - Exclude e2e test packages (./test/e2e/...)
357+
normalized := make(map[string]struct{})
355358
for p := range affected {
359+
// Trim Go test variant decorations that appear in `go list -test`
360+
if idx := strings.Index(p, " ["); idx != -1 {
361+
p = p[:idx]
362+
}
363+
// Exclude synthetic test packages like github.com/org/repo/pkg.name.test
364+
if strings.HasSuffix(p, ".test") {
365+
continue
366+
}
367+
if strings.Contains(p, "/test/e2e/") {
368+
continue
369+
}
370+
if p != "" {
371+
normalized[p] = struct{}{}
372+
}
373+
}
374+
var list []string
375+
for p := range normalized {
356376
list = append(list, p)
357377
}
358378
sort.Strings(list)

scripts/run-affected.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ go install sigs.k8s.io/controller-tools/cmd/[email protected] >/dev/null
77
go install k8s.io/code-generator/cmd/[email protected] >/dev/null
88
git fetch origin main --depth=1 || true
99

10-
# 1) Compute base (robust to unrelated histories)
11-
BASE="$(git merge-base HEAD origin/main 2>/dev/null || true)"
12-
if [ -z "${BASE}" ]; then
13-
echo "No merge-base with origin/main → running full set"
14-
PKGS="./..."
15-
E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files go.mod || true)"
10+
# 1) Determine changed files source: explicit args or git base diff
11+
if [ "$#" -gt 0 ]; then
12+
# Treat provided paths as changed files
13+
CHANGED_CSV=$(printf "%s," "$@" | sed 's/,$//')
14+
echo "Simulating changes in: $CHANGED_CSV"
15+
PKGS="$(go run ./scripts/affected-packages.go -changed-files "${CHANGED_CSV}")"
16+
E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files "${CHANGED_CSV}")"
1617
else
17-
PKGS="$(go run ./scripts/affected-packages.go -base "${BASE}")"
18-
E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -base "${BASE}")"
18+
# Compute base (robust to unrelated histories)
19+
BASE="$(git merge-base HEAD origin/main 2>/dev/null || true)"
20+
if [ -z "${BASE}" ]; then
21+
echo "No merge-base with origin/main → running full set"
22+
PKGS="./..."
23+
E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files go.mod || true)"
24+
else
25+
PKGS="$(go run ./scripts/affected-packages.go -base "${BASE}")"
26+
E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -base "${BASE}")"
27+
fi
1928
fi
2029

2130
# 2) Print what will run
@@ -41,11 +50,14 @@ fi
4150
PRE="$(echo "${E2E_OUT}" | awk -F: '$1=="preflight"{print $2}' | paste -sd'|' -)"
4251
SB="$( echo "${E2E_OUT}" | awk -F: '$1=="support-bundle"{print $2}' | paste -sd'|' -)"
4352

53+
# Use direct go test with the same build tags as the Makefile to avoid RUN quoting issues locally
54+
BUILD_TAGS='netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp'
55+
4456
if [ -n "${PRE}" ]; then
4557
echo "Running preflight e2e: ${PRE}"
46-
RUN="^((${PRE}))$" make support-bundle-e2e-go-test
58+
go test -tags "${BUILD_TAGS}" -installsuffix netgo -v -count=1 ./test/e2e/preflight -run "^(("${PRE}")$)" || true
4759
fi
4860
if [ -n "${SB}" ]; then
4961
echo "Running support-bundle e2e: ${SB}"
50-
RUN="^((${SB}))$" make support-bundle-e2e-go-test
62+
go test -tags "${BUILD_TAGS}" -installsuffix netgo -v -count=1 ./test/e2e/support-bundle -run "^(("${SB}")$)" || true
5163
fi

0 commit comments

Comments
 (0)