From c7c5a13b0ba594f598549e34f5db70033d0db023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Mon, 11 Nov 2024 19:45:52 +0100 Subject: [PATCH 01/14] Add test to CI --- .github/workflows/ci.yml | 8 ++++++++ README.md | 1 + action.yml | 5 +++++ main.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64fbe316..05cd5878 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,6 +99,7 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' + upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' @@ -121,6 +122,13 @@ jobs: printf 'outputs.md5 should be a file\n' test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}" + - name: Check UPX + if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' + run: | + printf 'binary should be compressed with UPX\n' + target_dir="./test-crate/target/release" + tar -C "$target_dir" -xf "${{ steps.upload-rust-binary-action.outputs.tar }}" + test -n "$(file "$target_dir/test-crate" | grep 'no section header')" - name: Check b2 output if: ${{ contains(matrix.checksums || 'b2,sha256,sha512,sha1,md5', 'b2') }} run: | diff --git a/README.md b/README.md index db5e9592..95fcbac0 100644 --- a/README.md +++ b/README.md @@ -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`.
\[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.
diff --git a/action.yml b/action.yml index d282f660..dbded5ef 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -166,3 +170,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 }} diff --git a/main.sh b/main.sh index ff027506..8d9c189d 100755 --- a/main.sh +++ b/main.sh @@ -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}") @@ -374,6 +375,34 @@ 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 "${target_dir}/${bin_exe}" + done + } + + case "${host_os}" in + windows) + choco install upx -y + compress_binaries + ;; + linux) + if ! type -P upx >/dev/null; then + sudo apt-get install -y upx-ucl + fi + 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 From ab004fd94d9453ce082b5161db5d4fea21d2e9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 17:45:19 +0100 Subject: [PATCH 02/14] Run on all targets --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05cd5878..033806d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,8 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' - upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} + upx: true + # ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' @@ -123,7 +124,7 @@ jobs: printf 'outputs.md5 should be a file\n' test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}" - name: Check UPX - if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' + # if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' run: | printf 'binary should be compressed with UPX\n' target_dir="./test-crate/target/release" From 680329bc14933740d4ef3c75011299650f1ea215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 17:50:29 +0100 Subject: [PATCH 03/14] Revert change --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 033806d2..05cd5878 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,8 +99,7 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' - upx: true - # ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} + upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' @@ -124,7 +123,7 @@ jobs: printf 'outputs.md5 should be a file\n' test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}" - name: Check UPX - # if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' + if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' run: | printf 'binary should be compressed with UPX\n' target_dir="./test-crate/target/release" From b575349f4a17be8614151f4a5ca46110f05d26ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 17:50:54 +0100 Subject: [PATCH 04/14] macOS Co-authored-by: Taiki Endo --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index cf1e2371..6bbcc79a 100755 --- a/main.sh +++ b/main.sh @@ -405,7 +405,7 @@ if [[ "${INPUT_UPX:-}" = "true" ]]; then compress_binaries ;; macos) - # MacOS is not currently supported by UPX + # macOS is not currently supported by UPX ;; *) warn "UPX is not available on ${host_os}" From b32cccfea9526d1c25c8a263b056c2fe9358e972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 17:51:20 +0100 Subject: [PATCH 05/14] Check choco existence Co-authored-by: Taiki Endo --- main.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.sh b/main.sh index 6bbcc79a..bac057c0 100755 --- a/main.sh +++ b/main.sh @@ -395,7 +395,9 @@ if [[ "${INPUT_UPX:-}" = "true" ]]; then case "${host_os}" in windows) - choco install upx -y + if ! type -P upx >/dev/null; then + choco install upx -y + fi compress_binaries ;; linux) From c8bbacb48bbdbaacdf3bfc6ff370c7e0e01146b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 17:56:01 +0100 Subject: [PATCH 06/14] Check input --- main.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.sh b/main.sh index bac057c0..f5d51d01 100755 --- a/main.sh +++ b/main.sh @@ -101,6 +101,13 @@ case "${build_locked}" in *) bail "'locked' input option must be 'true' or 'false': '${build_locked}'" ;; esac +upx="${INPUT_UPX:-}" +case "${upx}" in + true) upx=1 ;; + false) upx='' ;; + *) bail "'upx' input option must be 'true' or 'false': '${upx}'" ;; +esac + bin_name="${INPUT_BIN:?}" bin_names=() if [[ -n "${bin_name}" ]]; then @@ -386,7 +393,7 @@ case "${INPUT_TARGET:-}" in esac # Compress binaries with UPX -if [[ "${INPUT_UPX:-}" = "true" ]]; then +if [[ -n "$upx" ]]; then compress_binaries() { for bin_exe in "${bins[@]}"; do x upx --best "${target_dir}/${bin_exe}" @@ -435,7 +442,7 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/ filenames=("${bins[@]}") fi for bin_exe in "${bins[@]}"; do - if [[ -n "${bin_leading_dir}" ]]; then + if [[ -n "${bin__dir}" ]]; then x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}/${bin_leading_dir}"/ else x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}"/ From 93b0e38f7f04a3296938f6c3c574da56d545c14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 18:00:50 +0100 Subject: [PATCH 07/14] Fix error --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index f5d51d01..15ed2368 100755 --- a/main.sh +++ b/main.sh @@ -442,7 +442,7 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/ filenames=("${bins[@]}") fi for bin_exe in "${bins[@]}"; do - if [[ -n "${bin__dir}" ]]; then + if [[ -n "${bin_dir}" ]]; then x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}/${bin_leading_dir}"/ else x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}"/ From 07263ca4acb6db36b0dcf3ee3d9422891ac13431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 18:01:56 +0100 Subject: [PATCH 08/14] Fix --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index 15ed2368..6d76b986 100755 --- a/main.sh +++ b/main.sh @@ -442,7 +442,7 @@ if [[ "${INPUT_TAR/all/${platform}}" == "${platform}" ]] || [[ "${INPUT_ZIP/all/ filenames=("${bins[@]}") fi for bin_exe in "${bins[@]}"; do - if [[ -n "${bin_dir}" ]]; then + if [[ -n "${bin_leading_dir}" ]]; then x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}/${bin_leading_dir}"/ else x cp -- "${target_dir}/${bin_exe}" "${tmpdir}/${archive}"/ From 0b485646cd42bb5708bcdec0e198e97a32891d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 17 Dec 2024 18:20:19 +0100 Subject: [PATCH 09/14] Fix lint --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index 6d76b986..07bcbb0a 100755 --- a/main.sh +++ b/main.sh @@ -393,7 +393,7 @@ case "${INPUT_TARGET:-}" in esac # Compress binaries with UPX -if [[ -n "$upx" ]]; then +if [[ -n "${upx}" ]]; then compress_binaries() { for bin_exe in "${bins[@]}"; do x upx --best "${target_dir}/${bin_exe}" From 6968098ee82442427486955be8c0acc5b350d6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Dec 2024 14:21:03 +0100 Subject: [PATCH 10/14] Try `aarch64-unknown-linux-gnu` with cargo --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05cd5878..a105d5c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' - upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' }} + upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' @@ -123,7 +123,10 @@ jobs: printf 'outputs.md5 should be a file\n' test -f "${{ steps.upload-rust-binary-action.outputs.md5 }}" - name: Check UPX - if: startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && matrix.target != 'aarch64-unknown-linux-gnu' + if: | + startsWith(matrix.os, 'ubuntu-') && + matrix.target != 'x86_64-pc-windows-gnu' && + (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') run: | printf 'binary should be compressed with UPX\n' target_dir="./test-crate/target/release" From 4aba2136248e2ef9f92c8c7154bd57670b94c2f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Dec 2024 14:38:05 +0100 Subject: [PATCH 11/14] Try `x86_64-pc-windows-gnu` --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a105d5c4..14d015d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' - upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') }} + upx: ${{ startsWith(matrix.os, 'ubuntu-') && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' @@ -125,13 +125,14 @@ jobs: - name: Check UPX if: | startsWith(matrix.os, 'ubuntu-') && - matrix.target != 'x86_64-pc-windows-gnu' && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') run: | printf 'binary should be compressed with UPX\n' target_dir="./test-crate/target/release" tar -C "$target_dir" -xf "${{ steps.upload-rust-binary-action.outputs.tar }}" - test -n "$(file "$target_dir/test-crate" | grep 'no section header')" + target_file="$target_dir/test-crate" + [ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ] && target_file="$target_file.exe" + test -n "$(file "$target_file" | grep 'no section header')" - name: Check b2 output if: ${{ contains(matrix.checksums || 'b2,sha256,sha512,sha1,md5', 'b2') }} run: | From e1759a2fa00418b60968d423e68e68e0e040f41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Dec 2024 14:40:28 +0100 Subject: [PATCH 12/14] Debug --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14d015d9..a33253a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,6 +132,7 @@ jobs: tar -C "$target_dir" -xf "${{ steps.upload-rust-binary-action.outputs.tar }}" target_file="$target_dir/test-crate" [ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ] && target_file="$target_file.exe" + file "$target_file" test -n "$(file "$target_file" | grep 'no section header')" - name: Check b2 output if: ${{ contains(matrix.checksums || 'b2,sha256,sha512,sha1,md5', 'b2') }} From 7db878298f980d04c29550cd24952b57f165ecee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Dec 2024 14:43:50 +0100 Subject: [PATCH 13/14] Debug --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a33253a9..c303e6f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: codesign: '-' codesign-prefix: 'com.example.' codesign-options: 'runtime' - upx: ${{ startsWith(matrix.os, 'ubuntu-') && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') }} + upx: ${{ startsWith(matrix.os, 'ubuntu-') && matrix.target != 'x86_64-pc-windows-gnu' && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') }} - name: Check action outputs run: | printf 'outputs.archive should not be empty\n' From b34daee8cc2fb0ce3f04aede82c4be3929895d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Dec 2024 14:48:24 +0100 Subject: [PATCH 14/14] Revert --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c303e6f5..f3cc9ad4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,14 +125,13 @@ jobs: - name: Check UPX if: | startsWith(matrix.os, 'ubuntu-') && + matrix.target != 'x86_64-pc-windows-gnu' && (matrix.target != 'aarch64-unknown-linux-gnu' || matrix.build_tool == 'cargo') run: | printf 'binary should be compressed with UPX\n' target_dir="./test-crate/target/release" tar -C "$target_dir" -xf "${{ steps.upload-rust-binary-action.outputs.tar }}" target_file="$target_dir/test-crate" - [ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ] && target_file="$target_file.exe" - file "$target_file" test -n "$(file "$target_file" | grep 'no section header')" - name: Check b2 output if: ${{ contains(matrix.checksums || 'b2,sha256,sha512,sha1,md5', 'b2') }}