|
| 1 | +# Go Test Action |
| 2 | + |
| 3 | +A GitHub Composite Action that runs Go tests with race detection, coverage reporting, and JUnit XML output via `gotestsum`. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```yaml |
| 8 | +steps: |
| 9 | + - uses: actions/checkout@v4 |
| 10 | + - name: Go Test |
| 11 | + uses: NVIDIA/dsx-github-actions/.github/actions/go-test@main |
| 12 | +``` |
| 13 | +
|
| 14 | +### With custom packages and flags |
| 15 | +
|
| 16 | +```yaml |
| 17 | +steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Go Test |
| 20 | + uses: NVIDIA/dsx-github-actions/.github/actions/go-test@main |
| 21 | + with: |
| 22 | + packages: './pkg/...' |
| 23 | + test-flags: '-v -count=1 -timeout=10m' |
| 24 | + go-flags: '-mod=vendor' |
| 25 | + artifact-name: 'test-results-${{ matrix.go-version }}' |
| 26 | +``` |
| 27 | +
|
| 28 | +## Inputs |
| 29 | +
|
| 30 | +| Input | Description | Required | Default | |
| 31 | +| :--- | :--- | :--- | :--- | |
| 32 | +| `go-version` | Go version to use (e.g., `1.25.5`). If empty, uses `go.mod`. | `false` | `''` | |
| 33 | +| `go-version-file` | Path to `go.mod` for version detection. | `false` | `go.mod` | |
| 34 | +| `working-directory` | Working directory for running tests. | `false` | `.` | |
| 35 | +| `packages` | Go packages to test. | `false` | `./...` | |
| 36 | +| `race` | Enable race detector. | `false` | `true` | |
| 37 | +| `coverage` | Enable coverage reporting. | `false` | `true` | |
| 38 | +| `coverage-file` | Coverage output file name. | `false` | `coverage.out` | |
| 39 | +| `junit` | Generate JUnit XML report via `gotestsum`. | `false` | `true` | |
| 40 | +| `junit-file` | JUnit XML output file name. | `false` | `junit-report.xml` | |
| 41 | +| `test-flags` | Additional flags passed to `go test`. | `false` | `-v -count=1` | |
| 42 | +| `go-flags` | `GOFLAGS` environment variable (e.g., `-mod=vendor`). | `false` | `''` | |
| 43 | +| `gotestsum-version` | `gotestsum` version to install. | `false` | `v1.12.0` | |
| 44 | +| `upload-artifacts` | Upload coverage and JUnit reports as workflow artifacts. | `false` | `true` | |
| 45 | +| `artifact-name` | Name for uploaded artifact (override to avoid collisions in matrix builds). | `false` | `go-test-results` | |
| 46 | + |
| 47 | +## Outputs |
| 48 | + |
| 49 | +| Output | Description | |
| 50 | +| :--- | :--- | |
| 51 | +| `coverage-file` | Path to coverage output file. | |
| 52 | +| `junit-file` | Path to JUnit XML report. | |
| 53 | + |
| 54 | +## Behavior |
| 55 | + |
| 56 | +1. **Set up Go** using `actions/setup-go` with caching enabled. |
| 57 | +2. **Install gotestsum** (pinned version) if JUnit output is enabled. |
| 58 | +3. **Run tests** with configurable race detection, coverage, and JUnit output. |
| 59 | +4. **Display coverage summary** showing the total coverage percentage. |
| 60 | +5. **Upload artifacts** (coverage and JUnit reports) with 7-day retention. |
| 61 | + |
| 62 | +## Notes |
| 63 | + |
| 64 | +- When using matrix builds, set `artifact-name` to a unique value per matrix cell to avoid upload collisions (e.g., `artifact-name: 'test-results-${{ matrix.go-version }}'`). |
| 65 | +- All shell inputs are routed through environment variables to prevent expression injection. |
0 commit comments