Skip to content

Commit 2bbc991

Browse files
authored
chore(ci): add final_status property on junit XML [APMSP-2610] (#287)
* chore(ci): add final_status property on junit XML [APMSP-2610] * remove useless sudo * apt-get update * Use saxon * Use native XML tooling * Add echo on windows job
1 parent 1572290 commit 2bbc991

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3+
4+
<!-- Identity transform: copy everything as-is by default -->
5+
<xsl:template match="@*|node()">
6+
<xsl:copy>
7+
<xsl:apply-templates select="@*|node()"/>
8+
</xsl:copy>
9+
</xsl:template>
10+
11+
<!-- For testcase elements missing dd_tags[test.final_status] inside their properties block -->
12+
<xsl:template match="testcase[not(properties/property[@name='dd_tags[test.final_status]'])]">
13+
<xsl:copy>
14+
<xsl:apply-templates select="@*"/>
15+
<xsl:variable name="status">
16+
<xsl:choose>
17+
<xsl:when test="failure or error">fail</xsl:when>
18+
<xsl:when test="skipped">skip</xsl:when>
19+
<xsl:otherwise>pass</xsl:otherwise>
20+
</xsl:choose>
21+
</xsl:variable>
22+
<xsl:choose>
23+
<xsl:when test="properties">
24+
<!-- Inject into existing properties block, preserving child order -->
25+
<xsl:for-each select="node()">
26+
<xsl:choose>
27+
<xsl:when test="self::properties">
28+
<properties>
29+
<xsl:apply-templates select="@*|node()"/>
30+
<property name="dd_tags[test.final_status]" value="{$status}"/>
31+
</properties>
32+
</xsl:when>
33+
<xsl:otherwise>
34+
<xsl:apply-templates select="."/>
35+
</xsl:otherwise>
36+
</xsl:choose>
37+
</xsl:for-each>
38+
</xsl:when>
39+
<xsl:otherwise>
40+
<!-- No properties block: create one before other children -->
41+
<properties>
42+
<property name="dd_tags[test.final_status]" value="{$status}"/>
43+
</properties>
44+
<xsl:apply-templates select="node()"/>
45+
</xsl:otherwise>
46+
</xsl:choose>
47+
</xsl:copy>
48+
</xsl:template>
49+
50+
</xsl:stylesheet>

.github/workflows/dev.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ jobs:
6666
run: cd ${BUILD_DIR} && test/tests -r junit -o report.xml
6767
env:
6868
ASAN_OPTIONS: alloc_dealloc_mismatch=0
69+
- name: Add final_status property
70+
if: success() || failure()
71+
run: |
72+
which xsltproc || (apt-get update && apt-get install -y xsltproc)
73+
xml_file=".build/report.xml"
74+
echo "Fixing $xml_file"
75+
tmp_file="$(mktemp)"
76+
xsltproc --output "$tmp_file" ".github/workflows/add_final_status.xsl" "$xml_file"
77+
mv "$tmp_file" "$xml_file"
6978
- name: Upload test report to Datadog
79+
if: success() || failure()
7080
run: |
7181
curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_linux-${{ matrix.arch }}" --output "/usr/local/bin/datadog-ci" && chmod +x /usr/local/bin/datadog-ci
7282
datadog-ci junit upload --service dd-trace-cpp --tags test.source.file:test/*.cpp .build/report.xml
@@ -155,10 +165,25 @@ jobs:
155165
run: |
156166
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch ${{ matrix.arch }}
157167
.\build\test\tests.exe -r junit -o report.xml
168+
- name: Add final_status property
169+
if: success() || failure()
170+
run: |
171+
$xmlFile = "report.xml"
172+
$xslFile = ".github/workflows/add_final_status.xsl"
173+
$tmpFile = [System.IO.Path]::GetTempFileName()
174+
175+
echo "Fixing $xmlFile"
176+
177+
$transform = New-Object System.Xml.Xsl.XslCompiledTransform
178+
$transform.Load($xslFile)
179+
$transform.Transform($xmlFile, $tmpFile)
180+
181+
Move-Item -Force $tmpFile $xmlFile
158182
- name: Upload test report to Datadog
183+
if: success() || failure()
159184
run: |
160185
Invoke-WebRequest -Uri "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_win-x64" -OutFile "datadog-ci.exe"
161-
./datadog-ci.exe junit upload --service dd-trace-cpp --tags test.source.file:test/*.cpp report.xml
186+
./datadog-ci.exe junit upload --service dd-trace-cpp --tags test.source.file:test/*.cpp report.xml
162187
163188
coverage:
164189
needs: build-linux-cmake

0 commit comments

Comments
 (0)