Skip to content

Commit c7c5a13

Browse files
committed
Add test to CI
1 parent 4398438 commit c7c5a13

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
codesign: '-'
100100
codesign-prefix: 'com.example.'
101101
codesign-options: 'runtime'
102+
upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }}
102103
- name: Check action outputs
103104
run: |
104105
printf 'outputs.archive should not be empty\n'
@@ -121,6 +122,13 @@ jobs:
121122
122123
printf 'outputs.md5 should be a file\n'
123124
test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}"
125+
- name: Check UPX
126+
if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu'
127+
run: |
128+
printf 'binary should be compressed with UPX\n'
129+
target_dir="./test-crate/target/release"
130+
tar -C "$target_dir" -xf "${{ steps.upload-rust-binary-action.outputs.tar }}"
131+
test -n "$(file "$target_dir/test-crate" | grep 'no section header')"
124132
- name: Check b2 output
125133
if: ${{ contains(matrix.checksums || 'b2,sha256,sha512,sha1,md5', 'b2') }}
126134
run: |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Currently, this action is basically intended to be used in combination with an a
5656
| codesign | false | Sign build products using `codesign` on macOS | String | |
5757
| codesign-prefix | false | Prefix for the `codesign` identifier on macOS | String | |
5858
| codesign-options | false | Specifies a set of option flags to be embedded in the code signature on macOS. See the `codesign` manpage for details. | String | |
59+
| upx | false | Compress binaries using [UPX](https://upx.github.io) on some platforms | Boolean | `false` |
5960

6061
\[1] Required one of `token` input option or `GITHUB_TOKEN` environment variable. Not required when `dry-run` input option is set to `true`.<br>
6162
\[2] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.<br>

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ inputs:
108108
codesign_options:
109109
description: Alias for 'codesign-options'
110110
required: false
111+
upx:
112+
description: Compress binaries using UPX on some platforms
113+
required: false
114+
default: 'false'
111115

112116
outputs:
113117
archive:
@@ -166,3 +170,4 @@ runs:
166170
INPUT_CODESIGN: ${{ inputs.codesign }}
167171
INPUT_CODESIGN_PREFIX: ${{ inputs.codesign-prefix || inputs.codesign_prefix }}
168172
INPUT_CODESIGN_OPTIONS: ${{ inputs.codesign-options || inputs.codesign_options }}
173+
INPUT_UPX: ${{ inputs.upx }}

main.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ build() {
330330
*) bail "unrecognized build tool '${build_tool}'" ;;
331331
esac
332332
}
333+
333334
do_codesign() {
334335
if [[ -n "${INPUT_CODESIGN:-}" ]]; then
335336
local codesign_options=(--sign "${INPUT_CODESIGN}")
@@ -374,6 +375,34 @@ case "${INPUT_TARGET:-}" in
374375
;;
375376
esac
376377

378+
# Compress binaries with UPX
379+
if [[ "${INPUT_UPX:-}" = "true" ]]; then
380+
compress_binaries() {
381+
for bin_exe in "${bins[@]}"; do
382+
x upx --best "${target_dir}/${bin_exe}"
383+
done
384+
}
385+
386+
case "${host_os}" in
387+
windows)
388+
choco install upx -y
389+
compress_binaries
390+
;;
391+
linux)
392+
if ! type -P upx >/dev/null; then
393+
sudo apt-get install -y upx-ucl
394+
fi
395+
compress_binaries
396+
;;
397+
macos)
398+
# MacOS is not currently supported by UPX
399+
;;
400+
*)
401+
warn "UPX is not available on ${host_os}"
402+
;;
403+
esac
404+
fi
405+
377406
case "${host_os}" in
378407
macos)
379408
if type -P codesign >/dev/null; then

0 commit comments

Comments
 (0)