Skip to content

Commit

Permalink
Do not compress darwin arm64 binary (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejmalecki authored May 10, 2022
1 parent 5c7e47a commit 4ca78b1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
27 changes: 13 additions & 14 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ builds:
- goos: windows
goarch: arm64
hooks: &build-hooks
# Install upx first, https://github.com/upx/upx/releases
post: upx -9 "{{ .Path }}"
post: ./hack/compress-release-binary.sh {{ .Path }}
main: ./cmd/cli
binary: 'capact'
binary: "capact"
ldflags:
- -s -w -X capact.io/capact/cmd/cli/cmd.Version={{.Version}} -X capact.io/capact/cmd/cli/cmd.Revision={{.ShortCommit}} -X capact.io/capact/cmd/cli/cmd.BuildDate={{.Date}} -X capact.io/capact/cmd/cli/cmd.Branch={{.Branch}}

Expand All @@ -44,40 +43,40 @@ builds:
ignore: *build-ignore
hooks: *build-hooks
main: ./cmd/populator
binary: 'populator'
binary: "populator"

archives:
- id: capact-archive
name_template: &archives-name-template '{{ .Binary }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
name_template: &archives-name-template "{{ .Binary }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
format: &archives-format binary
builds:
- capact
- capact

- id: populator-archive
name_template: *archives-name-template
format: *archives-format
builds:
- populator
- populator

brews:
- name: capact
ids:
- capact-archive
- capact-archive
homepage: &homebrew-homepage https://github.com/capactio/homebrew-tap
description: "Capact CLI is a command-line tool, which manages Capact resources."
license: "Apache License 2.0"
tap: &homebrew-tap
owner: capactio
name: homebrew-tap
commit_author: &homebrew-commit-author
name: Capact Bot
email: capactbot@capact.io
name: Capact Bot
email: capactbot@capact.io
test: |
system "#{bin}/capact version"
- name: populator
ids:
- populator-archive
- populator-archive
homepage: *homebrew-homepage
description: "Populator is a command-line tool, which helps to populate various Capact content."
license: "Apache License 2.0"
Expand All @@ -97,7 +96,7 @@ dockers:
- "ghcr.io/capactio/tools/capact-cli:v{{ .Major }}"

checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"

snapshot:
name_template: "{{ .Tag }}-next"
Expand All @@ -106,8 +105,8 @@ changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"

dist: bin

Expand Down
28 changes: 28 additions & 0 deletions hack/compress-release-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# This script compresses binary file built by goreleaser.
#
# Requires passing path to the binary file as an argument.
# Requires UPX to be installed.

# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap

main() {
number_of_arguments=$1
file_path=$2

if [[ $number_of_arguments -lt 1 ]]; then
echo "Path to the binary file not provided"
exit 1
fi

# Do not compress darwin arm64 binary as it causes UPX to output broken file
if ! ( grep -q "darwin" <<< "$file_path" && grep -q "arm64" <<< "$file_path" ); then
upx -9 "$file_path"
fi
}

main $# "${1:-""}"

0 comments on commit 4ca78b1

Please sign in to comment.