Skip to content

Commit 240b5ca

Browse files
committed
Pass file stem from ci.yml; allow build script to control output dir
1 parent 85f5544 commit 240b5ca

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,23 @@ jobs:
3636
with:
3737
go-version: ${{ matrix.go-version }}
3838

39-
- name: Create junit-xml directory
40-
run: mkdir junit-xml
41-
4239
- name: Check
4340
run: go run . check
4441
working-directory: ./internal/cmd/build
4542

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

5047
- name: Integration tests (without cache)
51-
run: go run . integration-test -dev-server -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-nocache
48+
run: go run . integration-test -dev-server -junit-file-stem ${{matrix.os}}-${{matrix.go-version}}-nocache
5249
working-directory: ./internal/cmd/build
5350
env:
5451
WORKFLOW_CACHE_SIZE: "0"
5552
TEMPORAL_COVERAGE_FILE: ${{ matrix.uploadCoverage && 'integ_test_zero_cache_cover.out' || '' }}
5653

5754
- name: Integration tests (with cache)
58-
run: go run . integration-test -dev-server -junitfile junit-xml/${{matrix.os}}-${{matrix.go-version}}-cache
55+
run: go run . integration-test -dev-server -junit-file-stem ${{matrix.os}}-${{matrix.go-version}}-cache
5956
working-directory: ./internal/cmd/build
6057
env:
6158
TEMPORAL_COVERAGE_FILE: ${{ matrix.uploadCoverage && 'integ_test_normal_cache_cover.out' || '' }}
@@ -78,7 +75,7 @@ jobs:
7875
if: always()
7976
with:
8077
name: junit-xml--${{github.run_id}}--${{github.run_attempt}}--${{matrix.os}}-${{matrix.go-version}}
81-
path: junit-xml
78+
path: .build/junit-xml
8279
retention-days: 14
8380

8481
- name: Docker compose - checkout

internal/cmd/build/main.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func main() {
5454
}
5555

5656
const coverageDir = ".build/coverage"
57+
const junitDir = ".build/junit-xml"
5758

5859
type builder struct {
5960
thisDir string
@@ -117,7 +118,7 @@ func (b *builder) integrationTest() error {
117118
runFlag := flagSet.String("run", "", "Passed to go test as -run")
118119
devServerFlag := flagSet.Bool("dev-server", false, "Use an embedded dev server")
119120
coverageFileFlag := flagSet.String("coverage-file", "", "If set, enables coverage output to this filename")
120-
junitFileFlag := flagSet.String("junitfile", "junit-xml", "If set, a path prefix to which junit-style xml files should be written")
121+
junitFileStem := flagSet.String("junit-file-stem", "", "If set, an identifier to be used to construct junit xml output file names")
121122
if err := flagSet.Parse(os.Args[2:]); err != nil {
122123
return fmt.Errorf("failed parsing flags: %w", err)
123124
}
@@ -138,6 +139,13 @@ func (b *builder) integrationTest() error {
138139
}
139140
}
140141

142+
// Create junit XML output dir if junit XML output requested
143+
if *junitFileStem != "" {
144+
if err := os.MkdirAll(filepath.Join(b.rootDir, junitDir), 0777); err != nil {
145+
return fmt.Errorf("failed creating junit xml dir: %w", err)
146+
}
147+
}
148+
141149
// Start dev server if wanted
142150
if *devServerFlag {
143151
devServer, err := testsuite.StartDevServer(context.Background(), testsuite.DevServerOptions{
@@ -178,10 +186,12 @@ func (b *builder) integrationTest() error {
178186
// Run integration test
179187
args := []string{
180188
gotestsum,
181-
"--junitfile", *junitFileFlag + "-integration-test.xml",
182-
"--",
183-
"-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m",
184189
}
190+
if *junitFileStem != "" {
191+
args = append(args, "--junitfile", filepath.Join(b.rootDir, junitDir, *junitFileStem+"-integration-test.xml"))
192+
}
193+
args = append(args, "--", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "10m")
194+
185195
if *runFlag != "" {
186196
args = append(args, "-run", *runFlag)
187197
}
@@ -244,7 +254,7 @@ func (b *builder) unitTest() error {
244254
flagSet := flag.NewFlagSet("unit-test", flag.ContinueOnError)
245255
runFlag := flagSet.String("run", "", "Passed to go test as -run")
246256
coverageFlag := flagSet.Bool("coverage", false, "If set, enables coverage output")
247-
junitFileFlag := flagSet.String("junitfile", "junit-xml", "If set, a path prefix to which junit-style xml files should be written")
257+
junitFileStem := flagSet.String("junit-file-stem", "", "If set, an identifier to be used to construct junit xml output file names")
248258
if err := flagSet.Parse(os.Args[2:]); err != nil {
249259
return fmt.Errorf("failed parsing flags: %w", err)
250260
}
@@ -278,16 +288,24 @@ func (b *builder) unitTest() error {
278288
}
279289
}
280290

291+
// Create junit XML output dir if junit XML output requested
292+
if *junitFileStem != "" {
293+
if err := os.MkdirAll(filepath.Join(b.rootDir, junitDir), 0777); err != nil {
294+
return fmt.Errorf("failed creating junit xml dir: %w", err)
295+
}
296+
}
297+
281298
// Run unit test for each dir
282299
log.Printf("Running unit tests in dirs: %v", testDirs)
283300
for _, testDir := range testDirs {
284301
// Run unit test
285302
args := []string{
286303
gotestsum,
287-
"--junitfile", *junitFileFlag + strings.ReplaceAll(testDir, "/", "-") + "unit-test.xml",
288-
"--",
289-
"-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m",
290304
}
305+
if *junitFileStem != "" {
306+
args = append(args, "--junitfile", filepath.Join(b.rootDir, junitDir, *junitFileStem+"-"+strings.ReplaceAll(testDir, "/", "-")+"-unit-test.xml"))
307+
}
308+
args = append(args, "--", "-tags", "protolegacy", "-count", "1", "-race", "-v", "-timeout", "15m")
291309
if *runFlag != "" {
292310
args = append(args, "-run", *runFlag)
293311
}

0 commit comments

Comments
 (0)