@@ -11,8 +11,8 @@ stages:
1111 displayName : " Run All"
1212 pool :
1313 type : linux
14- # isCustom: true
15- # name: "$(BUILD_POOL_NAME_DEFAULT)"
14+ isCustom : true
15+ name : " $(BUILD_POOL_NAME_DEFAULT)"
1616 variables :
1717 ob_outputDirectory : $(Build.ArtifactStagingDirectory)/linux-unittest
1818 REPORT_DIR : $(Build.ArtifactStagingDirectory)/linux-unittest
@@ -65,16 +65,23 @@ stages:
6565 touch "$REPORT_XML"
6666 make tools
6767
68- $GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/linux-coverage.json
69- $GOCOV_XML_BIN < "$REPORT_DIR"/linux-coverage.json > "$REPORT_DIR"/linux-coverage.gocov.xml
68+ $GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/linux-coverage.json
69+ $GOCOV_XML_BIN < "$REPORT_DIR"/linux-coverage.json > "$REPORT_DIR"/linux-coverage.gocov.xml
7070 displayName: "Generate Test Reporting"
7171 workingDirectory: $(ACN_DIR)
7272
73+ task: PublishPipelineArtifact@1
74+ inputs:
75+ targetPath: $(REPORT_DIR)
76+ artifactName: drop_unittest_linux
77+
7378
7479 - job : windows
7580 displayName : " Run Tests - Windows"
7681 pool :
82+ isCustom : true
7783 type : windows
84+ name : " $(BUILD_POOL_NAME_DEFAULT_WINDOWS_ALT)"
7885 variables :
7986 ob_outputDirectory : $(Build.ArtifactStagingDirectory)/windows-unittest
8087
@@ -89,51 +96,98 @@ stages:
8996 version : ' $(GOVERSION)'
9097
9198 - script : |
92- set -e
93- BIN_INSTALL_DIR=$(realpath bin)
94- GOBIN="$BIN_INSTALL_DIR" go install github.com/jstemmer/go-junit-report/v2@latest
95- JUNIT_REPORT_BIN="$BIN_INSTALL_DIR/go-junit-report"
96-
97- mkdir -p "$REPORT_DIR"
98- touch "$REPORT_XML"
99+ # Define variables
100+ $BIN_INSTALL_DIR = (Resolve-Path -Path "bin").Path
101+ $PRE_BIN = $GOBIN
102+ # Install go-junit-report
103+ $env:GOBIN = $GOBIN
104+ go install github.com/jstemmer/go-junit-report/v2@latest
105+
106+ $JUNIT_REPORT_BIN = Join-Path -Path $BIN_INSTALL_DIR -ChildPath "go-junit-report"
107+
108+ # Create report directory and report.xml file
109+ if (!(Test-Path -Path $REPORT_DIR)) {
110+ New-Item -Path $REPORT_DIR -ItemType Directory
111+ }
112+ if (!(Test-Path -Path $REPORT_XML)) {
113+ New-Item -Path $REPORT_XML -ItemType File
114+ }
115+
116+ $env:GOBIN = $PRE_BIN
117+ # Run make tools
99118 make tools
119+
120+ # Run tests and generate report
121+ try {
122+ # Run test, capture output and exit code
123+ $testOutput = @(
124+ go test -timeout 30m -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=windows-coverage.out ./npm/... ./cni/... ./platform/...
125+ go tool cover -func=windows-coverage.out
126+ )
127+ $exitCode = $LASTEXITCODE
128+
129+ # Write test output to report.xml using go-junit-report
130+ $testOutput | & $JUNIT_REPORT_BIN | Out-File -FilePath $REPORT_XML -Encoding utf8
131+
132+ # Exit with test exit code
133+ if ($exitCode -ne 0) {
134+ exit $exitCode
135+ }
136+ } catch {
137+ Write-Error $_
138+ exit 1
139+ }
140+
141+ # List files in report directory
142+ Get-ChildItem -Path $REPORT_DIR -Force | Select-Object -ExpandProperty FullName | ForEach-Object { Write-Host $_ }
143+
144+ # Move coverage.out to COVERAGE_OUT
145+ Move-Item -Path "windows-coverage.out" -Destination $COVERAGE_OUT -Force
146+
147+ # List files in report directory again
148+ Get-ChildItem -Path $REPORT_DIR -Force | Select-Object -ExpandProperty FullName | ForEach-Object { Write-Host $_ }
100149
101- # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml),
102- # stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code.
103- # Read all output from fd 4 (output from tee) and write to to stdout
104- { { { {
105- go test -timeout 30m -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=windows-coverage.out ./npm/... ./cni/... ./platform/...
106- go tool cover -func=windows-coverage.out
107- echo $? >&3;
108- } | tee >($JUNIT_REPORT_BIN > "$REPORT_XML") >&4;
109- } 3>&1;
110- } | { read xs; exit $xs; }
111- } 4>&1
112-
113- ls -la "$REPORT_DIR"
114- mv windows-coverage.out "$COVERAGE_OUT"
115- ls -la "$REPORT_DIR"
116150 retryCountOnTaskFailure: 3
117151 displayName: "Run Unit Tests - Windows"
118152 workingDirectory: $(ACN_DIR)
119153
120154 - script : |
121- BIN_INSTALL_DIR=$(realpath bin)
122- GOBIN="$BIN_INSTALL_DIR" go install github.com/axw/gocov/gocov@latest
123- GOBIN="$BIN_INSTALL_DIR" go install github.com/AlekSi/gocov-xml@latest
124-
125- GOCOV_BIN="$BIN_INSTALL_DIR/gocov"
126- GOCOV_XML_BIN="$BIN_INSTALL_DIR/gocov-xml"
127-
128- mkdir -p "$REPORT_DIR"
129- touch "$REPORT_XML"
155+ # Define the installation directory for binaries
156+ $BIN_INSTALL_DIR = (Resolve-Path -Path "bin").Path
157+ $PRE_BIN = $GOBIN
158+
159+ # Install required Go packages
160+ $env:GOBIN = $BIN_INSTALL_DIR
161+ go install github.com/axw/gocov/gocov@latest
162+ go install github.com/AlekSi/gocov-xml@latest
163+
164+ # Define paths to the installed binaries
165+ $GOCOV_BIN = Join-Path -Path $BIN_INSTALL_DIR -ChildPath "gocov"
166+ $GOCOV_XML_BIN = Join-Path -Path $BIN_INSTALL_DIR -ChildPath "gocov-xml"
167+
168+ # Create the report directory and initialize the report XML file
169+ if (!(Test-Path -Path $REPORT_DIR)) {
170+ New-Item -Path $REPORT_DIR -ItemType Directory
171+ }
172+ if (!(Test-Path -Path $REPORT_XML)) {
173+ New-Item -Path $REPORT_XML -ItemType File
174+ }
175+
176+ $env:GOBIN = $PRE_BIN
177+ # Run the 'make tools' command (assuming 'make' is available in the system's PATH)
130178 make tools
131-
132- $GOCOV_BIN convert "$COVERAGE_OUT" > "$REPORT_DIR"/windows-coverage.json
133- $GOCOV_XML_BIN < "$REPORT_DIR"/windows-coverage.json > "$REPORT_DIR"/windows-coverage.gocov.xml
179+
180+ # Convert coverage data and generate reports
181+ & $GOCOV_BIN convert $COVERAGE_OUT | Out-File -FilePath (Join-Path -Path $REPORT_DIR -ChildPath "windows-coverage.json")
182+ & $GOCOV_XML_BIN < (Join-Path -Path $REPORT_DIR -ChildPath "windows-coverage.json") | Out-File -FilePath (Join-Path -Path $REPORT_DIR -ChildPath "windows-coverage.gocov.xml")
134183 displayName: "Generate Test Reporting"
135184 workingDirectory: $(ACN_DIR)
136185
186+ task: PublishPipelineArtifact@1
187+ inputs:
188+ targetPath: $(REPORT_DIR)
189+ artifactName: drop_unittest_windows
190+
137191
138192 - job : coverage
139193 displayName : " Check Test Coverage"
0 commit comments