Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ tests:
ODF_OPERATOR_SUB_CHANNEL: stable-4.21
OO_CHANNEL: stable
OPERATORS: storage-based-remediation
POLARION_TESTRUN_ID: "RHWA-SBR-4.22-weekly"
test:
- ref: medik8s-catalogsource
- ref: medik8s-operator-subscribe
Expand All @@ -240,6 +241,8 @@ tests:
requests:
cpu: 100m
memory: 200Mi
post:
- ref: medik8s-polarion-reporter
workflow: ipi-aws
zz_generated_metadata:
branch: main
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
set -eu -o pipefail

# Validate SHARED_DIR is set and non-empty before globbing against it.
if [[ -z "${SHARED_DIR:-}" ]]; then
echo "ERROR: SHARED_DIR is not set — cannot locate JUnit XML files."
exit 1
fi

IMPORT_URL="${POLARION_URL}/polarion/import/xunit"

echo "Collecting JUnit XML files from \$SHARED_DIR..."
xml_files=("${SHARED_DIR}"/*_junit.xml)

if [[ ! -e "${xml_files[0]}" ]]; then
echo "No *_junit.xml files found in \$SHARED_DIR — skipping Polarion import."
exit 0
fi

echo "Found ${#xml_files[@]} file(s): ${xml_files[*]}"

# Write credentials to a netrc file so they never appear in the process argv.
netrc_file=$(mktemp)
polarion_host=$(echo "${POLARION_URL}" | sed 's|https\?://||' | cut -d/ -f1)
cat > "${netrc_file}" <<NETRC
machine ${polarion_host}
login $(cat /var/run/polarion/username)
password $(cat /var/run/polarion/password)
NETRC
chmod 600 "${netrc_file}"

# XML-escape a string for use in an attribute value.
xml_escape() { printf '%s' "$1" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g'; }

# Build properties file for the XUnit importer.
# polarion-project-id and polarion-testrun-id are read by Polarion from this
# companion file when present alongside the XML in a multipart POST.
properties_file=$(mktemp /tmp/polarion-props.XXXXXX.xml)
{
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<testsuites-importer>'
echo ' <properties>'
echo " <property name=\"polarion-project-id\" value=\"$(xml_escape "${POLARION_PROJECT_ID}")\"/>"
if [[ -n "${POLARION_TESTRUN_ID}" ]]; then
echo " <property name=\"polarion-testrun-id\" value=\"$(xml_escape "${POLARION_TESTRUN_ID}")\"/>"
fi
echo ' </properties>'
echo '</testsuites-importer>'
} > "${properties_file}"

response_file=$(mktemp)

for xml_file in "${xml_files[@]}"; do
echo "Importing $(basename "${xml_file}") into Polarion project ${POLARION_PROJECT_ID}..."
http_code=$(curl --silent --netrc-file "${netrc_file}" \
--output "${response_file}" --write-out "%{http_code}" \
-F "file=@${xml_file}" \
-F "properties=@${properties_file}" \
"${IMPORT_URL}")

if [[ "${http_code}" -ge 200 && "${http_code}" -lt 300 ]]; then
echo "Import succeeded (HTTP ${http_code})."
else
echo "Import failed (HTTP ${http_code}):"
cat "${response_file}"
exit 1
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ref:
as: medik8s-polarion-reporter
from: cli
commands: medik8s-polarion-reporter-commands.sh
credentials:
- namespace: test-credentials
name: medik8s-polarion-creds
mount_path: /var/run/polarion
resources:
requests:
cpu: 100m
memory: 100Mi
best_effort: true
timeout: 10m0s
env:
- name: POLARION_PROJECT_ID
default: "OSE"
documentation: Polarion project ID to import results into.
- name: POLARION_TESTRUN_ID
default: ""
documentation: |-
Polarion test run ID to update (e.g. "RHWA-SBR-4.22-weekly").
If empty, Polarion creates a new test run from the imported XML.
- name: POLARION_URL
default: "https://polarion.engineering.redhat.com"
documentation: Base URL of the Polarion instance.
documentation: |-
Uploads JUnit XML test results from $SHARED_DIR to Polarion via the XUnit
importer API. Reads credentials from the medik8s-polarion-creds secret.
Must run after the test step that writes junit_*.xml files to $SHARED_DIR.
Comment on lines +27 to +30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align the documented XML glob with the implemented one.

The docs say junit_*.xml, but the command script matches *_junit.xml. Please make these consistent to avoid operator confusion.

Suggested patch
-    Must run after the test step that writes junit_*.xml files to $SHARED_DIR.
+    Must run after the test step that writes *_junit.xml files to $SHARED_DIR.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@ci-operator/step-registry/medik8s/polarion-reporter/medik8s-polarion-reporter-ref.yaml`
around lines 29 - 32, The documentation in the yaml file states the glob pattern
as junit_*.xml, but the actual command script implementation uses *_junit.xml.
Update the documentation string in the medik8s-polarion-reporter-ref.yaml file
to match the actual glob pattern used in the command script by changing
junit_*.xml to *_junit.xml to ensure consistency and prevent user confusion
about the expected file naming convention.