Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not compress darwin arm64 binary #714

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:-""}"