Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Setup Go Environment'
description: 'Setup Go with caching and common environment variables'
inputs:
go-version-file:
description: 'Path to go.mod file'
required: false
default: 'go.mod'
outputs:
go-version:
description: 'The Go version that was installed'
value: ${{ steps.setup-go.outputs.go-version }}
cache-hit:
description: 'Whether the Go cache was hit'
value: ${{ steps.setup-go.outputs.cache-hit }}
runs:
using: 'composite'
steps:
- name: Setup Go
id: setup-go
uses: actions/setup-go@v5
Copy link

Choose a reason for hiding this comment

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

Bug: Go Version Downgrade Causes Compatibility Issues

The composite action uses actions/setup-go@v5, which is a downgrade from v6 used in previous workflows. This could introduce compatibility issues or miss features and bug fixes from the newer version.

Fix in Cursor Fix in Web

with:
go-version-file: ${{ inputs.go-version-file }}
cache: true

- name: Set Go environment variables
shell: bash
run: |
echo "GOMAXPROCS=2" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Print Go environment
shell: bash
run: |
echo "Go version: $(go version)"
echo "GOOS: $(go env GOOS)"
echo "GOARCH: $(go env GOARCH)"
echo "Cache directory: $(go env GOCACHE)"
echo "Module cache: $(go env GOMODCACHE)"
218 changes: 117 additions & 101 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,145 +2,161 @@ name: build-test

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
branches:
- v1beta3
types: [opened, reopened, synchronize, ready_for_review]
branches: [v1beta3]
push:
branches:
- "v1beta3"
branches: [v1beta3]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
fail_if_pull_request_is_draft:
if: github.event.pull_request.draft == true
# Detect changes to optimize test execution
changes:
runs-on: ubuntu-latest
outputs:
go-files: ${{ steps.filter.outputs.go-files }}
preflight: ${{ steps.filter.outputs.preflight }}
support-bundle: ${{ steps.filter.outputs.support-bundle }}
examples: ${{ steps.filter.outputs.examples }}
steps:
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
run: exit 1
- uses: actions/checkout@v5
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
go-files:
- '**/*.go'
- 'go.{mod,sum}'
- 'Makefile'
preflight:
- 'cmd/preflight/**'
- 'pkg/preflight/**'
support-bundle:
- 'cmd/troubleshoot/**'
- 'pkg/supportbundle/**'
examples:
- 'examples/**'
- 'test/run-examples.sh'

test-integration:
# Validation jobs
validate:
if: needs.changes.outputs.go-files == 'true'
needs: changes
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- uses: replicatedhq/action-k3s@main
id: k3s
with:
version: v1.31.2-k3s1
# test-integration includes unit tests
- run: make test-integration
- uses: ./.github/actions/setup-go

- name: Check go mod tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum || {
echo "::error::Please run 'go mod tidy' and commit changes"
exit 1
}

compile-preflight:
- name: Format and vet
run: |
make fmt
git diff --exit-code || {
echo "::error::Please run 'make fmt' and commit changes"
exit 1
}
make vet

# Unit and integration tests
test:
if: needs.changes.outputs.go-files == 'true'
needs: [changes, validate]
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- run: make preflight
- uses: actions/upload-artifact@v4
- uses: ./.github/actions/setup-go

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

- name: Run tests
run: make test-integration

validate-preflight-e2e:
# Build binaries
build:
if: needs.changes.outputs.go-files == 'true'
needs: [changes, validate]
runs-on: ubuntu-latest
needs: compile-preflight
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- uses: replicatedhq/action-k3s@main
id: k3s
with:
version: v1.31.2-k3s1
- name: Download preflight binary
uses: actions/download-artifact@v5
- uses: ./.github/actions/setup-go
- run: make build
- uses: actions/upload-artifact@v4
with:
name: preflight
name: binaries
path: bin/
- run: chmod +x bin/preflight
- run: make preflight-e2e-test
retention-days: 1

run-examples:
# Examples validation
examples:
if: needs.changes.outputs.examples == 'true' || needs.changes.outputs.go-files == 'true'
needs: changes
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- run: make run-examples

compile-supportbundle:
# E2E tests
e2e:
if: needs.changes.outputs.go-files == 'true' || github.event_name == 'push'
needs: [changes, build]
Copy link

Choose a reason for hiding this comment

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

Bug: E2E Job Runs Without Build Job

The e2e job's if condition allows it to run on push events even when no Go files have changed. However, it depends on the build job, which is skipped in this scenario because its if condition requires Go file changes. This leads to the e2e job failing when it attempts to download the binaries artifact that was never uploaded.

Fix in Cursor Fix in Web

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
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- run: make support-bundle
- uses: actions/upload-artifact@v4
with:
name: support-bundle
path: bin/support-bundle

validate-supportbundle-e2e:
runs-on: ubuntu-latest
needs: compile-supportbundle
steps:
- uses: actions/checkout@v5
- uses: replicatedhq/action-k3s@main
id: k3s
- name: Setup K3s
if: matrix.needs-k3s
uses: replicatedhq/action-k3s@main
with:
version: v1.31.2-k3s1
- name: Download support bundle binary
uses: actions/download-artifact@v5
with:
name: support-bundle
path: bin/
- run: chmod +x bin/support-bundle
- run: make support-bundle-e2e-test

# 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:
- uses: actions/checkout@v5
- name: Download support bundle binary
uses: actions/download-artifact@v5
with:
name: support-bundle
path: bin/
- run: chmod +x bin/support-bundle
- name: Download preflight binary
uses: actions/download-artifact@v5

- uses: actions/download-artifact@v4
with:
name: preflight
name: binaries
path: bin/
- run: chmod +x bin/preflight
- run: make support-bundle-e2e-go-test

# Summary job - all tests must pass for this to succeed
validate-success:
runs-on: ubuntu-latest
needs:
- tidy-check
- test-integration
- run-examples
- validate-preflight-e2e
- validate-supportbundle-e2e
- validate-supportbundle-e2e-go
- run: chmod +x bin/*
- run: make ${{ matrix.target }}

# Success summary
success:
if: always()
needs: [validate, test, build, examples, e2e]
runs-on: ubuntu-latest
steps:
# Check if all required jobs succeeded
- name: fail if any required job failed
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
# Success message
- name: All tests passed
run: echo "All build and test jobs completed successfully"
- name: Check results
run: |
if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "::error::Some jobs failed or were cancelled"
exit 1
fi
echo "All tests passed!"