Run relevant tests #15
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
| 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" | |
| - name: No affected packages — skip tests | |
| if: steps.affected.outputs.has_changes != 'true' | |
| run: echo "No Go packages affected by this PR; skipping tests." | |
| e2e-affected: | |
| needs: test-affected | |
| if: github.event.pull_request.draft == false | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| suite: [unit, preflight, support-bundle] | |
| 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 }}" | |
| - name: Compute affected packages | |
| id: affected | |
| run: | | |
| set -euo pipefail | |
| echo "Base: ${{ steps.pr-info.outputs.BASE_REF }}" | |
| go run ./scripts/affected-packages.go -base "${{ steps.pr-info.outputs.BASE_REF }}" > /tmp/affected.txt | |
| 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: Run unit tests (filtered) | |
| if: matrix.suite == 'unit' && steps.affected.outputs.has_changes == 'true' | |
| run: | | |
| set -euo pipefail | |
| if grep -qx "./..." /tmp/affected.txt; then | |
| echo "Module files changed; running all unit tests" | |
| make test | |
| else | |
| echo "Running unit tests for affected packages" | |
| pkgs=$(tr '\n' ' ' < /tmp/affected.txt) | |
| PACKAGES="$pkgs" make test-packages | |
| fi | |
| - name: Run e2e (filtered) - ${{ matrix.suite }} | |
| if: matrix.suite != 'unit' && steps.affected_e2e.outputs.has_changes == 'true' | |
| run: | | |
| set -euo pipefail | |
| docker rm -f kind-cluster-control-plane 2>/dev/null || true | |
| if [ "${{ matrix.suite }}" = "preflight" ]; then | |
| file=/tmp/preflight-tests.txt | |
| path=./test/e2e/preflight | |
| else | |
| file=/tmp/support-tests.txt | |
| path=./test/e2e/support-bundle | |
| fi | |
| if [ -s "$file" ]; then | |
| regex="$(grep -v '^$' "$file" | tr '\n' '|' | sed 's/|$//')" | |
| if [ -n "$regex" ]; then | |
| if [ "${{ matrix.suite }}" = "preflight" ]; then | |
| E2EPATHS="$path" RUN="^(${regex})$" make preflight-e2e-go-test | |
| else | |
| E2EPATHS="$path" RUN="^(${regex})$" make support-bundle-e2e-go-test | |
| fi | |
| else | |
| echo "No valid ${{ matrix.suite }} tests matched after filtering" | |
| fi | |
| else | |
| echo "No ${{ matrix.suite }} e2e changes" | |
| fi | |