Skip to content

Commit

Permalink
Allow to compress binaries with UPX
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Nov 10, 2024
1 parent ea88c27 commit 78bd5fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Currently, this action is basically intended to be used in combination with an a
| codesign | false | Sign build products using `codesign` on macOS | String | |
| codesign-prefix | false | Prefix for the `codesign` identifier on macOS | String | |
| 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 | |
| upx | false | Compress binaries using [UPX](https://upx.github.io) on some platforms | Boolean | `false` |

\[1] Required one of `token` input option or `GITHUB_TOKEN` environment variable. Not required when `dry-run` input option is set to `true`.<br>
\[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>
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ inputs:
codesign_options:
description: Alias for 'codesign-options'
required: false
upx:
description: Compress binaries using UPX on some platforms
required: false
default: 'false'

outputs:
archive:
Expand Down Expand Up @@ -163,3 +167,4 @@ runs:
INPUT_CODESIGN: ${{ inputs.codesign }}
INPUT_CODESIGN_PREFIX: ${{ inputs.codesign-prefix || inputs.codesign_prefix }}
INPUT_CODESIGN_OPTIONS: ${{ inputs.codesign-options || inputs.codesign_options }}
INPUT_UPX: ${{ inputs.upx }}
27 changes: 27 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ build() {
*) bail "unrecognized build tool '${build_tool}'" ;;
esac
}

do_codesign() {
if [[ -n "${INPUT_CODESIGN:-}" ]]; then
local codesign_options=(--sign "${INPUT_CODESIGN}")
Expand Down Expand Up @@ -374,6 +375,32 @@ case "${INPUT_TARGET:-}" in
;;
esac

# Compress binaries with UPX
if [[ "${INPUT_UPX:-}" = "true" ]]; then
compress_binaries() {
for bin_exe in "${bins[@]}"; do
x upx --best --lzma "${target_dir}/${bin_exe}"
done
}

case "${host_os}" in
windows)
choco install upx -y
compress_binaries
;;
linux)
sudo apt-get install -y upx-ucl
compress_binaries
;;
macos)
# MacOS is not currently supported by UPX.
;;
*)
warn "UPX is not available on ${host_os}"
;;
esac
fi

case "${host_os}" in
macos)
if type -P codesign >/dev/null; then
Expand Down

0 comments on commit 78bd5fe

Please sign in to comment.