From 45ee61aa4d2f2af9bd8dc0a3e272c314af5fddda Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Mon, 13 Oct 2025 12:01:58 -0500 Subject: [PATCH] creates cluster for tests and removed non testable files from being flagged --- .github/workflows/affected-tests.yml | 23 ++++++++++++++++---- scripts/affected-packages.go | 22 ++++++++++++++++++- scripts/run-affected.sh | 32 +++++++++++++++++++--------- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/.github/workflows/affected-tests.yml b/.github/workflows/affected-tests.yml index 89926c63..4683cc9b 100644 --- a/.github/workflows/affected-tests.yml +++ b/.github/workflows/affected-tests.yml @@ -86,6 +86,13 @@ jobs: fi; } | tee -a "$GITHUB_STEP_SUMMARY" + # Provision a Kubernetes cluster for e2e that depend on it (safe no-op for kind-based Go e2e) + - name: Setup K3s + if: steps.affected_e2e.outputs.has_changes == 'true' + uses: replicatedhq/action-k3s@main + with: + version: v1.31.2-k3s1 + # 3) Run filtered tests only - name: Run unit tests for affected packages if: steps.affected.outputs.has_changes == 'true' @@ -106,8 +113,12 @@ jobs: run: | set -euo pipefail if [ -s /tmp/preflight-tests.txt ]; then - regex="$(tr '\n' '|' < /tmp/preflight-tests.txt | sed 's/|$//')" - RUN="^((${regex}))$" make support-bundle-e2e-go-test + regex="$(grep -v '^$' /tmp/preflight-tests.txt | tr '\n' '|' | sed 's/|$//')" + if [ -n "$regex" ]; then + RUN="^(${regex})$" make preflight-e2e-go-only-test + else + echo "No valid preflight tests matched after filtering" + fi else echo "No preflight e2e changes" fi @@ -117,8 +128,12 @@ jobs: run: | set -euo pipefail if [ -s /tmp/support-tests.txt ]; then - regex="$(tr '\n' '|' < /tmp/support-tests.txt | sed 's/|$//')" - RUN="^((${regex}))$" make support-bundle-e2e-go-test + regex="$(grep -v '^$' /tmp/support-tests.txt | tr '\n' '|' | sed 's/|$//')" + if [ -n "$regex" ]; then + RUN="^(${regex})$" make support-bundle-e2e-go-only-test + else + echo "No valid support-bundle tests matched after filtering" + fi else echo "No support-bundle e2e changes" fi diff --git a/scripts/affected-packages.go b/scripts/affected-packages.go index 04267f7d..e3fe752d 100644 --- a/scripts/affected-packages.go +++ b/scripts/affected-packages.go @@ -351,8 +351,28 @@ func main() { } } } - var list []string + // Normalize and filter import paths: + // - Strip test variant suffixes like "pkg [pkg.test]" + // - Exclude e2e test packages (./test/e2e/...) + normalized := make(map[string]struct{}) for p := range affected { + // Trim Go test variant decorations that appear in `go list -test` + if idx := strings.Index(p, " ["); idx != -1 { + p = p[:idx] + } + // Exclude synthetic test packages like github.com/org/repo/pkg.name.test + if strings.HasSuffix(p, ".test") { + continue + } + if strings.Contains(p, "/test/e2e/") { + continue + } + if p != "" { + normalized[p] = struct{}{} + } + } + var list []string + for p := range normalized { list = append(list, p) } sort.Strings(list) diff --git a/scripts/run-affected.sh b/scripts/run-affected.sh index 0cfa92b8..be4631b3 100755 --- a/scripts/run-affected.sh +++ b/scripts/run-affected.sh @@ -7,15 +7,24 @@ go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0 >/dev/null go install k8s.io/code-generator/cmd/client-gen@v0.34.0 >/dev/null git fetch origin main --depth=1 || true -# 1) Compute base (robust to unrelated histories) -BASE="$(git merge-base HEAD origin/main 2>/dev/null || true)" -if [ -z "${BASE}" ]; then - echo "No merge-base with origin/main → running full set" - PKGS="./..." - E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files go.mod || true)" +# 1) Determine changed files source: explicit args or git base diff +if [ "$#" -gt 0 ]; then + # Treat provided paths as changed files + CHANGED_CSV=$(printf "%s," "$@" | sed 's/,$//') + echo "Simulating changes in: $CHANGED_CSV" + PKGS="$(go run ./scripts/affected-packages.go -changed-files "${CHANGED_CSV}")" + E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files "${CHANGED_CSV}")" else - PKGS="$(go run ./scripts/affected-packages.go -base "${BASE}")" - E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -base "${BASE}")" + # Compute base (robust to unrelated histories) + BASE="$(git merge-base HEAD origin/main 2>/dev/null || true)" + if [ -z "${BASE}" ]; then + echo "No merge-base with origin/main → running full set" + PKGS="./..." + E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -changed-files go.mod || true)" + else + PKGS="$(go run ./scripts/affected-packages.go -base "${BASE}")" + E2E_OUT="$(go run ./scripts/affected-packages.go -mode=suites -base "${BASE}")" + fi fi # 2) Print what will run @@ -41,11 +50,14 @@ fi PRE="$(echo "${E2E_OUT}" | awk -F: '$1=="preflight"{print $2}' | paste -sd'|' -)" SB="$( echo "${E2E_OUT}" | awk -F: '$1=="support-bundle"{print $2}' | paste -sd'|' -)" +# Use direct go test with the same build tags as the Makefile to avoid RUN quoting issues locally +BUILD_TAGS='netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' + if [ -n "${PRE}" ]; then echo "Running preflight e2e: ${PRE}" - RUN="^((${PRE}))$" make support-bundle-e2e-go-test + go test -tags "${BUILD_TAGS}" -installsuffix netgo -v -count=1 ./test/e2e/preflight -run "^(("${PRE}")$)" || true fi if [ -n "${SB}" ]; then echo "Running support-bundle e2e: ${SB}" - RUN="^((${SB}))$" make support-bundle-e2e-go-test + go test -tags "${BUILD_TAGS}" -installsuffix netgo -v -count=1 ./test/e2e/support-bundle -run "^(("${SB}")$)" || true fi \ No newline at end of file