@@ -52,12 +52,9 @@ pipeline {
5252 }
5353 stage(' Go Tools' ) {
5454 steps {
55- // unhandled error checker
56- sh ' go install github.com/kisielk/errcheck@latest'
5755 // goveralls is used to send coverprofiles to coveralls.io
5856 sh ' go install github.com/mattn/goveralls@latest'
59- // Jenkins test reporting tools
60- sh ' go install github.com/tebeka/go2xunit@latest'
57+ sh ' go install gotest.tools/gotestsum@latest'
6158 }
6259 }
6360 }
@@ -90,89 +87,86 @@ pipeline {
9087 stage(' CE' ) {
9188 when { branch ' main' }
9289 steps {
93- // Travis-related variables are required as coveralls.io only officially supports a certain set of CI tools.
94- withEnv([" PATH+GO=${ env.GOTOOLS} /bin" , " TRAVIS_BRANCH=${ env.BRANCH} " , " TRAVIS_PULL_REQUEST=${ env.CHANGE_ID} " , " TRAVIS_JOB_ID=${ env.BUILD_NUMBER} " ]) {
95- githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ce-unit-tests' , description : ' CE Unit Tests Running' , status : ' PENDING' )
96-
97- // Build CE coverprofiles
98- sh ' 2>&1 go test -shuffle=on -timeout=20m -coverpkg=./... -coverprofile=cover_ce.out -race -count=1 -v ./... > verbose_ce.out.raw || true'
99-
100- // Print total coverage stats
101- sh ' go tool cover -func=cover_ce.out | awk \' END{print "Total SG CE Coverage: " $3}\' '
102-
103- sh ' mkdir -p reports'
104-
105- // strip non-printable characters from the raw verbose test output
106- sh ' LC_CTYPE=C tr -dc [:print:][:space:] < verbose_ce.out.raw > verbose_ce.out'
107-
108- // Grab test fail/total counts so we can print them later
109- sh " grep '\\ -\\ -\\ - PASS: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-pass.count"
110- sh " grep '\\ -\\ -\\ - FAIL: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-fail.count"
111- sh " grep '\\ -\\ -\\ - SKIP: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-skip.count"
112- sh " grep '=== RUN' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-total.count"
113- script {
90+ script {
91+ // Travis-related variables are required as coveralls.io only officially supports a certain set of CI tools.
92+ withEnv([" PATH+GO=${ env.GOTOOLS} /bin" , " TRAVIS_BRANCH=${ env.BRANCH} " , " TRAVIS_PULL_REQUEST=${ env.CHANGE_ID} " , " TRAVIS_JOB_ID=${ env.BUILD_NUMBER} " ]) {
93+ githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ce-unit-tests' , description : ' CE Unit Tests Running' , status : ' PENDING' )
94+
95+ // --junitfile-project-name is used so that Jenkins doesn't collapse CE and EE results together.
96+ def testExitCode = sh(
97+ script : ' gotestsum --junitfile=test-ce.xml --junitfile-project-name CE --junitfile-testcase-classname relative --format standard-verbose -- -shuffle=on -timeout=20m -coverpkg=./... -coverprofile=cover_ce.out -race -count=1 ./... > verbose_ce.out' ,
98+ returnStatus : true ,
99+ )
100+
101+ // convert the junit file to prepend CE- to all test names to differentiate from EE tests
102+ sh ''' xmlstarlet ed -u '//testcase/@classname' -x 'concat("CE-", .)' test-ce.xml > reports/test-ce.xml'''
103+
104+ // Print total coverage stats
105+ sh ' go tool cover -func=cover_ce.out | awk \' END{print "Total SG CE Coverage: " $3}\' '
106+
107+ sh ' mkdir -p reports'
108+
109+ // Grab test fail/total counts so we can print them later
110+ sh " grep '\\ -\\ -\\ - PASS: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-pass.count"
111+ sh " grep '\\ -\\ -\\ - FAIL: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-fail.count"
112+ sh " grep '\\ -\\ -\\ - SKIP: ' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-skip.count"
113+ sh " grep '=== RUN' verbose_ce.out | wc -l | awk '{printf \$ 1}' > test-ce-total.count"
114114 env. TEST_CE_PASS = readFile ' test-ce-pass.count'
115115 env. TEST_CE_FAIL = readFile ' test-ce-fail.count'
116116 env. TEST_CE_SKIP = readFile ' test-ce-skip.count'
117117 env. TEST_CE_TOTAL = readFile ' test-ce-total.count'
118- }
119118
120- // Generate junit-formatted test report
121- script {
122- try {
123- sh ' which go2xunit' // check if go2xunit is installed
124- sh ' go2xunit -fail -suite-name-prefix="CE-" -input verbose_ce.out -output reports/test-ce.xml'
119+ if (testExitCode == 0 ) {
125120 githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ce-unit-tests' , description : env. TEST_CE_PASS + ' /' + env. TEST_CE_TOTAL + ' passed (' + env. TEST_CE_SKIP + ' skipped)' , status : ' SUCCESS' )
126- } catch ( Exception e) {
121+ } else {
127122 githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ce-unit-tests' , description : env. TEST_CE_FAIL + ' /' + env. TEST_CE_TOTAL + ' failed (' + env. TEST_CE_SKIP + ' skipped)' , status : ' FAILURE' )
128123 // archive verbose test logs in the event of a test failure
129124 archiveArtifacts artifacts : ' verbose_ce.out' , fingerprint : false
130125 unstable(' At least one CE unit test failed' )
131126 }
132- }
133127
134- // Publish CE coverage to coveralls.io
135- // Replace covermode values with set just for coveralls to reduce the variability in reports.
136- sh ' awk \' NR==1{print "mode: set";next} $NF>0{$NF=1} {print}\' cover_ce.out > cover_ce_coveralls.out'
137- sh ' which goveralls' // check if goveralls is installed
138- sh ' goveralls -coverprofile=cover_ce_coveralls.out -service=uberjenkins -repotoken=$COVERALLS_TOKEN || true'
128+ // Publish CE coverage to coveralls.io
129+ // Replace covermode values with set just for coveralls to reduce the variability in reports.
130+ sh ' awk \' NR==1{print "mode: set";next} $NF>0{$NF=1} {print}\' cover_ce.out > cover_ce_coveralls.out'
131+ sh ' which goveralls' // check if goveralls is installed
132+ sh ' goveralls -coverprofile=cover_ce_coveralls.out -service=uberjenkins -repotoken=$COVERALLS_TOKEN || true'
133+ }
139134 }
140135 }
141136 }
142137
143138 stage(' EE' ) {
144139 steps {
145- withEnv([" PATH+GO=${ env.GOTOOLS} /bin" ]) {
146- githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ee-unit-tests' , description : ' EE Unit Tests Running' , status : ' PENDING' )
147-
148- // Build EE coverprofiles
149- sh " 2>&1 go test -shuffle=on -timeout=20m -tags ${ EE_BUILD_TAG} -coverpkg=./... -coverprofile=cover_ee.out -race -count=1 -v ./... > verbose_ee.out.raw || true"
150-
151- sh ' go tool cover -func=cover_ee.out | awk \' END{print "Total SG EE Coverage: " $3}\' '
152-
153- sh ' mkdir -p reports'
154-
155- // strip non-printable characters from the raw verbose test output
156- sh ' LC_CTYPE=C tr -dc [:print:][:space:] < verbose_ee.out.raw > verbose_ee.out'
157-
158- // Grab test fail/total counts so we can print them later
159- sh " grep '\\ -\\ -\\ - PASS: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-pass.count"
160- sh " grep '\\ -\\ -\\ - FAIL: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-fail.count"
161- sh " grep '\\ -\\ -\\ - SKIP: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-skip.count"
162- sh " grep '=== RUN' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-total.count"
163- script {
140+ script {
141+ withEnv([" PATH+GO=${ env.GOTOOLS} /bin" ]) {
142+ githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ee-unit-tests' , description : ' EE Unit Tests Running' , status : ' PENDING' )
143+
144+ // --junitfile-project-name is used so that Jenkins doesn't collapse CE and EE results together.
145+ def testExitCode = sh(
146+ script : " gotestsum --junitfile=test-ee.xml --junitfile-project-name EE --junitfile-testcase-classname relative --format standard-verbose -- -shuffle=on -timeout=20m -tags ${ EE_BUILD_TAG} -coverpkg=./... -coverprofile=cover_ee.out -race -count=1 ./... 2>&1 > verbose_ee.out" ,
147+ returnStatus : true ,
148+ )
149+ sh ' mkdir -p reports'
150+
151+ // convert the junit file to prepend EE- to all test names to differentiate from EE tests
152+ sh ''' xmlstarlet ed -u '//testcase/@classname' -x 'concat("EE-", .)' test-ee.xml > reports/test-ee.xml'''
153+
154+ sh ' go tool cover -func=cover_ee.out | awk \' END{print "Total SG EE Coverage: " $3}\' '
155+
156+ // Grab test fail/total counts so we can print them later
157+ sh " grep '\\ -\\ -\\ - PASS: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-pass.count"
158+ sh " grep '\\ -\\ -\\ - FAIL: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-fail.count"
159+ sh " grep '\\ -\\ -\\ - SKIP: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-skip.count"
160+ sh " grep '=== RUN' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-total.count"
164161 env. TEST_EE_PASS = readFile ' test-ee-pass.count'
165162 env. TEST_EE_FAIL = readFile ' test-ee-fail.count'
166163 env. TEST_EE_SKIP = readFile ' test-ee-skip.count'
167164 env. TEST_EE_TOTAL = readFile ' test-ee-total.count'
168- }
169165
170- // Generate junit-formatted test report
171- script {
172- try {
173- sh ' go2xunit -fail -suite-name-prefix="EE-" -input verbose_ee.out -output reports/test-ee.xml'
166+ // Generate junit-formatted test report
167+ if (testExitCode == 0 ) {
174168 githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ee-unit-tests' , description : env. TEST_EE_PASS + ' /' + env. TEST_EE_TOTAL + ' passed (' + env. TEST_EE_SKIP + ' skipped)' , status : ' SUCCESS' )
175- } catch ( Exception e) {
169+ } else {
176170 githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ee-unit-tests' , description : env. TEST_EE_FAIL + ' /' + env. TEST_EE_TOTAL + ' failed (' + env. TEST_EE_SKIP + ' skipped)' , status : ' FAILURE' )
177171 // archive verbose test logs in the event of a test failure
178172 archiveArtifacts artifacts : ' verbose_ee.out' , fingerprint : false
0 commit comments