Skip to content

Commit

Permalink
Pass file stem from ci.yml; allow build script to control output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Sep 12, 2024
1 parent 85f5544 commit 240b5ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,23 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- 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' }} -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}
run: go run . unit-test -coverage=${{ matrix.uploadCoverage && 'true' || 'false' }} -junit-file-stem ${{matrix.os}}-${{matrix.go-version}}
working-directory: ./internal/cmd/build

- name: Integration tests (without cache)
run: go run . integration-test -dev-server -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-nocache
run: go run . integration-test -dev-server -junit-file-stem ${{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 -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-cache
run: go run . integration-test -dev-server -junit-file-stem ${{matrix.os}}-${{matrix.go-version}}-cache
working-directory: ./internal/cmd/build
env:
TEMPORAL_COVERAGE_FILE: ${{ matrix.uploadCoverage && 'integ_test_normal_cache_cover.out' || '' }}
Expand All @@ -78,7 +75,7 @@ jobs:
if: always()
with:
name: junit-xml--${{github.run_id}}--${{github.run_attempt}}--${{matrix.os}}-${{matrix.go-version}}
path: junit-xml
path: .build/junit-xml
retention-days: 14

- name: Docker compose - checkout
Expand Down
34 changes: 26 additions & 8 deletions internal/cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func main() {
}

const coverageDir = ".build/coverage"
const junitDir = ".build/junit-xml"

type builder struct {
thisDir string
Expand Down Expand Up @@ -117,7 +118,7 @@ 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", "junit-xml", "If set, a path prefix to which junit-style xml files should be written")
junitFileStem := flagSet.String("junit-file-stem", "", "If set, an identifier to be used to construct junit xml output file names")
if err := flagSet.Parse(os.Args[2:]); err != nil {
return fmt.Errorf("failed parsing flags: %w", err)
}
Expand All @@ -138,6 +139,13 @@ func (b *builder) integrationTest() error {
}
}

// Create junit XML output dir if junit XML output requested
if *junitFileStem != "" {
if err := os.MkdirAll(filepath.Join(b.rootDir, junitDir), 0777); err != nil {
return fmt.Errorf("failed creating junit xml dir: %w", err)
}
}

// Start dev server if wanted
if *devServerFlag {
devServer, err := testsuite.StartDevServer(context.Background(), testsuite.DevServerOptions{
Expand Down Expand Up @@ -178,10 +186,12 @@ func (b *builder) integrationTest() error {
// Run integration test
args := []string{
gotestsum,
"--junitfile", *junitFileFlag + "-integration-test.xml",
"--",
"-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m",
}
if *junitFileStem != "" {
args = append(args, "--junitfile", filepath.Join(b.rootDir, junitDir, *junitFileStem+"-integration-test.xml"))
}
args = append(args, "--", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m")

if *runFlag != "" {
args = append(args, "-run", *runFlag)
}
Expand Down Expand Up @@ -244,7 +254,7 @@ 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", "junit-xml", "If set, a path prefix to which junit-style xml files should be written")
junitFileStem := flagSet.String("junit-file-stem", "", "If set, an identifier to be used to construct junit xml output file names")
if err := flagSet.Parse(os.Args[2:]); err != nil {
return fmt.Errorf("failed parsing flags: %w", err)
}
Expand Down Expand Up @@ -278,16 +288,24 @@ func (b *builder) unitTest() error {
}
}

// Create junit XML output dir if junit XML output requested
if *junitFileStem != "" {
if err := os.MkdirAll(filepath.Join(b.rootDir, junitDir), 0777); err != nil {
return fmt.Errorf("failed creating junit xml dir: %w", err)
}
}

// Run unit test for each dir
log.Printf("Running unit tests in dirs: %v", testDirs)
for _, testDir := range testDirs {
// Run unit test
args := []string{
gotestsum,
"--junitfile", *junitFileFlag + strings.ReplaceAll(testDir, "/", "-") + "unit-test.xml",
"--",
"-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m",
}
if *junitFileStem != "" {
args = append(args, "--junitfile", filepath.Join(b.rootDir, junitDir, *junitFileStem+"-"+strings.ReplaceAll(testDir, "/", "-")+"-unit-test.xml"))
}
args = append(args, "--", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m")
if *runFlag != "" {
args = append(args, "-run", *runFlag)
}
Expand Down

0 comments on commit 240b5ca

Please sign in to comment.