Skip to content

Commit 50f5c05

Browse files
committed
Allow to compress binaries with UPX
1 parent ea88c27 commit 50f5c05

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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:
@@ -163,3 +167,4 @@ runs:
163167
INPUT_CODESIGN: ${{ inputs.codesign }}
164168
INPUT_CODESIGN_PREFIX: ${{ inputs.codesign-prefix || inputs.codesign_prefix }}
165169
INPUT_CODESIGN_OPTIONS: ${{ inputs.codesign-options || inputs.codesign_options }}
170+
INPUT_UPX: ${{ inputs.upx }}

main.sh

Lines changed: 27 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,32 @@ 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 --lzma "${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+
sudo apt-get install -y upx-ucl
393+
compress_binaries
394+
;;
395+
macos)
396+
# MacOS is not currently supported by UPX
397+
;;
398+
*)
399+
warn "UPX is not available on ${host_os}"
400+
;;
401+
esac
402+
fi
403+
377404
case "${host_os}" in
378405
macos)
379406
if type -P codesign >/dev/null; then

0 commit comments

Comments
 (0)