1+ # This is the workflow for SWT that collects and reports junit results
2+
3+ # This script runs from the master branch all the time. This means if you update it in a
4+ # Pull Request, the update won't take effect until after you merge the PR, the PR itself
5+ # will *not* use the edits.
6+ # Therefore to really test a change to this script, push it to your fork's master branch
7+ # and then create a PR against your own master branch.
8+
9+ # You can run this locally to test changes with the act command https://nektosact.com/
10+ # Steps:
11+ # 1. Get a PAT (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
12+ # Use fine grained one, needs Read access to artifact metadata, and metadata
13+ # 2. Get the URL of some artifacts to test against from a previous run of the build
14+ # script (such as your last run on your fork's master branch). It looks like:
15+ # https://api.github.com/repos/jonahgraham/eclipse.platform.swt/actions/runs/19980765555/artifacts
16+ # 3. Run the act command:
17+ # act -W '.github/workflows/junit.yml' -s GITHUB_TOKEN=your_token --input artifacts_url=your_url
18+
119name : Publish Unit Test Results
220
321on :
@@ -10,37 +28,101 @@ permissions:
1028 contents : read
1129
1230jobs :
13- unit-test-results :
14- name : Unit Test Results
31+ discover-results :
1532 runs-on : ubuntu-latest
1633 if : github.event.workflow_run.conclusion != 'skipped'
34+ outputs :
35+ matrix : ${{ steps.build-matrix.outputs.matrix }}
36+ isall : ${{ steps.build-matrix.outputs.all }}
37+ steps :
38+ - name : Find test-results from artifacts_url and build dynamic matrix
39+ id : build-matrix
40+ env :
41+ GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
42+ run : |
43+ set -x
44+ # Get the URL from the event, or the act command line
45+ artifacts_url=${{ github.event.workflow_run.artifacts_url || github.event.inputs.artifacts_url }}
46+ results=$(gh api "$artifacts_url" -q '.artifacts[] | [.name] | @tsv' | grep 'test-results-')
47+
48+ platforms=""
49+ if [[ "$results" == *macos* ]]; then
50+ platforms="macos"
51+ fi
52+ if [[ "$results" == *linux* ]]; then
53+ if [[ -n "$platforms" ]]; then
54+ platforms+=" "
55+ fi
56+ platforms+="linux"
57+ fi
58+ if [[ "$results" == *win32* ]]; then
59+ if [[ -n "$platforms" ]]; then
60+ platforms+=" "
61+ fi
62+ platforms+="win32"
63+ fi
64+
65+ if [[ "$platforms" == "macos linux win32" ]]; then
66+ platforms+=" all"
67+ echo "isall=1" >> "$GITHUB_OUTPUT"
68+ else
69+ echo "isall=0" >> "$GITHUB_OUTPUT"
70+ fi
71+
72+ json=$(jq -R --arg key "platform" 'split(" ") | {($key): .}' <<< "$platforms")
73+
74+ echo "Matrix JSON (pretty): ${json}"
75+ {
76+ echo 'matrix<<EOF'
77+ printf '%s\n' "$json"
78+ echo 'EOF'
79+ } >> "$GITHUB_OUTPUT"
80+
81+ results :
82+ needs : discover-results
83+ runs-on : ubuntu-latest
1784 permissions :
1885 checks : write
1986 pull-requests : write
2087 contents : read
2188 issues : read
2289 actions : read
90+ strategy :
91+ # Use the dynamic matrix from the previous job
92+ matrix : ${{ fromJson(needs.discover-results.outputs.matrix) }}
93+ fail-fast : false
2394
2495 steps :
25- - name : Download and Extract Artifacts
96+ - name : Downloading rest results for ${{ matrix.platform }}
2697 env :
2798 GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
2899 run : |
29- mkdir -p artifacts && cd artifacts
100+ set -x
101+ mkdir -p artifacts && cd artifacts
30102
31- artifacts_url=${{ github.event.workflow_run.artifacts_url }}
103+ # Get the URL from the event, or the act command line
104+ artifacts_url=${{ github.event.workflow_run.artifacts_url || github.event.inputs.artifacts_url }}
32105
33- gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
34- do
35- IFS=$'\t' read name url <<< "$artifact"
36- gh api $url > "$name.zip"
37- unzip -d "$name" "$name.zip"
38- done
106+ if [[ "${{ matrix.platform }}" == "all" ]]; then
107+ # allow everything through
108+ grep="."
109+ else
110+ # only download event file and tests for this platform
111+ grep="Event File|${{ matrix.platform }}"
112+ fi
113+ gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | grep -E "$grep" | while read artifact
114+ do
115+ IFS=$'\t' read name url <<< "$artifact"
116+ gh api $url > "$name.zip"
117+ unzip -d "$name" "$name.zip"
118+ done
39119
40120 - name : Publish Unit Test Results
41121 uses : EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2.21.0
42122 id : test-results
43123 with :
124+ check_name : ${{ matrix.platform == 'all' && 'Test Results' || format('Test Results ({0})', matrix.platform) }}
125+ comment_mode : ${{ (matrix.platform == 'all') == (needs.discover-results.outputs.isall == '1') && 'always' || 'off' }}
44126 commit : ${{ github.event.workflow_run.head_sha }}
45127 event_file : artifacts/Event File/event.json
46128 event_name : ${{ github.event.workflow_run.event }}
0 commit comments