Skip to content

Commit 3c2bc3d

Browse files
authored
Collect all test reports in a single workflow and print it in GitHub (#22)
closes #21
1 parent 6ec16e1 commit 3c2bc3d

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,23 @@ jobs:
5757
with:
5858
ghc-version: ${{ matrix.ghc }}
5959
cabal-version: 'latest'
60+
6061
- name: Configure
6162
run: |
6263
ARCHITECTURE=$(uname -m)
6364
echo "ARCH=$ARCHITECTURE" >> $GITHUB_ENV
6465
echo ${{ env.ARCH }}
6566
cabal configure --enable-tests
67+
6668
- name: Freeze
6769
run: cabal freeze --project-file=cabal.release.project
70+
6871
- name: Cache
6972
uses: actions/cache@v4.0.2
7073
with:
7174
path: ${{ steps.setup-haskell.outputs.cabal-store }}
72-
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
73-
restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}-
75+
key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
76+
restore-keys: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-
7477

7578
- name: Build
7679
run: cabal build --project-file=cabal.release.project
@@ -83,6 +86,17 @@ jobs:
8386
cp "${path}" distribution
8487
done
8588
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
89+
echo "REPORT_NAME=report-${{ matrix.os }}-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
90+
91+
- name: Test
92+
run: cabal test --project-file=cabal.release.project --test-options "--xml=../print-api/${{ env.REPORT_NAME }}.xml" all
93+
94+
- name: Upload the test report
95+
uses: actions/upload-artifact@v4
96+
if: success() || failure() # always run even if the previous step fails
97+
with:
98+
name: ${{ env.REPORT_NAME }}
99+
path: ${{ env.REPORT_NAME }}.xml
86100

87101
- name: File type
88102
run: file distribution/*
@@ -100,14 +114,15 @@ jobs:
100114
run: |
101115
executables=( $(ls distribution) )
102116
version=$(./distribution/print-api --version)
103-
archive="print-api-${version}-${{ runner.os }}-${{ env.ARCH }}-ghc-${{ matrix.ghc }}.tar.gz"
117+
archive="print-api-${version}-${{ matrix.os }}-${{ env.ARCH }}-ghc-${{ matrix.ghc }}.tar.gz"
104118
tar -czvf "${archive}" -C distribution "${executables[@]}"
105119
echo "PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
120+
echo "ARTIFACT_NAME=artifact-${{ matrix.os }}-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
106121
107122
- name: Upload the executables archive
108-
uses: actions/upload-artifact@v3
123+
uses: actions/upload-artifact@v4
109124
with:
110-
name: artifact
125+
name: ${{ env.ARTIFACT_NAME }}
111126
path: ${{ env.PRINTAPI_EXEC_TAR }}
112127

113128
build-alpine:
@@ -145,11 +160,12 @@ jobs:
145160
- name: Freeze
146161
run: cabal freeze --project-file=cabal.static.project
147162

148-
- uses: actions/cache@v4
163+
- name: Cache
164+
uses: actions/cache@v4
149165
with:
150166
path: ${{ steps.setup-haskell.outputs.cabal-store }}
151-
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-${{ hashFiles('**/plan.json') }}
152-
restore-keys: ${{ runner.os }}-${{ steps.setup.outputs.ghc-version }}-
167+
key: alpine-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
168+
restore-keys: alpine-3.20-${{ matrix.ghc }}-
153169

154170
- name: Build
155171
run: cabal build --project-file=cabal.static.project
@@ -162,15 +178,17 @@ jobs:
162178
cp "${path}" distribution
163179
done
164180
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
181+
echo "REPORT_NAME=report-alpine-3.20-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
165182
166183
- name: Test
167-
run: cabal test --project-file=cabal.static.project --test-options "--xml=../print-api/report.xml" all
184+
run: cabal test --project-file=cabal.static.project --test-options "--xml=../print-api/${REPORT_NAME}.xml" all
168185

169-
- name: Publish Test Report
170-
uses: mikepenz/action-junit-report@v4
186+
- name: Upload the test report
187+
uses: actions/upload-artifact@v4
171188
if: success() || failure() # always run even if the previous step fails
172-
with:
173-
report_paths: "report.xml"
189+
with:
190+
name: ${{ env.REPORT_NAME }}
191+
path: ${{ env.REPORT_NAME }}.xml
174192

175193
- name: File type
176194
run: file distribution/*
@@ -188,14 +206,15 @@ jobs:
188206
run: |
189207
executables=( $(ls distribution) )
190208
version=$(./distribution/print-api --version)
191-
archive="print-api-${version}-${{ runner.os }}-${{ env.ARCH }}-static-ghc-${{ matrix.ghc }}.tar.gz"
209+
archive="print-api-${version}-alpine-3.20-${{ env.ARCH }}-static-ghc-${{ matrix.ghc }}.tar.gz"
192210
tar -c -z -v -f "${archive}" -C distribution "${executables[@]}"
193211
echo "PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
212+
echo "ARTIFACT_NAME=artifact-alpine-3.20-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
194213
195214
- name: Upload the executables archive
196-
uses: actions/upload-artifact@v3
215+
uses: actions/upload-artifact@v4
197216
with:
198-
name: artifact
217+
name: ${{ env.ARTIFACT_NAME }}
199218
path: ${{ env.PRINTAPI_EXEC_TAR }}
200219

201220
prerelease-head:
@@ -204,9 +223,10 @@ jobs:
204223
needs: ['builds', 'build-alpine']
205224

206225
steps:
207-
- uses: actions/download-artifact@v3
226+
- uses: actions/download-artifact@v4
208227
with:
209-
name: artifact
228+
pattern: artifact-*
229+
merge-multiple: true
210230
path: ./out
211231

212232
- name: Release

.github/workflows/test-reports.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test Reports
2+
on:
3+
workflow_run:
4+
workflows: [ "Tests Pipeline" ]
5+
types: [ completed ]
6+
7+
permissions:
8+
checks: write
9+
10+
jobs:
11+
checks:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install juitparser
15+
run: |
16+
pip install junitparser==3.2.0
17+
- name: Download Test Report
18+
uses: actions/download-artifact@v4
19+
with:
20+
pattern: report-*
21+
merge-multiple: true
22+
workflow: ${{ github.event.workflow.id }}
23+
run-id: ${{ github.event.workflow_run.id }}
24+
github-token: ${{ secrets.GH_PAT }} # token with actions:read permissions on target repo
25+
- name: Merge XML files
26+
run: |
27+
junitparser merge --glob *.xml final-report.xml
28+
- name: Publish Test Report
29+
uses: mikepenz/action-junit-report@v3
30+
with:
31+
commit: ${{github.event.workflow_run.head_sha}}
32+
report_paths: 'final-report.xml'

print-api.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cabal-version: 2.4
22
name: print-api
3-
version: 0.1.0.1
3+
-- For the purpose of release and pre-release versioning, we use the following scheme:
4+
-- EPOCH.MAJOR.MINOR.PATCH
5+
-- with the MINOR member being even for releases and odd for pre-releases
6+
version: 0.1.1.0
47
synopsis: Print the API of a package.
58
license: BSD-3-Clause
69
author: Ben Gamari, Hécate Kleidukos

0 commit comments

Comments
 (0)