creates cluster for tests and removed non testable files from being flagged

This commit is contained in:
Noah Campbell
2025-10-13 12:01:58 -05:00
parent e3458ad297
commit 45ee61aa4d
3 changed files with 62 additions and 15 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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