Skip to content

Commit

Permalink
Add JUnit annotate BK plugin (elastic#5473)
Browse files Browse the repository at this point in the history
* Add JUnit annotate BK plugin

Signed-off-by: Alexandros Sapranidis <alexandros@elastic.co>
  • Loading branch information
alexsapran authored Oct 8, 2024
1 parent 1d3e007 commit 0d5b335
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 60 deletions.
89 changes: 54 additions & 35 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ steps:
key: "unit-tests-2204"
command: ".buildkite/scripts/steps/unit-tests.sh"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "gcp"
image: "family/core-ubuntu-2204"
Expand All @@ -35,10 +35,10 @@ steps:
key: "unit-tests-2204-arm64"
command: ".buildkite/scripts/steps/unit-tests.sh"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "aws"
imagePrefix: "core-ubuntu-2204-aarch64"
Expand All @@ -52,10 +52,10 @@ steps:
key: "unit-tests-win2022"
command: ".\\.buildkite\\scripts\\steps\\unit-tests.ps1"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "gcp"
image: "family/core-windows-2022"
Expand All @@ -70,10 +70,10 @@ steps:
key: "unit-tests-win2016"
command: ".\\.buildkite\\scripts\\steps\\unit-tests.ps1"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "gcp"
image: "family/core-windows-2016"
Expand All @@ -90,10 +90,10 @@ steps:
command: ".buildkite/scripts/steps/unit-tests.sh"
branches: main
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: orka
imagePrefix: generic-13-ventura-arm
Expand All @@ -105,10 +105,10 @@ steps:
key: "unit-tests-macos-13"
command: ".buildkite/scripts/steps/unit-tests.sh"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: orka
imagePrefix: generic-13-ventura-x64
Expand All @@ -123,10 +123,10 @@ steps:
key: "unit-tests-win10"
command: ".\\.buildkite\\scripts\\steps\\unit-tests.ps1"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "gcp"
# TODO create own image
Expand All @@ -140,10 +140,10 @@ steps:
key: "unit-tests-win11"
command: ".\\.buildkite\\scripts\\steps\\unit-tests.ps1"
artifact_paths:
- "build/TEST-go-unit.html"
- "build/TEST-go-unit.xml"
- "build/TEST-*.html"
- "build/TEST-*.xml"
- "build/diagnostics/*"
- "coverage.out"
- "coverage-*.out"
agents:
provider: "gcp"
# TODO create own image
Expand All @@ -154,22 +154,41 @@ steps:
manual:
allowed: true


- label: ":junit: Junit annotate"
plugins:
- junit-annotate#v2.5.0:
artifacts: "build/*.xml"
always-annotate: true
agents:
provider: "gcp"
depends_on:
- step: "unit-tests-2204"
allow_failure: true
- step: "unit-tests-2204-arm64"
allow_failure: true
- step: "unit-tests-win2022"
allow_failure: true
- step: "unit-tests-win2016"
allow_failure: true
- step: "unit-tests-macos-13-arm"
allow_failure: true
- step: "unit-tests-macos-13"
allow_failure: true
- step: "unit-tests-win10"
allow_failure: true
- step: "unit-tests-win11"
allow_failure: true


- label: "Merge coverage reports"
key: "merge-coverage"
env:
BUILDKITE_REPO: ""
command: "
command: |
.buildkite/scripts/steps/merge.sh
unit-tests-2204
unit-tests-2204-arm64
unit-tests-win2016
unit-tests-win2022
unit-tests-macos-13
unit-tests-win10
unit-tests-win11
"
artifact_paths:
- "build/TEST-go-unit.cov"
- "TEST-go-unit.cov"
agents:
image: "golang:1.22.6"
depends_on:
Expand Down Expand Up @@ -206,7 +225,7 @@ steps:
agents:
image: "docker.elastic.co/cloud-ci/sonarqube/buildkite-scanner:latest"
command:
- "buildkite-agent artifact download --step merge-coverage build/TEST-go-unit.cov ."
- "buildkite-agent artifact download --step merge-coverage TEST-go-unit.cov ."
- "/scan-source-code.sh"
depends_on:
- "merge-coverage"
Expand Down
21 changes: 6 additions & 15 deletions .buildkite/scripts/steps/merge.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
#!/bin/bash

# Downloads and merges coverage files from multiple steps into a single file (build/TEST-go-unit.cov).
# Usage: merge.sh <step1> <step2> ... Where <step> is the id of the step that contains the coverage artifact.#

# Usage: merge.sh <step1> <step2> ... Where <step> is the id of the step that contains the coverage artifact.#
set -euo pipefail
set -x # for debugging

COV_ARTIFACT="coverage.out"
MERGED_COV_FILE="build/TEST-go-unit.cov"
# Space separated list of paths to coverage files
COV_PATHS=""
MERGED_COV_FILE="TEST-go-unit.cov"

go install github.com/wadey/gocovmerge@latest
mkdir -p build

for STEP_ID in "$@"; do
mkdir -p $STEP_ID
buildkite-agent artifact download --step $STEP_ID $COV_ARTIFACT $STEP_ID
COV_PATHS="${COV_PATHS} $STEP_ID/$COV_ARTIFACT"
done

gocovmerge $COV_PATHS > $MERGED_COV_FILE
echo "Merged coverage file: $MERGED_COV_FILE. See artifacts"
buildkite-agent artifact download "coverage-*.out" .
# Space separated list of paths to coverage files
find coverage-*.out -exec printf '%s ' {} \; | xargs gocovmerge > "$MERGED_COV_FILE"
echo "Merged coverage file: $MERGED_COV_FILE. See artifacts"
10 changes: 6 additions & 4 deletions .buildkite/scripts/steps/unit-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ Write-Host "--- Build"
mage build

if ($LASTEXITCODE -ne 0) {
exit 1
exit 1
}

Write-Host "--- Unit tests"
$env:TEST_COVERAGE = $true
$env:RACE_DETECTOR = $true
mage unitTest
# Copy coverage file to build directory so it can be downloaded as an artifact
cp .\build\TEST-go-unit.cov coverage.out

Write-Host "--- Prepare artifacts"
$buildkiteJobId = $env:BUILDKITE_JOB_ID
Move-Item -Path "build/TEST-go-unit.cov" -Destination "coverage-$buildkiteJobId.out"
Move-Item -Path "build/TEST-go-unit.xml" -Destination "build/TEST-$buildkiteJobId.xml"
if ($LASTEXITCODE -ne 0) {
exit 1
exit 1
}


9 changes: 5 additions & 4 deletions .buildkite/scripts/steps/unit-tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
set -uo pipefail

source .buildkite/scripts/common.sh
set +euo pipefail

echo "--- Unit tests"
RACE_DETECTOR=true TEST_COVERAGE=true mage unitTest
TESTS_EXIT_STATUS=$?
echo "--- Prepare artifacts"
# Copy coverage file to build directory so it can be downloaded as an artifact
cp build/TEST-go-unit.cov coverage.out
exit $TESTS_EXIT_STATUS
mv build/TEST-go-unit.cov "coverage-${BUILDKITE_JOB_ID:go-unit}.out"
mv build/TEST-go-unit.xml build/"TEST-${BUILDKITE_JOB_ID:go-unit}.xml"
exit $TESTS_EXIT_STATUS
6 changes: 4 additions & 2 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ func makeGoTestArgs(name string) GoTestArgs {
}

func makeGoTestArgsForModule(name, module string) GoTestArgs {
fileName := fmt.Sprintf("build/TEST-go-%s-%s", strings.Replace(strings.ToLower(name), " ", "_", -1),
strings.Replace(strings.ToLower(module), " ", "_", -1))
fileName := fmt.Sprintf("build/TEST-go-%s-%s",
strings.Replace(strings.ToLower(name), " ", "_", -1),
strings.Replace(strings.ToLower(module), " ", "_", -1),
)
params := GoTestArgs{
LogName: fmt.Sprintf("%s-%s", name, module),
Race: RaceDetector,
Expand Down

0 comments on commit 0d5b335

Please sign in to comment.