Skip to content

Commit cd237db

Browse files
skipihamir-suspect
andauthored
Pass additional environment information to tests, compress reports (#58)
Co-authored-by: Amir Hasanbasic <[email protected]>
1 parent 3540ff8 commit cd237db

31 files changed

+4191
-1344
lines changed

.semaphore/integration.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ blocks:
2828
- phpunit
2929
- embedded
3030
commands:
31-
- test-results publish priv/parsers/$PARSER/in.xml -p $PARSER
31+
- test-results publish --no-compress priv/parsers/$PARSER/in.xml -p $PARSER
3232
- artifact pull job test-results/junit.json -d /tmp/junit.json
33-
- cat <<< $(jq --sort-keys . priv/parsers/$PARSER/out.json) > priv/parsers/$PARSER/out.json
34-
- cat <<< $(jq --sort-keys . /tmp/junit.json) > /tmp/junit.json
33+
- cat <<< $(jq 'walk(if type == "object" then del(.type, .semaphoreEnv) else . end)' --sort-keys . priv/parsers/$PARSER/out.json) > priv/parsers/$PARSER/out.json
34+
- cat <<< $(jq 'walk(if type == "object" then del(.type, .semaphoreEnv) else . end)' --sort-keys . /tmp/junit.json) > /tmp/junit.json
3535
- diff priv/parsers/$PARSER/out.json /tmp/junit.json
3636
- name: Merging - directory as input
3737
commands:
38-
- test-results publish priv/merging
38+
- test-results publish --no-compress priv/merging
3939
- artifact pull job test-results/junit.json -d /tmp/junit.json
40-
- cat <<< $(jq --sort-keys . priv/merging/out.json) > priv/merging/out.json
41-
- cat <<< $(jq --sort-keys . /tmp/junit.json) > /tmp/junit.json
40+
- cat <<< $(jq 'walk(if type == "object" then del(.type, .semaphoreEnv) else . end)' --sort-keys . priv/merging/out.json) > priv/merging/out.json
41+
- cat <<< $(jq 'walk(if type == "object" then del(.type, .semaphoreEnv) else . end)' --sort-keys . /tmp/junit.json) > /tmp/junit.json
4242
- diff priv/merging/out.json /tmp/junit.json
4343
- name: Integration tests - generate pipeline report
4444
dependencies:
@@ -47,15 +47,15 @@ blocks:
4747
jobs:
4848
- name: generate pipeline report
4949
commands:
50-
- test-results gen-pipeline-report
50+
- test-results gen-pipeline-report --no-compress
5151
- name: Integration tests - workflow level
5252
dependencies:
5353
- Integration tests - generate pipeline report
5454
task:
5555
jobs:
5656
- name: Generate pipeline summary
5757
commands:
58-
- 'artifact pull workflow test-results/${SEMAPHORE_PIPELINE_ID}-summary.json -d /tmp/summary.json'
58+
- "artifact pull workflow test-results/${SEMAPHORE_PIPELINE_ID}-summary.json -d /tmp/summary.json"
5959
- cat <<< $(jq --sort-keys . priv/workflow/summary-out.json) > priv/workflow/summary-out.json
6060
- cat <<< $(jq --sort-keys . /tmp/summary.json) > /tmp/summary.json
6161
- diff /tmp/summary.json priv/workflow/summary-out.json

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ run:
44
go run main.go $(arg)
55

66
regen:
7-
go run main.go compile priv/parsers/generic/in.xml priv/parsers/generic/out.json
8-
go run main.go compile priv/parsers/rspec/in.xml priv/parsers/rspec/out.json
9-
go run main.go compile priv/parsers/exunit/in.xml priv/parsers/exunit/out.json
10-
go run main.go compile priv/parsers/golang/in.xml priv/parsers/golang/out.json
11-
go run main.go compile -p phpunit priv/parsers/phpunit/in.xml priv/parsers/phpunit/out.json
12-
go run main.go compile -p embedded priv/parsers/embedded/in.xml priv/parsers/embedded/out.json
13-
go run main.go compile priv/merging priv/merging/out.json
7+
go run main.go compile --no-compress priv/parsers/generic/in.xml priv/parsers/generic/out.json
8+
go run main.go compile --no-compress priv/parsers/rspec/in.xml priv/parsers/rspec/out.json
9+
go run main.go compile --no-compress priv/parsers/exunit/in.xml priv/parsers/exunit/out.json
10+
go run main.go compile --no-compress priv/parsers/golang/in.xml priv/parsers/golang/out.json
11+
go run main.go compile --no-compress -p phpunit priv/parsers/phpunit/in.xml priv/parsers/phpunit/out.json
12+
go run main.go compile --no-compress -p embedded priv/parsers/embedded/in.xml priv/parsers/embedded/out.json
13+
go run main.go compile --no-compress priv/merging priv/merging/out.json
14+
1415
test:
1516
gotestsum ./...
1617

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ The main purpose of the CLI is to:
1313
- compile and publish JUnit XML files into a JSON report
1414
- merge multiple JSON reports into a single summary report
1515

16+
> [!NOTE]
17+
>
18+
> Starting from version `0.7.0`, test reports are compressed using gzip to optimize storage and handling. To maintain backward compatibility with existing systems and processes, the compressed files will continue to use the `.json` file extension. This approach ensures seamless integration with tools and workflows that expect files in this format.
19+
>
20+
> However, please be aware that while these files retain the `.json` extension, they are in a compressed format and will need to be decompressed using gzip-compatible tools before they can be read as standard JSON.
21+
>
22+
> For users who prefer to work with uncompressed reports or for systems that require non-compressed files, we've introduced a `--no-compress` option. This can be used to generate and upload test reports in the traditional, uncompressed JSON format.
23+
1624
## Compiling and publishing JUnit XML files
1725

1826
Given your JUnit XML report is named `results.xml` you can run the following command to generate a report:

cmd/combine.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ var combineCmd = &cobra.Command{
3838
return err
3939
}
4040

41+
skipCompression, err := cmd.Flags().GetBool("no-compress")
42+
if err != nil {
43+
return err
44+
}
45+
4146
paths, err := cli.LoadFiles(inputs, ".json")
4247
if err != nil {
4348
return err
@@ -71,7 +76,7 @@ var combineCmd = &cobra.Command{
7176
return err
7277
}
7378

74-
_, err = cli.WriteToFilePath(jsonData, output)
79+
_, err = cli.WriteToFilePath(jsonData, output, !skipCompression)
7580
if err != nil {
7681
return err
7782
}

cmd/compile.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ var compileCmd = &cobra.Command{
4040
output := args[len(args)-1]
4141

4242
err := cli.SetLogLevel(cmd)
43+
if err != nil {
44+
return err
45+
}
4346

47+
skipCompression, err := cmd.Flags().GetBool("no-compress")
4448
if err != nil {
4549
return err
4650
}
@@ -79,7 +83,7 @@ var compileCmd = &cobra.Command{
7983
return err
8084
}
8185

82-
_, err = cli.WriteToFilePath(jsonData, tmpFile.Name())
86+
_, err = cli.WriteToFilePath(jsonData, tmpFile.Name(), !skipCompression)
8387
if err != nil {
8488
return err
8589
}
@@ -96,7 +100,7 @@ var compileCmd = &cobra.Command{
96100
return err
97101
}
98102

99-
_, err = cli.WriteToFilePath(jsonData, output)
103+
_, err = cli.WriteToFilePath(jsonData, output, !skipCompression)
100104
if err != nil {
101105
return err
102106
}

cmd/gen-pipeline-report.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ var genPipelineReportCmd = &cobra.Command{
4242
if err != nil {
4343
return err
4444
}
45+
skipCompression, err := cmd.Flags().GetBool("no-compress")
46+
if err != nil {
47+
return err
48+
}
4549

4650
var dir string
4751

@@ -78,7 +82,7 @@ var genPipelineReportCmd = &cobra.Command{
7882
return err
7983
}
8084

81-
fileName, err := cli.WriteToTmpFile(jsonData)
85+
fileName, err := cli.WriteToTmpFile(jsonData, !skipCompression)
8286
if err != nil {
8387
return err
8488
}
@@ -94,6 +98,10 @@ var genPipelineReportCmd = &cobra.Command{
9498
}
9599

96100
func pushSummaries(testResult []parser.TestResults, level, path string, cmd *cobra.Command) error {
101+
skipCompression, err := cmd.Flags().GetBool("no-compress")
102+
if err != nil {
103+
return err
104+
}
97105
if len(testResult) == 0 {
98106
logger.Info("no test results to process")
99107
return nil
@@ -111,7 +119,7 @@ func pushSummaries(testResult []parser.TestResults, level, path string, cmd *cob
111119
return err
112120
}
113121

114-
summaryFileName, err := cli.WriteToTmpFile(jsonSummary)
122+
summaryFileName, err := cli.WriteToTmpFile(jsonSummary, !skipCompression)
115123
if err != nil {
116124
return err
117125
}

cmd/publish.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ var publishCmd = &cobra.Command{
4444
return err
4545
}
4646

47+
skipCompression, err := cmd.Flags().GetBool("no-compress")
48+
if err != nil {
49+
return err
50+
}
51+
4752
paths, err := cli.LoadFiles(inputs, ".xml")
4853
if err != nil {
4954
return err
@@ -78,7 +83,7 @@ var publishCmd = &cobra.Command{
7883
return err
7984
}
8085

81-
_, err = cli.WriteToFile(jsonData, tmpFile)
86+
_, err = cli.WriteToFile(jsonData, tmpFile, !skipCompression)
8287
if err != nil {
8388
return err
8489
}
@@ -100,7 +105,7 @@ var publishCmd = &cobra.Command{
100105
return err
101106
}
102107

103-
fileName, err := cli.WriteToTmpFile(jsonData)
108+
fileName, err := cli.WriteToTmpFile(jsonData, !skipCompression)
104109
if err != nil {
105110
return err
106111
}

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
var cfgFile string
3232

33-
var versionString = "0.6.8"
33+
var versionString = "0.7.0"
3434

3535
// rootCmd represents the base command when called without any subcommands
3636
var rootCmd = &cobra.Command{
@@ -59,6 +59,7 @@ func init() {
5959
rootCmd.PersistentFlags().StringP("name", "N", "", "name of the suite")
6060
rootCmd.PersistentFlags().StringP("suite-prefix", "S", "", "prefix for each suite")
6161
rootCmd.PersistentFlags().StringP("parser", "p", "auto", "override parser to be used")
62+
rootCmd.PersistentFlags().Bool("no-compress", false, "skip gzip compression for the output")
6263

6364
// Cobra also supports local flags, which will only run
6465
// when this action is called directly.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/semaphoreci/test-results
33
go 1.20
44

55
require (
6+
github.com/google/go-cmp v0.5.7
67
github.com/google/uuid v1.3.0
78
github.com/mitchellh/go-homedir v1.1.0
89
github.com/sirupsen/logrus v1.8.1

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
9797
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9898
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9999
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
100+
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
101+
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
100102
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
101103
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
102104
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -375,6 +377,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
375377
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
376378
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
377379
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
380+
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U=
378381
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
379382
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
380383
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

0 commit comments

Comments
 (0)