@@ -44,11 +44,13 @@ jobs:
44
44
strategy :
45
45
matrix : ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
46
46
steps :
47
- - name : Checkout base repo
48
- uses : actions/checkout@v4
49
47
- name : " Install tools"
48
+ if : ${{ matrix.os == 'ubuntu-latest' }}
50
49
run : |
51
- .github/workflows/install-tools.sh
50
+ sudo apt install upx-ucl
51
+
52
+ - name : Checkout base repo
53
+ uses : actions/checkout@v4
52
54
- name : Set up Haskell
53
55
id : setup-haskell
54
56
uses : haskell-actions/setup@v2
75
77
76
78
- name : Install
77
79
run : |
78
- bin=$(cabal -v0 --project-file=cabal.release.project list-bin print-api)
79
80
mkdir distribution
80
- cp ${bin} distribution/print-api
81
+ for executable in 'print-api' 'print-api-${{ matrix.ghc }}'; do
82
+ path=$(cabal -v0 --project-file=cabal.release.project list-bin "print-api:exe:${executable}")
83
+ cp "${path}" distribution
84
+ done
81
85
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
82
86
83
87
- name : Test
@@ -90,19 +94,25 @@ jobs:
90
94
report_paths : " report.xml"
91
95
92
96
- name : File type
93
- run : file distribution/print-api
97
+ run : file distribution/*
98
+
99
+ - name : Post-process executables
100
+ if : ${{ matrix.os == 'ubuntu-latest' }}
101
+ run : |
102
+ for executable in distribution/*; do
103
+ strip "${executable}"
104
+ upx -9 "${executable}"
105
+ done
94
106
95
- - name : Package the print-api executable
107
+ - name : Package the executables
96
108
run : |
97
- PRINTAPI_EXEC=distribution/print-api
98
- .github/workflows/process-binaries.sh
99
- DIR=$(dirname $PRINTAPI_EXEC)
100
- FILE=$(basename $PRINTAPI_EXEC)
109
+ executables=( $(ls distribution) )
101
110
version=$(./distribution/print-api --version)
102
- PRINTAPI_EXEC_TAR=print-api-${version}-${{ runner.os }}-${{ matrix.ghc }}-${{ env.ARCH }}.tar.gz
103
- tar -czvf $PRINTAPI_EXEC_TAR -C $DIR $FILE
104
- echo PRINTAPI_EXEC_TAR=$PRINTAPI_EXEC_TAR >> $GITHUB_ENV
105
- - name : Upload the print-api executable
111
+ archive="print-api-${version}-${{ runner.os }}-${{ env.ARCH }}-ghc-${{ matrix.ghc }}.tar.gz"
112
+ tar -czvf "${archive}" -C distribution "${executables[@]}"
113
+ echo "PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
114
+
115
+ - name : Upload the executables archive
106
116
uses : actions/upload-artifact@v3
107
117
with :
108
118
name : artifact
@@ -154,9 +164,11 @@ jobs:
154
164
155
165
- name : Install
156
166
run : |
157
- bin=$(cabal -v0 --project-file=cabal.static.project list-bin print-api)
158
167
mkdir distribution
159
- cp ${bin} distribution/print-api
168
+ for executable in 'print-api' 'print-api-${{ matrix.ghc }}'; do
169
+ path=$(cabal -v0 --project-file=cabal.static.project list-bin "print-api:exe:${executable}")
170
+ cp "${path}" distribution
171
+ done
160
172
echo "$GITHUB_WORKSPACE/distribution" >> "$GITHUB_PATH"
161
173
162
174
- name : Test
@@ -169,40 +181,76 @@ jobs:
169
181
report_paths : " report.xml"
170
182
171
183
- name : File type
172
- run : file distribution/print-api
184
+ run : file distribution/*
185
+
186
+ - name : Post-process executables
187
+ if : ${{ matrix.os == 'ubuntu-latest' }}
188
+ run : |
189
+ for executable in distribution/*; do
190
+ strip "${executable}"
191
+ upx -9 "${executable}"
192
+ done
173
193
174
- - name : Package the print-api executable
194
+ - name : Package the executables
195
+ shell : bash
175
196
run : |
176
- PRINTAPI_EXEC=distribution/print-api
177
- .github/workflows/process-binaries.sh
178
- DIR=$(dirname $PRINTAPI_EXEC)
179
- FILE=$(basename $PRINTAPI_EXEC)
197
+ executables=( $(ls distribution) )
180
198
version=$(./distribution/print-api --version)
181
- PRINTAPI_EXEC_TAR= print-api-${version}-${{ runner.os }}-static- ${{ matrix.ghc }}-${{ env.ARCH }}.tar.gz
182
- tar -czvf $PRINTAPI_EXEC_TAR -C $DIR $FILE
183
- echo PRINTAPI_EXEC_TAR=$PRINTAPI_EXEC_TAR >> $GITHUB_ENV
199
+ archive=" print-api-${version}-${{ runner.os }}-${{ env.ARCH }}-static-ghc- ${{ matrix.ghc }}.tar.gz"
200
+ tar -czvf "${archive}" -C distribution "${executables[@]}"
201
+ echo " PRINTAPI_EXEC_TAR=${archive}" >> $GITHUB_ENV
184
202
185
- - name : Upload print-api executable to workflow artifacts
203
+ - name : Upload the executables archive
186
204
uses : actions/upload-artifact@v3
187
205
with :
188
206
name : artifact
189
207
path : ${{ env.PRINTAPI_EXEC_TAR }}
190
208
209
+ # NOTE: We run upx on the executables in every linux job to compress them.
210
+ # That means, the assets that are linked dynamically _appear_ to be statically
211
+ # linked after that, despite not being compiled statically in Alpine with
212
+ # musl. They are still dynamically-linked once they are decompresed.
213
+ # See: https://stackoverflow.com/questions/20740625/does-upx-magically-transform-binaries-from-dynamically-linked-into-statically-li
191
214
release :
192
215
name : Create a GitHub Release with the binary artifacts
193
216
runs-on : ubuntu-latest
194
- if : startsWith(github.ref, 'refs/tags/v')
195
217
needs : ['tests', 'build-alpine']
196
218
197
219
steps :
198
220
- uses : actions/download-artifact@v3
199
221
with :
200
222
name : artifact
201
- path : ./out
223
+ path : ./artifacts
224
+
225
+ - name : Prepare release
226
+ shell : bash
227
+ run : |
228
+ create-tarball() {
229
+ local name="${1}"
230
+ local pattern="${2}"
231
+
232
+ echo "::group::Creating release tarball ${name}.tar.gz"
233
+ mkdir "${name}"
234
+ find artifacts -type f -name "${pattern}" -exec tar -x -z -f {} -C "${name}" \;
235
+ local files=( $(find "${name}" -type f -printf '%P\n') )
236
+ if [[ ${#files[@]} > 0 ]]; then
237
+ echo "Packaging ${#files[@]} files"
238
+ tar -c -z -v -f "release/${name}.tar.gz" -C "${name}" "${files[@]}"
239
+ else
240
+ echo "No files to package"
241
+ fi
242
+ echo '::endgroup::'
243
+ }
244
+
245
+ mkdir release
246
+ for base in $(ls artifacts | cut -d - -f -5 | sort --uniq); do
247
+ create-tarball "${base}" "${base}-ghc-*.tar.gz"
248
+ create-tarball "${base}-static" "${base}-static-ghc-*.tar.gz"
249
+ done
202
250
203
251
- name : Release
204
252
uses : softprops/action-gh-release@v2
205
- if : startsWith(github.ref, 'refs/tags/')
206
253
with :
254
+ prerelease : ${{ startsWith(github.ref, 'refs/tags/v') }}
207
255
draft : true
208
- files : ./out /*
256
+ files : ./release /*
0 commit comments