-
Notifications
You must be signed in to change notification settings - Fork 2.2k
ci: add medik8s-polarion-reporter Prow step for Polarion XUnit import #80497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maximunited
wants to merge
2
commits into
openshift:main
Choose a base branch
from
maximunited:feat/medik8s-polarion-reporter-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ci-operator/step-registry/medik8s/polarion-reporter/medik8s-polarion-reporter-commands.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/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 |
30 changes: 30 additions & 0 deletions
30
ci-operator/step-registry/medik8s/polarion-reporter/medik8s-polarion-reporter-ref.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🤖 Prompt for AI Agents