Skip to content

Commit afd7206

Browse files
committed
fixup! Edit Pipeline Trigger
1 parent 4780e09 commit afd7206

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

.pipelines/templates/run-unit-tests.yaml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ stages:
6565
$GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/linux-coverage.json
6666
$GOCOV_XML_BIN < "$REPORT_DIR"/linux-coverage.json > "$REPORT_DIR"/linux-coverage.gocov.xml
6767
68-
echo "##vso[task.setvariable variable=COVERAGE_OUT_XML;isOutput=true]$(cat $REPORT_DIR/linux-coverage.xml)"
69-
echo "##vso[task.setvariable variable=GOCOV_OUT_XML;isOutput=true]$(cat $REPORT_DIR/linux-coverage.gocov.xml)"
68+
echo "##vso[task.setvariable variable=JUNIT_XML;isOutput=true]$(cat $REPORT_XML | base64 -w 0)"
69+
echo "##vso[task.setvariable variable=COVERAGE_OUT_JSON;isOutput=true]$(cat $REPORT_DIR/linux-coverage.json | base64 -w 0)"
70+
echo "##vso[task.setvariable variable=COVERAGE_OUT_XML;isOutput=true]$(cat $REPORT_DIR/linux-coverage.xml | base64 -w 0)"
71+
echo "##vso[task.setvariable variable=GOCOV_OUT_XML;isOutput=true]$(cat $REPORT_DIR/linux-coverage.gocov.xml | base64 -w 0)"
7072
name: report
7173
displayName: "Generate Test Reporting"
7274
@@ -168,6 +170,7 @@ stages:
168170
arguments: $(Build.SourcesDirectory)
169171
scriptSource: 'inline'
170172
script: |
173+
import base64
171174
import os
172175
import subprocess
173176
import sys
@@ -211,22 +214,28 @@ stages:
211214
with open(coverage_xml, 'w') as xml_file:
212215
with open(coverage_json, 'r') as json_file:
213216
subprocess.run([gocov_xml_bin], stdin=json_file, stdout=xml_file, check=True)
217+
218+
# Encoding function to convert long multi-line files to single line for setting vso variable.
219+
def encode_file_to_base64(file_path):
220+
with open(file_path, 'rb') as file:
221+
encoded_string = base64.b64encode(file.read()).decode('utf-8')
222+
return encoded_string
223+
214224
# coverage json
215-
with open(coverage_json, 'r') as f:
216-
coverage_out_json_content = f.read()
217-
print(f"##vso[task.setvariable variable=COVERAGE_OUT_JSON;isOutput=true]{coverage_out_json_content}")
225+
coverage_out_json_content = encode_file_to_base64(coverage_json)
226+
print(f"##vso[task.setvariable variable=COVERAGE_OUT_JSON;isOutput=true]{coverage_out_json_content}")
227+
218228
# coverage xml
219-
with open(coverage_xml, 'r') as xml_file:
220-
xml_content = xml_file.read()
221-
print(f"##vso[task.setvariable variable=COVERAGE_OUT_XML;isOutput=true]{xml_content}")
229+
coverage_xml_content = encode_file_to_base64(coverage_json)
230+
print(f"##vso[task.setvariable variable=COVERAGE_OUT_XML;isOutput=true]{coverage_xml_content}")
231+
222232
# go cover
223-
with open(gocover_out, 'r') as f:
224-
gocover_out_content = f.read()
225-
print(f"##vso[task.setvariable variable=GOCOV_OUT;isOutput=true]{gocover_out_content}")
233+
gocover_out_content = encode_file_to_base64(gocover_out)
234+
print(f"##vso[task.setvariable variable=GOCOV_OUT;isOutput=true]{gocover_out_content}")
235+
226236
# junit xml
227-
with open(junit_xml, 'r') as f:
228-
junit_xml_content = f.read()
229-
print(f"##vso[task.setvariable variable=JUNIT_XML;isOutput=true]{junit_xml_content}")
237+
junit_xml_content = encode_file_to_base64(junit_xml)
238+
print(f"##vso[task.setvariable variable=JUNIT_XML;isOutput=true]{junit_xml_content}")
230239
231240
232241
- job: coverage
@@ -241,18 +250,26 @@ stages:
241250
ob_outputDirectory: $(Build.ArtifactStagingDirectory)/out
242251

243252
WINDOWS_JUNIT_XML: $[ dependencies.windows.outputs['report.JUNIT_XML'] ]
244-
WINDOWS_COVERAGE_OUT: $[ dependencies.windows.outputs['report.COVERAGE_OUT_XML'] ]
253+
WINDOWS_COVERAGE_OUT_XML: $[ dependencies.windows.outputs['report.COVERAGE_OUT_XML'] ]
254+
WINDOWS_COVERAGE_OUT_JSON: $[ dependencies.windows.outputs['report.COVERAGE_OUT_JSON'] ]
245255
WINDOWS_GOCOV_OUT: $[ dependencies.windows.outputs['report.GOCOV_OUT'] ]
246-
LINUX_COVERAGE_OUT: $[ dependencies.linux.outputs['report.COVERAGE_OUT_XML'] ]
256+
257+
LINUX_COVERAGE_OUT_JSON: $[ dependencies.linux.outputs['report.COVERAGE_OUT_JSON'] ]
258+
LINUX_COVERAGE_OUT_XML: $[ dependencies.linux.outputs['report.COVERAGE_OUT_XML'] ]
247259
LINUX_GOCOV_OUT: $[ dependencies.linux.outputs['report.GOCOV_OUT_XML'] ]
260+
LINUX_JUNIT_XML: $[ dependencies.linux.outputs['report.JUNIT_XML'] ]
248261
steps:
249262
- script: |
250263
mkdir "$COV_DIR"
251-
echo "$LINUX_COVERAGE_OUT" > "$COV_DIR"/linux-coverage.xml
252-
echo "$LINUX_GOCOV_OUT" > "$COV_DIR"/linux-coverage.gocov.xml
253-
echo "$WINDOWS_COVERAGE_OUT" > "$COV_DIR"/windows-coverage.xml
254-
echo "$WINDOWS_GOCOV_OUT" > "$COV_DIR"/windows-coverage.gocov.xml
255-
echo "$WINDOWS_JUNIT_XML" > "$COV_DIR"/windows-coverage.junit.xml
264+
echo "$LINUX_COVERAGE_OUT_XML" | base64 -d > "$COV_DIR"/linux-coverage.xml
265+
echo "$LINUX_COVERAGE_OUT_JSON" | base64 -d > "$COV_DIR"/linux-coverage.json
266+
echo "$LINUX_GOCOV_OUT" | base64 -d > "$COV_DIR"/linux-coverage.gocov.xml
267+
echo "$LINUX_JUNIT_XML" | base64 -d > "$COV_DIR"/linux-coverage.junit.xml
268+
269+
echo "$WINDOWS_COVERAGE_OUT_XML" | base64 -d > "$COV_DIR"/windows-coverage.xml
270+
echo "$WINDOWS_COVERAGE_OUT_JSON" | base64 -d > "$COV_DIR"/windows-coverage.json
271+
echo "$WINDOWS_GOCOV_OUT" | base64 -d > "$COV_DIR"/windows-coverage.gocov.xml
272+
echo "$WINDOWS_JUNIT_XML" | base64 -d > "$COV_DIR"/windows-coverage.junit.xml
256273
env:
257274
COV_DIR: $(Build.ArtifactStagingDirectory)/coverage
258275
@@ -261,7 +278,7 @@ stages:
261278
inputs:
262279
testResultsFormat: 'JUnit'
263280
testResultsFiles: # string. Required. Test results files. Default: **/TEST-*.xml.
264-
searchFolder: coverage/**/*.xml
281+
searchFolder: coverage/**/*.junit.xml
265282
failTaskOnFailedTests: true
266283
failTaskOnMissingResultsFile: false
267284
#testRunTitle: # Name of the test runs

0 commit comments

Comments
 (0)