-
Notifications
You must be signed in to change notification settings - Fork 105
Run relevant tests #1896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoaheCampbell
wants to merge
30
commits into
main
Choose a base branch
from
run-relevant-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,134
−71
Open
Run relevant tests #1896
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 3f06912
added flag to specify files changed for testing
NoaheCampbell a2a424b
added test and makes new relevant tests run tests
NoaheCampbell 8762bd1
changed tests always are flagged as affected tests
NoaheCampbell 2d664b8
separated build and test actions for relevant tests
NoaheCampbell d325804
readded build binary action for tests
NoaheCampbell 1c234e4
shows affected test summary
NoaheCampbell 0f747f5
removed main requirement on affected tests
NoaheCampbell e05962b
affected test workflow runs on PR
NoaheCampbell 2b82454
Update affected-tests.yml
NoaheCampbell cb32216
runs all tests when test change is detected
NoaheCampbell e3458ad
can run unit tests via makefile
NoaheCampbell 45ee61a
creates cluster for tests and removed non testable files from being f…
NoaheCampbell bf1dfa0
removed references to nonexistent tests
NoaheCampbell 6ea8cbc
creates clusters for tests via replicated actions
NoaheCampbell a6d3e3e
Update affected-tests.yml
NoaheCampbell 8f7cf26
Update affected-tests.yml
NoaheCampbell 1aa74db
Update affected-tests.yml
NoaheCampbell fb09834
Update affected-tests.yml
NoaheCampbell 78af920
runs e2e preflight and support bundle tests as matrix
NoaheCampbell 409a02a
Update affected-tests.yml
NoaheCampbell c84ea20
e2e test make target build the binaries first
NoaheCampbell a677646
reduced redundant building
NoaheCampbell 8920a9d
Update Makefile
NoaheCampbell f7a941c
regression tests run separate from relevant test detection
NoaheCampbell e084c0a
regression tests run in matrix
NoaheCampbell 9278d50
use kubeconfig to properly set up preflight regression tests
NoaheCampbell e73e137
uses unique namespaces for different preflight regression tests
NoaheCampbell 1013f2a
does not recalculate affected e2e tests
NoaheCampbell 2a2b0e0
reverted regression tests to how they were before
NoaheCampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 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 }} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -65,6 +66,7 @@ jobs: | |
path: bin/preflight | ||
|
||
validate-preflight-e2e: | ||
if: github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
needs: compile-preflight | ||
steps: | ||
|
@@ -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: | ||
|
@@ -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: | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- uses: actions/checkout@v5 | ||
- name: Download support bundle binary | ||
uses: actions/download-artifact@v5 | ||
|
@@ -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 | ||
|
@@ -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' }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.