mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
ci: extract go-test-failure-report composite action (#25670)
The Go test jobs in `ci.yaml` each had ~30 lines of inline shell that
wrapped `gotestsum` with a PATH shim to capture JSON, then ran
`gotestsummary` and `upload-artifact` to publish a failure report. Three
jobs carried three near-identical copies.
This change replaces the three inline blocks with a single composite
action at `.github/actions/go-test-failure-report/` that runs the same
`gotestsummary` invocation, writes the same markdown to
`GITHUB_STEP_SUMMARY`, and uploads the same NDJSON artifact. The PATH
shim is gone; gotestsum's native `GOTESTSUM_JSONFILE` env variable is
used instead, plumbed through the `test-go-pg` composite.
`test-go-pg` gains three optional inputs:
- `gotestsum-json-file` — explicit JSON file path (or `default` for
`${RUNNER_TEMP}/go-test.json`)
- `run-regex` — passed to `go test -run`
- `test-shuffle` — passed to `go test -shuffle`
All three have safe defaults so existing callers are unaffected.
No observable change in CI behavior: the three existing test-go-pg jobs
continue to emit the same JSON, render the same failure summary, and
upload the same artifact.
Stacked under #25667, which uses the new composite and inputs to power a
new flake-detector workflow.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
name: "Go Test Failure Report"
|
||||
description: "Publish Go test failure summaries and upload failure artifacts"
|
||||
|
||||
inputs:
|
||||
json-file:
|
||||
description: "Path to the gotestsum JSON file. Use default for RUNNER_TEMP/go-test.json."
|
||||
required: false
|
||||
default: "default"
|
||||
failures-file:
|
||||
description: "Path to write newline-delimited failure details. Use default for RUNNER_TEMP/go-test-failures.ndjson."
|
||||
required: false
|
||||
default: "default"
|
||||
artifact-name:
|
||||
description: "Artifact name for uploaded failure details"
|
||||
required: true
|
||||
retention-days:
|
||||
description: "Artifact retention in days"
|
||||
required: false
|
||||
default: "7"
|
||||
max-output-bytes:
|
||||
description: "Maximum bytes to include in the markdown summary"
|
||||
required: false
|
||||
default: "16384"
|
||||
max-failures:
|
||||
description: "Maximum failures to include in the summary output"
|
||||
required: false
|
||||
default: "50"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Resolve Go test report paths
|
||||
id: paths
|
||||
shell: bash
|
||||
env:
|
||||
JSON_FILE: ${{ inputs.json-file }}
|
||||
FAILURES_FILE: ${{ inputs.failures-file }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
json_file="$JSON_FILE"
|
||||
if [[ "$json_file" == "default" ]]; then
|
||||
json_file="${RUNNER_TEMP}/go-test.json"
|
||||
fi
|
||||
failures_file="$FAILURES_FILE"
|
||||
if [[ "$failures_file" == "default" ]]; then
|
||||
failures_file="${RUNNER_TEMP}/go-test-failures.ndjson"
|
||||
fi
|
||||
{
|
||||
echo "json-file=${json_file}"
|
||||
echo "failures-file=${failures_file}"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Publish Go test failure summary
|
||||
shell: bash
|
||||
env:
|
||||
JSON_FILE: ${{ steps.paths.outputs.json-file }}
|
||||
FAILURES_FILE: ${{ steps.paths.outputs.failures-file }}
|
||||
MAX_OUTPUT_BYTES: ${{ inputs.max-output-bytes }}
|
||||
MAX_FAILURES: ${{ inputs.max-failures }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
go run ./scripts/gotestsummary \
|
||||
--jsonfile "${JSON_FILE}" \
|
||||
--markdown-out - \
|
||||
--failures-out "${FAILURES_FILE}" \
|
||||
--max-output-bytes "${MAX_OUTPUT_BYTES}" \
|
||||
--max-failures "${MAX_FAILURES}" \
|
||||
>> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
- name: Upload Go test failures
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: ${{ inputs.artifact-name }}
|
||||
path: ${{ steps.paths.outputs.failures-file }}
|
||||
retention-days: ${{ inputs.retention-days }}
|
||||
@@ -26,6 +26,18 @@ inputs:
|
||||
description: "Packages to test (default: ./...)"
|
||||
required: false
|
||||
default: "./..."
|
||||
run-regex:
|
||||
description: "Go test name regex passed via RUN"
|
||||
required: false
|
||||
default: ""
|
||||
test-shuffle:
|
||||
description: "Go test shuffle mode passed via TEST_SHUFFLE"
|
||||
required: false
|
||||
default: ""
|
||||
gotestsum-json-file:
|
||||
description: "Optional Linux path for gotestsum --jsonfile output. Use default for RUNNER_TEMP/go-test.json."
|
||||
required: false
|
||||
default: ""
|
||||
embedded-pg-path:
|
||||
description: "Path for embedded postgres data (Windows/macOS only)"
|
||||
required: false
|
||||
@@ -61,8 +73,11 @@ runs:
|
||||
TEST_NUM_PARALLEL_PACKAGES: ${{ inputs.test-parallelism-packages }}
|
||||
TEST_NUM_PARALLEL_TESTS: ${{ inputs.test-parallelism-tests }}
|
||||
TEST_COUNT: ${{ inputs.test-count }}
|
||||
RUN: ${{ inputs.run-regex }}
|
||||
TEST_SHUFFLE: ${{ inputs.test-shuffle }}
|
||||
TEST_PACKAGES: ${{ inputs.test-packages }}
|
||||
RACE_DETECTION: ${{ inputs.race-detection }}
|
||||
GOTESTSUM_JSONFILE_INPUT: ${{ inputs.gotestsum-json-file }}
|
||||
TS_DEBUG_DISCO: "true"
|
||||
TS_DEBUG_DERP: "true"
|
||||
LC_CTYPE: "en_US.UTF-8"
|
||||
@@ -70,6 +85,18 @@ runs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# gotestsum natively reads GOTESTSUM_JSONFILE; set it directly instead
|
||||
# of writing a PATH shim. "default" is the historical
|
||||
# ${RUNNER_TEMP}/go-test.json location consumed by
|
||||
# ./.github/actions/go-test-failure-report.
|
||||
if [[ -n "${GOTESTSUM_JSONFILE_INPUT}" ]]; then
|
||||
if [[ "${GOTESTSUM_JSONFILE_INPUT}" == "default" ]]; then
|
||||
export GOTESTSUM_JSONFILE="${RUNNER_TEMP}/go-test.json"
|
||||
else
|
||||
export GOTESTSUM_JSONFILE="${GOTESTSUM_JSONFILE_INPUT}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${RACE_DETECTION} == true ]]; then
|
||||
make test-race
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user