Skip to content

Commit

Permalink
Dump junit xml
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Sep 12, 2024
1 parent 592ae12 commit 64e0a30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,29 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: Install gotestsum
run: go install gotest.tools/gotestsum@latest

- name: Create junit-xml directory
run: mkdir junit-xml

- name: Check
run: go run . check
working-directory: ./internal/cmd/build

- name: Unit test
run: go run . unit-test -coverage=${{ matrix.uploadCoverage && 'true' || 'false' }}
run: go run . unit-test -coverage=${{ matrix.uploadCoverage && 'true' || 'false' }} -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}
working-directory: ./internal/cmd/build

- name: Integration tests (without cache)
run: go run . integration-test -dev-server
run: go run . integration-test -dev-server -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-nocache
working-directory: ./internal/cmd/build
env:
WORKFLOW_CACHE_SIZE: "0"
TEMPORAL_COVERAGE_FILE: ${{ matrix.uploadCoverage && 'integ_test_zero_cache_cover.out' || '' }}

- name: Integration tests (with cache)
run: go run . integration-test -dev-server
run: go run . integration-test -dev-server -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-cache
working-directory: ./internal/cmd/build
env:
TEMPORAL_COVERAGE_FILE: ${{ matrix.uploadCoverage && 'integ_test_normal_cache_cover.out' || '' }}
Expand Down
22 changes: 19 additions & 3 deletions internal/cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ func (b *builder) integrationTest() error {
runFlag := flagSet.String("run", "", "Passed to go test as -run")
devServerFlag := flagSet.Bool("dev-server", false, "Use an embedded dev server")
coverageFileFlag := flagSet.String("coverage-file", "", "If set, enables coverage output to this filename")
junitFileFlag := flagSet.String("junitfile", "", "If set, a path prefix to which junit-style xml files should be written")
if err := flagSet.Parse(os.Args[2:]); err != nil {
return fmt.Errorf("failed parsing flags: %w", err)
}

gotestsum, err := b.getInstalledTool("gotest.tools/gotestsum")
if err != nil {
return fmt.Errorf("failed getting gotestsum: %w", err)
}
// Also accept coverage file as env var
if env := strings.TrimSpace(os.Getenv("TEMPORAL_COVERAGE_FILE")); *coverageFileFlag == "" && env != "" {
*coverageFileFlag = env
Expand Down Expand Up @@ -171,7 +176,10 @@ func (b *builder) integrationTest() error {
}

// Run integration test
args := []string{"go", "test", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m"}
args := []string{gotestsum, "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m"}
if *junitFileFlag != "" {
args = append(args, "--junitfile", *junitFileFlag+"-integration-test.xml")
}
if *runFlag != "" {
args = append(args, "-run", *runFlag)
}
Expand Down Expand Up @@ -234,14 +242,19 @@ func (b *builder) unitTest() error {
flagSet := flag.NewFlagSet("unit-test", flag.ContinueOnError)
runFlag := flagSet.String("run", "", "Passed to go test as -run")
coverageFlag := flagSet.Bool("coverage", false, "If set, enables coverage output")
junitFileFlag := flagSet.String("junitfile", "", "If set, a path prefix to which junit-style xml files should be written")
if err := flagSet.Parse(os.Args[2:]); err != nil {
return fmt.Errorf("failed parsing flags: %w", err)
}

gotestsum, err := b.getInstalledTool("gotest.tools/gotestsum")
if err != nil {
return fmt.Errorf("failed getting gotestsum: %w", err)
}
// Find every non ./test-prefixed package that has a test file
testDirMap := map[string]struct{}{}
var testDirs []string
err := fs.WalkDir(os.DirFS(b.rootDir), ".", func(p string, d fs.DirEntry, err error) error {
err = fs.WalkDir(os.DirFS(b.rootDir), ".", func(p string, d fs.DirEntry, err error) error {
if !strings.HasPrefix(p, "test") && strings.HasSuffix(p, "_test.go") {
dir := path.Dir(p)
if _, ok := testDirMap[dir]; !ok {
Expand All @@ -267,7 +280,10 @@ func (b *builder) unitTest() error {
log.Printf("Running unit tests in dirs: %v", testDirs)
for _, testDir := range testDirs {
// Run unit test
args := []string{"go", "test", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m"}
args := []string{gotestsum, "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m"}
if *junitFileFlag != "" {
args = append(args, "--junitfile", *junitFileFlag+strings.ReplaceAll(testDir, "/", "-")+"unit-test.xml")
}
if *runFlag != "" {
args = append(args, "-run", *runFlag)
}
Expand Down

0 comments on commit 64e0a30

Please sign in to comment.