Skip to content

Publish Unit Test Results #71

Publish Unit Test Results

Publish Unit Test Results #71

Workflow file for this run

name: Publish Unit Test Results
on:
workflow_run:
workflows: ["SWT Matrix Build"]
types:
- completed
permissions:
contents: read
jobs:
# discover-results:
# runs-on: ubuntu-latest
# outputs:
# matrix: ${{ steps.build-matrix.outputs.matrix }}
# steps:
# - name: Find directories and build matrix
# id: build-matrix
# run: |
# # Change this path to whatever root you care about
# ROOT_DIR="projects"
# # Collect immediate subdirectories of ROOT_DIR
# if [ ! -d "$ROOT_DIR" ]; then
# echo "No $ROOT_DIR directory found, using empty matrix."
# echo 'matrix={"dir":[]}' >> "$GITHUB_OUTPUT"
# exit 0
# fi
# dirs=$(find "$ROOT_DIR" -mindepth 1 -maxdepth 1 -type d -printf '%f\n')
# if [ -z "$dirs" ]; then
# echo "No subdirectories found under $ROOT_DIR, using empty matrix."
# echo 'matrix={"dir":[]}' >> "$GITHUB_OUTPUT"
# exit 0
# fi
# echo "Found directories:"
# echo "$dirs"
# # Turn the list into JSON: { "dir": ["foo","bar", ...] }
# json=$(printf '%s\n' "$dirs" | jq -R . | jq -s '{dir: .}')
# echo "Matrix JSON: $json"
# echo "matrix=$json" >> "$GITHUB_OUTPUT"
unit-test-results:
name: Unit Test Results
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
permissions:
checks: write
pull-requests: write
contents: read
issues: read
actions: read
steps:
- name: Download and Extract Artifacts
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
set -x
mkdir -p artifacts && cd artifacts
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
do
IFS=$'\t' read name url <<< "$artifact"
gh api $url > "$name.zip"
unzip -d "$name" "$name.zip"
done
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2.21.0
id: test-results
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
files: "artifacts/**/*.xml"
- name: Set badge color
if: github.ref == 'refs/heads/master'
shell: bash
run: |
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
success)
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
;;
failure)
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
;;
neutral)
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
;;
esac
- name: Create badge
if: github.ref == 'refs/heads/master'
uses: emibcn/badge-action@808173dd03e2f30c980d03ee49e181626088eee8
with:
label: Tests
status: '${{ fromJSON( steps.test-results.outputs.json ).stats.tests }} tests, ${{ fromJSON( steps.test-results.outputs.json ).stats.runs }} runs: ${{ fromJSON( steps.test-results.outputs.json ).conclusion }}'
color: ${{ env.BADGE_COLOR }}
path: badge.svg
- name: Upload badge to Gist
if: github.ref == 'refs/heads/master'
uses: andymckay/append-gist-action@ab30bf28df67017c7ad696500b218558c7c04db3
with:
token: ${{ secrets.GIST_TOKEN }}
gistURL: https://gist.githubusercontent.com/eclipse-releng-bot/78d110a601baa4ef777ccb472f584038
file: badge.svg