Skip to content

Commit 23c6d19

Browse files
authored
Harmonise the CI setup with get-tested (#26)
1 parent 0c0c88b commit 23c6d19

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

.github/workflows/ci.yml

+43-35
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,44 @@ jobs:
6161
run: |
6262
ARCHITECTURE=$(uname -m)
6363
echo "ARCH=$ARCHITECTURE" >> $GITHUB_ENV
64+
KERNEL=$(uname -s)
65+
echo "KERNEL=$KERNEL" >> $GITHUB_ENV
66+
echo "REPORT_NAME=report-$KERNEL-ghc-${{ matrix.ghc }}.xml" >> $GITHUB_ENV
6467
echo ${{ env.ARCH }}
65-
cabal configure --enable-tests
68+
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
69+
echo "REPORT_NAME=report-${{ matrix.os }}-ghc-${{ matrix.ghc }}.xml" >> $GITHUB_ENV
6670
6771
- name: Freeze
6872
run: cabal freeze --project-file=cabal.release.project
6973

7074
- name: Cache
71-
uses: actions/cache@v4.0.2
75+
uses: actions/cache@v4
7276
with:
77+
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
7378
path: ${{ steps.setup-haskell.outputs.cabal-store }}
74-
key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
75-
restore-keys: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-
79+
restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}-
7680

7781
- name: Build
7882
run: cabal build --project-file=cabal.release.project
7983

80-
- name: Install
81-
run: |
82-
mkdir distribution
83-
for executable in 'print-api' 'print-api-${{ matrix.ghc }}'; do
84-
path=$(cabal -v0 --project-file=cabal.release.project list-bin "print-api:exe:${executable}")
85-
cp "${path}" distribution
86-
done
87-
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
88-
echo "REPORT_NAME=report-${{ matrix.os }}-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
89-
9084
- name: Test
91-
run: cabal test --project-file=cabal.release.project --test-options "--xml=../print-api/${{ env.REPORT_NAME }}.xml" all
85+
run: |
86+
cabal test --project-file=cabal.release.project --test-options "--xml=../print-api/${{ env.REPORT_NAME }}" all
9287
9388
- name: Upload the test report
9489
uses: actions/upload-artifact@v4
9590
if: success() || failure() # always run even if the previous step fails
9691
with:
9792
name: ${{ env.REPORT_NAME }}
98-
path: ${{ env.REPORT_NAME }}.xml
93+
path: ${{ env.REPORT_NAME }}
94+
95+
- name: Install
96+
run: |
97+
mkdir distribution
98+
for executable in 'print-api' 'print-api-${{ matrix.ghc }}'; do
99+
path=$(cabal -v0 --project-file=cabal.release.project list-bin "print-api:exe:${executable}")
100+
cp -v "${path}" distribution
101+
done
99102
100103
- name: File type
101104
run: file distribution/*
@@ -112,17 +115,16 @@ jobs:
112115
shell: bash
113116
run: |
114117
executables=( $(ls distribution) )
115-
version=$(./distribution/print-api --version)
116-
archive="print-api-${version}-${{ matrix.os }}-${{ env.ARCH }}-ghc-${{ matrix.ghc }}.tar.gz"
117-
tar -czvf "${archive}" -C distribution "${executables[@]}"
118-
echo "PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
119-
echo "ARTIFACT_NAME=artifact-${{ matrix.os }}-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
118+
ARTIFACT_NAME=print-api-${{ env.KERNEL }}-ghc-${{ matrix.ghc }}
119+
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
120+
ARCHIVE=${ARTIFACT_NAME}.tar.gz
121+
tar -czvf "${ARCHIVE}" -C distribution "${executables[@]}"
120122
121123
- name: Upload the executables archive
122124
uses: actions/upload-artifact@v4
123125
with:
124126
name: ${{ env.ARTIFACT_NAME }}
125-
path: ${{ env.PRINTAPI_EXEC_TAR }}
127+
path: ${{ env.ARTIFACT_NAME }}.tar.gz
126128

127129
build-alpine:
128130
name: ${{ matrix.ghc }} on alpine-3.20
@@ -153,7 +155,11 @@ jobs:
153155
run: |
154156
ARCHITECTURE=$(uname -m)
155157
echo "ARCH=$ARCHITECTURE" >> $GITHUB_ENV
158+
KERNEL=$(uname -s)
159+
echo "KERNEL=$KERNEL" >> $GITHUB_ENV
160+
echo "REPORT_NAME=report-$KERNEL-ghc-${{ matrix.ghc }}.xml" >> $GITHUB_ENV
156161
echo ${{ env.ARCH }}
162+
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
157163
cabal configure --enable-tests
158164
159165
- name: Freeze
@@ -177,15 +183,15 @@ jobs:
177183
cp "${path}" distribution
178184
done
179185
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
180-
echo "REPORT_NAME=report-alpine-3.20-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
186+
echo "REPORT_NAME=report-${{ env.KERNEL }}-static-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
181187
182188
- name: Test
183189
run: cabal test --project-file=cabal.static.project --test-options "--xml=../print-api/${REPORT_NAME}.xml" all
184190

185191
- name: Upload the test report
186192
uses: actions/upload-artifact@v4
187193
if: success() || failure() # always run even if the previous step fails
188-
with:
194+
with:
189195
name: ${{ env.REPORT_NAME }}
190196
path: ${{ env.REPORT_NAME }}.xml
191197

@@ -204,21 +210,21 @@ jobs:
204210
shell: bash
205211
run: |
206212
executables=( $(ls distribution) )
207-
version=$(./distribution/print-api --version)
208-
archive="print-api-${version}-alpine-3.20-${{ env.ARCH }}-static-ghc-${{ matrix.ghc }}.tar.gz"
209-
tar -c -z -v -f "${archive}" -C distribution "${executables[@]}"
210-
echo "PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
211-
echo "ARTIFACT_NAME=artifact-alpine-3.20-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
213+
ARTIFACT_NAME=print-api-${{ env.KERNEL }}-static-ghc-${{ matrix.ghc }}
214+
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
215+
ARCHIVE=${ARTIFACT_NAME}.tar.gz
216+
tar -czvf "${ARCHIVE}" -C distribution "${executables[@]}"
212217
213-
- name: Upload the executables archive
218+
- name: Upload the get-tested executable
214219
uses: actions/upload-artifact@v4
215220
with:
216221
name: ${{ env.ARTIFACT_NAME }}
217-
path: ${{ env.PRINTAPI_EXEC_TAR }}
222+
path: ${{ env.ARTIFACT_NAME }}.tar.gz
218223

219224
collect-test-results:
220225
name: Collect test results
221226
runs-on: ubuntu-latest
227+
if: ${{ always() }}
222228
needs: ['builds', 'build-alpine']
223229
steps:
224230
- name: Install junitparser
@@ -229,12 +235,11 @@ jobs:
229235
with:
230236
pattern: report-*
231237
merge-multiple: true
232-
workflow: ${{ github.event.workflow.id }}
233-
run-id: ${{ github.event.workflow_run.id }}
234-
github-token: ${{ secrets.GH_PAT }} # token with actions:read permissions on target repo
238+
235239
- name: Merge XML files
236240
run: |
237241
junitparser merge --glob *.xml final-report.xml
242+
238243
- name: Publish Test Report
239244
uses: mikepenz/action-junit-report@v4
240245
with:
@@ -244,12 +249,15 @@ jobs:
244249
prerelease-head:
245250
name: Create a GitHub prerelease with the binary artifacts
246251
runs-on: ubuntu-latest
252+
if: github.ref == 'refs/heads/main'
247253
needs: ['builds', 'build-alpine']
254+
permissions:
255+
contents: write
248256

249257
steps:
250258
- uses: actions/download-artifact@v4
251259
with:
252-
pattern: artifact-*
260+
pattern: print-api-*
253261
merge-multiple: true
254262
path: ./out
255263

0 commit comments

Comments
 (0)