Skip to content

Commit 3252886

Browse files
authored
ci: strip binaries and check size (#3092)
1 parent 68609e8 commit 3252886

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
fetch-depth: 1
4747
- name: Build binaries
4848
run: ./scripts/build.sh
49+
- name: Print binaries size
50+
run: ls -lh ./bin
51+
- name: Check binary size
52+
run: ./scripts/check-size.sh ./bin/*linux-x86_64
4953

5054
docker-tests:
5155
runs-on: ubuntu-latest

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ builds:
2222
- goos: darwin
2323
goarch: 386
2424
ldflags:
25+
- -s -w
2526
- -X main.Version={{ .Version }}
2627
- -X main.BuildDate={{ .Date }}
2728
- -X main.GitBranch={{ .Branch }}

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export CGO_ENABLED=0
44
LDFLAGS=(
5+
-s
56
-w
67
-extldflags
78
-static

scripts/check-size.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#/bin/env bash
2+
3+
MAX_BINARY_SIZE=25000000
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
function usage() {
8+
echo "Usage:"
9+
echo " $SCRIPT_DIR [BINARY_FILE]"
10+
11+
echo ""
12+
exit "$1";
13+
}
14+
15+
if [[ $# -ne 1 ]]; then
16+
usage
17+
fi
18+
19+
BINARY_SIZE=$(stat -c %s $1)
20+
21+
echo "Binary size: $BINARY_SIZE"
22+
23+
if (( $BINARY_SIZE > $MAX_BINARY_SIZE )); then
24+
echo "Size is greater than limit"
25+
exit 1
26+
else
27+
echo "Size is valid"
28+
fi

0 commit comments

Comments
 (0)