Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
37292e6
finds and runs relevant code change tests
NoaheCampbell Oct 10, 2025
3f06912
added flag to specify files changed for testing
NoaheCampbell Oct 11, 2025
a2a424b
added test and makes new relevant tests run tests
NoaheCampbell Oct 11, 2025
8762bd1
changed tests always are flagged as affected tests
NoaheCampbell Oct 11, 2025
2d664b8
separated build and test actions for relevant tests
NoaheCampbell Oct 13, 2025
d325804
readded build binary action for tests
NoaheCampbell Oct 13, 2025
1c234e4
shows affected test summary
NoaheCampbell Oct 13, 2025
0f747f5
removed main requirement on affected tests
NoaheCampbell Oct 13, 2025
e05962b
affected test workflow runs on PR
NoaheCampbell Oct 13, 2025
2b82454
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
cb32216
runs all tests when test change is detected
NoaheCampbell Oct 13, 2025
e3458ad
can run unit tests via makefile
NoaheCampbell Oct 13, 2025
45ee61a
creates cluster for tests and removed non testable files from being f…
NoaheCampbell Oct 13, 2025
bf1dfa0
removed references to nonexistent tests
NoaheCampbell Oct 13, 2025
6ea8cbc
creates clusters for tests via replicated actions
NoaheCampbell Oct 13, 2025
a6d3e3e
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
8f7cf26
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
1aa74db
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
fb09834
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
78af920
runs e2e preflight and support bundle tests as matrix
NoaheCampbell Oct 13, 2025
409a02a
Update affected-tests.yml
NoaheCampbell Oct 13, 2025
c84ea20
e2e test make target build the binaries first
NoaheCampbell Oct 13, 2025
a677646
reduced redundant building
NoaheCampbell Oct 13, 2025
8920a9d
Update Makefile
NoaheCampbell Oct 13, 2025
f7a941c
regression tests run separate from relevant test detection
NoaheCampbell Oct 14, 2025
e084c0a
regression tests run in matrix
NoaheCampbell Oct 14, 2025
9278d50
use kubeconfig to properly set up preflight regression tests
NoaheCampbell Oct 14, 2025
e73e137
uses unique namespaces for different preflight regression tests
NoaheCampbell Oct 14, 2025
1013f2a
does not recalculate affected e2e tests
NoaheCampbell Oct 14, 2025
2a2b0e0
reverted regression tests to how they were before
NoaheCampbell Oct 14, 2025
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
170 changes: 170 additions & 0 deletions .github/workflows/affected-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: Affected Go Tests

on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

permissions:
contents: read

jobs:
test-affected:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Go Mod Download
run: go mod download

- name: Compute base ref
id: pr-info
run: |
echo "BASE_REF=origin/${{ github.base_ref }}" >> "$GITHUB_OUTPUT"
echo "Base ref: origin/${{ github.base_ref }}"
# 2) Detect relevant unit packages and e2e tests
- name: Compute affected packages
id: affected
run: |
set -euo pipefail
echo "Base: ${{ steps.pr-info.outputs.BASE_REF }}"
# Generate affected package list to a file for reuse in subsequent steps
go run ./scripts/affected-packages.go -base "${{ steps.pr-info.outputs.BASE_REF }}" > /tmp/affected.txt
echo "Affected packages:" || true
if [ -s /tmp/affected.txt ]; then
cat /tmp/affected.txt
else
echo "(none)"
fi
# Expose whether we have any packages to test
if [ -s /tmp/affected.txt ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Compute affected e2e tests
id: affected_e2e
run: |
set -euo pipefail
go run ./scripts/affected-packages.go -mode=suites -base "${{ steps.pr-info.outputs.BASE_REF }}" > /tmp/affected-e2e.txt
awk -F: '$1=="preflight"{print $2}' /tmp/affected-e2e.txt > /tmp/preflight-tests.txt
awk -F: '$1=="support-bundle"{print $2}' /tmp/affected-e2e.txt > /tmp/support-tests.txt
if [ -s /tmp/preflight-tests.txt ] || [ -s /tmp/support-tests.txt ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish affected summary
if: always()
run: |
{
echo "### Affected unit packages";
if [ -s /tmp/affected.txt ]; then
sed 's/^/- /' /tmp/affected.txt;
else
echo "- (none)";
fi;
echo;
echo "### Affected e2e tests";
if [ -s /tmp/affected-e2e.txt ]; then
sed 's/^/- /' /tmp/affected-e2e.txt;
else
echo "- (none)";
fi;
} | tee -a "$GITHUB_STEP_SUMMARY"
# Provision a Kubernetes cluster for e2e using Replicated compatibility actions
- name: Create k3s cluster
id: create-cluster
if: steps.affected_e2e.outputs.has_changes == 'true'
uses: replicatedhq/compatibility-actions/create-cluster@v1
with:
api-token: ${{ secrets.REPLICATED_API_TOKEN }}
kubernetes-distribution: k3s
cluster-name: pr-${{ github.run_id }}-${{ github.run_attempt }}
ttl: 25m
timeout-minutes: 5

- name: Configure kubeconfig
if: steps.affected_e2e.outputs.has_changes == 'true'
run: |
echo "${{ steps.create-cluster.outputs.cluster-kubeconfig }}" > $GITHUB_WORKSPACE/kubeconfig.yaml
echo "KUBECONFIG=$GITHUB_WORKSPACE/kubeconfig.yaml" >> $GITHUB_ENV
- name: Build binaries for script-based e2e
if: steps.affected_e2e.outputs.has_changes == 'true'
run: |
make bin/preflight bin/support-bundle
# 3) Run filtered tests only
- name: Run unit tests for affected packages
if: steps.affected.outputs.has_changes == 'true'
run: |
set -euo pipefail
# If the script output contains './...' then run all tests
if grep -qx "./..." /tmp/affected.txt; then
echo "Module files changed; running all tests"
make test
else
echo "Running tests for affected packages"
pkgs=$(tr '\n' ' ' < /tmp/affected.txt)
PACKAGES="$pkgs" make test-packages
fi
- name: Run preflight e2e (filtered)
if: steps.affected_e2e.outputs.has_changes == 'true'
run: |
set -euo pipefail
if [ -s /tmp/preflight-tests.txt ]; then
regex="$(grep -v '^$' /tmp/preflight-tests.txt | tr '\n' '|' | sed 's/|$//')"
if [ -n "$regex" ]; then
RUN="^(${regex})$" make preflight-e2e-test
else
echo "No valid preflight tests matched after filtering"
fi
else
echo "No preflight e2e changes"
fi
- name: Run support-bundle e2e (filtered)
if: steps.affected_e2e.outputs.has_changes == 'true'
run: |
set -euo pipefail
if [ -s /tmp/support-tests.txt ]; then
regex="$(grep -v '^$' /tmp/support-tests.txt | tr '\n' '|' | sed 's/|$//')"
if [ -n "$regex" ]; then
RUN="^(${regex})$" make support-bundle-e2e-go-test
else
echo "No valid support-bundle tests matched after filtering"
fi
else
echo "No support-bundle e2e changes"
fi
- name: No affected packages — skip tests
if: steps.affected.outputs.has_changes != 'true'
run: echo "No Go packages affected by this PR; skipping tests."

# Cleanup cluster
- name: Remove cluster
if: always() && steps.affected_e2e.outputs.has_changes == 'true'
uses: replicatedhq/compatibility-actions/remove-cluster@v1
continue-on-error: true
with:
api-token: ${{ secrets.REPLICATED_API_TOKEN }}
cluster-id: ${{ steps.create-cluster.outputs.cluster-id }}


13 changes: 9 additions & 4 deletions .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- run: make tidy-diff

test-integration:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -65,6 +66,7 @@ jobs:
path: bin/preflight

validate-preflight-e2e:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: compile-preflight
steps:
Expand Down Expand Up @@ -95,6 +97,7 @@ jobs:
path: bin/support-bundle

validate-supportbundle-e2e:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: compile-supportbundle
steps:
Expand All @@ -113,9 +116,10 @@ jobs:

# Additional e2e tests for support bundle that run in Go, these create a Kind cluster
validate-supportbundle-e2e-go:
runs-on: ubuntu-latest
needs: compile-supportbundle
steps:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: compile-supportbundle
steps:
- uses: actions/checkout@v5
- name: Download support bundle binary
uses: actions/download-artifact@v5
Expand All @@ -133,6 +137,7 @@ jobs:

# summary jobs, these jobs will only run if all the other jobs have succeeded
validate-pr-tests:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- tidy-check
Expand All @@ -147,10 +152,10 @@ jobs:
# this job will validate that the validation did not fail and that all pr-tests succeed
# it is used for the github branch protection rule
validate-success:
if: ${{ always() && github.event_name == 'push' }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Branch Protection Bypassed by Job Event Change

The validate-success job, intended for GitHub branch protection, now only runs on push events. This prevents the required status check from being available for pull requests, breaking branch protection.

Fix in Cursor Fix in Web

runs-on: ubuntu-latest
needs:
- validate-pr-tests
if: always()
steps:
# https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
# if the validate-pr-tests job was not successful, this job will fail
Expand Down
91 changes: 32 additions & 59 deletions .github/workflows/build-test.yaml → .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-test
name: build

on:
pull_request:
Expand Down Expand Up @@ -47,6 +47,19 @@ jobs:
- uses: actions/checkout@v5
- uses: ./.github/actions/setup-go

- name: Cache Go build and modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Go mod download
run: go mod download

- name: Check go mod tidy
run: |
go mod tidy
Expand All @@ -65,22 +78,7 @@ jobs:
make vet

# Unit and integration tests
test:
if: needs.changes.outputs.go-files == 'true'
needs: [changes, lint]
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/setup-go

- name: Setup K3s
uses: replicatedhq/action-k3s@main
with:
version: v1.31.2-k3s1

- name: Run tests
run: make test-integration
# (moved to push-full-tests.yml)

# Build binaries
build:
Expand All @@ -91,71 +89,46 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/setup-go
- run: make build
- uses: actions/upload-artifact@v4
with:
name: binaries
path: bin/
retention-days: 1

# E2E tests
e2e:
if: needs.changes.outputs.go-files == 'true' || github.event_name == 'push'
needs: [changes, build]
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- name: preflight
target: preflight-e2e-test
needs-k3s: true
- name: support-bundle-shell
target: support-bundle-e2e-test
needs-k3s: true
- name: support-bundle-go
target: support-bundle-e2e-go-test
needs-k3s: false
steps:
- uses: actions/checkout@v5

- name: Setup K3s
if: matrix.needs-k3s
uses: replicatedhq/action-k3s@main
- name: Cache Go build and modules
uses: actions/cache@v4
with:
version: v1.31.2-k3s1
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- uses: actions/download-artifact@v4
- name: Go mod download
run: go mod download
- run: make build
- uses: actions/upload-artifact@v4
with:
name: binaries
path: bin/
retention-days: 1

- run: chmod +x bin/*
- run: make ${{ matrix.target }}
# (moved to push-full-tests.yml)

# Success summary
success:
if: always()
needs: [lint, test, build, e2e]
needs: [lint, build]
runs-on: ubuntu-latest
steps:
- name: Check results
run: |
# Check if any required jobs failed
if [[ "${{ needs.lint.result }}" == "failure" ]] || \
[[ "${{ needs.test.result }}" == "failure" ]] || \
[[ "${{ needs.build.result }}" == "failure" ]] || \
[[ "${{ needs.e2e.result }}" == "failure" ]]; then
[[ "${{ needs.build.result }}" == "failure" ]]; then
echo "::error::Some jobs failed or were cancelled"
exit 1
fi

# Check if any required jobs were cancelled
if [[ "${{ needs.lint.result }}" == "cancelled" ]] || \
[[ "${{ needs.test.result }}" == "cancelled" ]] || \
[[ "${{ needs.build.result }}" == "cancelled" ]] || \
[[ "${{ needs.e2e.result }}" == "cancelled" ]]; then
[[ "${{ needs.build.result }}" == "cancelled" ]]; then
echo "::error::Some jobs failed or were cancelled"
exit 1
fi
Expand Down
Loading
Loading