refactor: Reduce zb binary size (#1783)

Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
Alexei Dodon
2023-09-13 10:28:14 +03:00
committed by GitHub
parent 98ab43f6ef
commit 48bf7f69f8
17 changed files with 243 additions and 152 deletions
+73
View File
@@ -0,0 +1,73 @@
name: "Check binary size increase"
on:
pull_request:
branches: [main]
permissions: read-all
jobs:
compare-binary-sizes:
runs-on: ubuntu-latest
name: compare-with-main
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
cache: false
go-version: 1.20.x
- name: Checkout zot (main branch)
run: |
mkdir -p $GITHUB_WORKSPACE/zot_main
git clone https://github.com/project-zot/zot zot_main/
- name: Check if zot-minimal binary increased with more than 1%
run: |
echo "Building zot-minimal and check size"
cd $GITHUB_WORKSPACE
make binary-minimal
BINSIZE=$(stat -c%s "bin/zot-linux-amd64-minimal")
echo "Building zot-minimal on main branch and check size"
cd zot_main
make binary-minimal
BINSIZE_MAIN=$(stat -c%s "bin/zot-linux-amd64-minimal")
echo "PR binary size: $BINSIZE Bytes"
echo "main branch binary size: $BINSIZE_MAIN Bytes"
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zot-minimal binary size is not affected by PR" && exit 0
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
echo "zot minimal binary increased by $PERCENTAGE% comparing with main"; \
if ((`bc <<< "$PERCENTAGE>=1.0"`)); then exit 1; fi; \
else \
PERCENTAGE=$(echo "scale=2; (($BINSIZE_MAIN-$BINSIZE)*100)/$BINSIZE_MAIN" | bc); \
echo "zot minimal binary decreased by $PERCENTAGE% comparing with main"; \
fi
- if: always()
name: Check if zb binary increased with more than 1%
run: |
echo "Building zb and check size"
cd $GITHUB_WORKSPACE
make bench
BINSIZE=$(stat -c%s "bin/zb-linux-amd64")
echo "Building zb on main branch and check size"
cd zot_main
make bench
BINSIZE_MAIN=$(stat -c%s "bin/zb-linux-amd64")
echo "PR binary size: $BINSIZE Bytes"
echo "main branch binary size: $BINSIZE_MAIN Bytes"
[[ $BINSIZE -eq $BINSIZE_MAIN ]] && echo "zb binary size is not affected by PR" && exit 0
if [[ $BINSIZE -gt $BINSIZE_MAIN ]]; then \
PERCENTAGE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc); \
echo "zb binary increased by $PERCENTAGE% comparing with main"; \
if ((`bc <<< "$PERCENTAGE>=1.0"`)); then exit 1; fi; \
else \
PERCENTAGE=$(echo "scale=2; (($BINSIZE_MAIN-$BINSIZE)*100)/$BINSIZE_MAIN" | bc); \
echo "zb binary decreased by $PERCENTAGE% comparing with main"; \
fi
-3
View File
@@ -36,9 +36,6 @@ jobs:
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
# Optional: if set to true then the action will use pre-installed Go.
skip-go-installation: true
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
-40
View File
@@ -1,40 +0,0 @@
name: "zot minimal binary size"
on:
pull_request:
branches: [main]
permissions: read-all
jobs:
zot-minimal-size:
runs-on: ubuntu-latest
name: compare-binary-size
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
cache: false
go-version: 1.20.x
- name: Check if zot-minimal binary increased with more than 1%
run: |
echo "Building zot-minimal and check size"
cd $GITHUB_WORKSPACE
make binary-minimal
BINSIZE=$(stat -c%s "bin/zot-linux-amd64-minimal")
echo "Building zot-minimal on main branch and check size"
mkdir -p zot_main
git clone https://github.com/project-zot/zot zot_main/
cd zot_main
make binary-minimal
BINSIZE_MAIN=$(stat -c%s "bin/zot-linux-amd64-minimal")
cd $GITHUB_WORKSPACE && rm -rf zot_main
[[ $BINSIZE -gt $BINSIZE_MAIN ]] || exit 0
echo "PR changes increased size of zot-minimal binary"
echo "PR binary size: $BINSIZE Bytes"
echo "main branch binary size: $BINSIZE_MAIN Bytes"
PERCENTACE=$(echo "scale=2; (($BINSIZE-$BINSIZE_MAIN)*100)/$BINSIZE_MAIN" | bc)
if ((`bc <<< "$PERCENTACE>=1.0"`)); then echo "zot minimal binary increased by $PERCENTACE% comparing with main"; exit 1; fi