ci: fix harbor auth and publish go test totals

This commit is contained in:
Brad Stein 2026-04-10 06:24:41 -03:00
parent fe7295d629
commit cccbd6ebd2

70
Jenkinsfile vendored
View File

@ -55,11 +55,10 @@ spec:
- name: docker-config-writable - name: docker-config-writable
emptyDir: {} emptyDir: {}
- name: dind-storage - name: dind-storage
persistentVolumeClaim: emptyDir: {}
claimName: jenkins-dind-cache
- name: harbor-config - name: harbor-config
secret: secret:
secretName: harbor-bstein-robot secretName: harbor-robot-pipeline
items: items:
- key: .dockerconfigjson - key: .dockerconfigjson
path: config.json path: config.json
@ -95,7 +94,31 @@ spec:
container('tester') { container('tester') {
sh ''' sh '''
set -eu set -eu
go test ./... apt-get update >/dev/null
apt-get install -y --no-install-recommends jq >/dev/null
mkdir -p build
set +e
go test -json ./... > build/go-test.json
test_rc=$?
set -e
tests_total="$(jq -s '[.[] | select(.Test != null and (.Action=="pass" or .Action=="fail" or .Action=="skip"))] | length' build/go-test.json)"
tests_failed="$(jq -s '[.[] | select(.Test != null and .Action=="fail")] | length' build/go-test.json)"
tests_skipped="$(jq -s '[.[] | select(.Test != null and .Action=="skip")] | length' build/go-test.json)"
tests_errors="$(jq -s '[.[] | select(.Test == null and .Action=="fail")] | length' build/go-test.json)"
tests_passed=$((tests_total - tests_failed - tests_skipped))
if [ "${tests_passed}" -lt 0 ]; then
tests_passed=0
fi
cat > build/test-summary.json <<EOF
{
"tests": ${tests_total},
"passed": ${tests_passed},
"failed": ${tests_failed},
"errors": ${tests_errors},
"skipped": ${tests_skipped}
}
EOF
exit "${test_rc}"
''' '''
} }
} }
@ -133,15 +156,18 @@ spec:
stage('Build & push image') { stage('Build & push image') {
steps { steps {
container('builder') { container('builder') {
sh ''' withCredentials([usernamePassword(credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
set -eu sh '''
VERSION_TAG=$(cut -d= -f2 build.env) set -eu
docker buildx build --platform linux/arm64 \ VERSION_TAG=$(cut -d= -f2 build.env)
--provenance=false \ printf '%s' "${HARBOR_PASSWORD}" | docker login registry.bstein.dev -u "${HARBOR_USERNAME}" --password-stdin
--tag registry.bstein.dev/bstein/soteria:${VERSION_TAG} \ docker buildx build --platform linux/arm64 \
--tag registry.bstein.dev/bstein/soteria:latest \ --provenance=false \
--push . --tag registry.bstein.dev/bstein/soteria:${VERSION_TAG} \
''' --tag registry.bstein.dev/bstein/soteria:latest \
--push .
'''
}
} }
} }
} }
@ -168,10 +194,19 @@ spec:
ok_count="$(fetch_counter ok)" ok_count="$(fetch_counter ok)"
failed_count="$(fetch_counter failed)" failed_count="$(fetch_counter failed)"
ok_count=$((ok_count + 1)) ok_count=$((ok_count + 1))
tests_passed="$(jq -r '.passed // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_failed="$(jq -r '.failed // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_errors="$(jq -r '.errors // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_skipped="$(jq -r '.skipped // 0' build/test-summary.json 2>/dev/null || echo 0)"
cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null
# TYPE platform_quality_gate_runs_total counter # TYPE platform_quality_gate_runs_total counter
platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count} platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count}
platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count} platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count}
# TYPE soteria_quality_gate_tests_total gauge
soteria_quality_gate_tests_total{suite="${suite}",result="passed"} ${tests_passed}
soteria_quality_gate_tests_total{suite="${suite}",result="failed"} ${tests_failed}
soteria_quality_gate_tests_total{suite="${suite}",result="error"} ${tests_errors}
soteria_quality_gate_tests_total{suite="${suite}",result="skipped"} ${tests_skipped}
METRICS METRICS
''' '''
} }
@ -197,10 +232,19 @@ METRICS
ok_count="$(fetch_counter ok)" ok_count="$(fetch_counter ok)"
failed_count="$(fetch_counter failed)" failed_count="$(fetch_counter failed)"
failed_count=$((failed_count + 1)) failed_count=$((failed_count + 1))
tests_passed="$(jq -r '.passed // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_failed="$(jq -r '.failed // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_errors="$(jq -r '.errors // 0' build/test-summary.json 2>/dev/null || echo 0)"
tests_skipped="$(jq -r '.skipped // 0' build/test-summary.json 2>/dev/null || echo 0)"
cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null cat <<METRICS | curl -fsS --data-binary @- "${gateway}/metrics/job/platform-quality-ci/suite/${suite}" >/dev/null
# TYPE platform_quality_gate_runs_total counter # TYPE platform_quality_gate_runs_total counter
platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count} platform_quality_gate_runs_total{suite="${suite}",status="ok"} ${ok_count}
platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count} platform_quality_gate_runs_total{suite="${suite}",status="failed"} ${failed_count}
# TYPE soteria_quality_gate_tests_total gauge
soteria_quality_gate_tests_total{suite="${suite}",result="passed"} ${tests_passed}
soteria_quality_gate_tests_total{suite="${suite}",result="failed"} ${tests_failed}
soteria_quality_gate_tests_total{suite="${suite}",result="error"} ${tests_errors}
soteria_quality_gate_tests_total{suite="${suite}",result="skipped"} ${tests_skipped}
METRICS METRICS
''' '''
} }