@@ -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,85 @@ 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+ sh ' mkdir -p reports'
96+ // --junitfile-project-name is used so that Jenkins doesn't collapse CE and EE results together.
97+ def testExitCode = sh(
98+ 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' ,
99+ returnStatus : true ,
100+ )
101+
102+ // convert the junit file to prepend CE- to all test names to differentiate from EE tests
103+ sh ''' xmlstarlet ed -u '//testcase/@classname' -x 'concat("CE-", .)' test-ce.xml > reports/test-ce.xml'''
104+
105+ // Print total coverage stats
106+ sh ' go tool cover -func=cover_ce.out | awk \' END{print "Total SG CE Coverage: " $3}\' '
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"
114113 env. TEST_CE_PASS = readFile ' test-ce-pass.count'
115114 env. TEST_CE_FAIL = readFile ' test-ce-fail.count'
116115 env. TEST_CE_SKIP = readFile ' test-ce-skip.count'
117116 env. TEST_CE_TOTAL = readFile ' test-ce-total.count'
118- }
119117
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'
118+ if (testExitCode == 0 ) {
125119 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) {
120+ } else {
127121 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' )
128122 // archive verbose test logs in the event of a test failure
129123 archiveArtifacts artifacts : ' verbose_ce.out' , fingerprint : false
130124 unstable(' At least one CE unit test failed' )
131125 }
132- }
133126
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'
127+ // Publish CE coverage to coveralls.io
128+ // Replace covermode values with set just for coveralls to reduce the variability in reports.
129+ sh ' awk \' NR==1{print "mode: set";next} $NF>0{$NF=1} {print}\' cover_ce.out > cover_ce_coveralls.out'
130+ sh ' which goveralls' // check if goveralls is installed
131+ sh ' goveralls -coverprofile=cover_ce_coveralls.out -service=uberjenkins -repotoken=$COVERALLS_TOKEN || true'
132+ }
139133 }
140134 }
141135 }
142136
143137 stage(' EE' ) {
144138 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 {
139+ script {
140+ withEnv([" PATH+GO=${ env.GOTOOLS} /bin" ]) {
141+ githubNotify(credentialsId : " ${ GH_ACCESS_TOKEN_CREDENTIAL} " , context : ' sgw-pipeline-ee-unit-tests' , description : ' EE Unit Tests Running' , status : ' PENDING' )
142+
143+ sh ' mkdir -p reports'
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+
150+ // convert the junit file to prepend EE- to all test names to differentiate from EE tests
151+ sh ''' xmlstarlet ed -u '//testcase/@classname' -x 'concat("EE-", .)' test-ee.xml > reports/test-ee.xml'''
152+
153+ sh ' go tool cover -func=cover_ee.out | awk \' END{print "Total SG EE Coverage: " $3}\' '
154+
155+ // Grab test fail/total counts so we can print them later
156+ sh " grep '\\ -\\ -\\ - PASS: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-pass.count"
157+ sh " grep '\\ -\\ -\\ - FAIL: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-fail.count"
158+ sh " grep '\\ -\\ -\\ - SKIP: ' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-skip.count"
159+ sh " grep '=== RUN' verbose_ee.out | wc -l | awk '{printf \$ 1}' > test-ee-total.count"
164160 env. TEST_EE_PASS = readFile ' test-ee-pass.count'
165161 env. TEST_EE_FAIL = readFile ' test-ee-fail.count'
166162 env. TEST_EE_SKIP = readFile ' test-ee-skip.count'
167163 env. TEST_EE_TOTAL = readFile ' test-ee-total.count'
168- }
169164
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'
165+ // Generate junit-formatted test report
166+ if (testExitCode == 0 ) {
174167 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) {
168+ } else {
176169 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' )
177170 // archive verbose test logs in the event of a test failure
178171 archiveArtifacts artifacts : ' verbose_ee.out' , fingerprint : false
0 commit comments