Skip to content

ci: strip binaries and check size #3092

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

Merged
merged 3 commits into from
Apr 27, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
fetch-depth: 1
- name: Build binaries
run: ./scripts/build.sh
- name: Print binaries size
run: ls -lh ./bin
- name: Check binary size
run: ./scripts/check-size.sh ./bin/*linux-x86_64

docker-tests:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ builds:
- goos: darwin
goarch: 386
ldflags:
- -s -w
- -X main.Version={{ .Version }}
- -X main.BuildDate={{ .Date }}
- -X main.GitBranch={{ .Branch }}
Expand Down
1 change: 1 addition & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export CGO_ENABLED=0
LDFLAGS=(
-s
-w
-extldflags
-static
Expand Down
28 changes: 28 additions & 0 deletions scripts/check-size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#/bin/env bash

MAX_BINARY_SIZE=25000000

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

function usage() {
echo "Usage:"
echo " $SCRIPT_DIR [BINARY_FILE]"

echo ""
exit "$1";
}

if [[ $# -ne 1 ]]; then
usage
fi

BINARY_SIZE=$(stat -c %s $1)

echo "Binary size: $BINARY_SIZE"

if (( $BINARY_SIZE > $MAX_BINARY_SIZE )); then
echo "Size is greater than limit"
exit 1
else
echo "Size is valid"
fi