File: check-size.sh

package info (click to toggle)
golang-github-checkpoint-restore-checkpointctl 1.3.0%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 628 kB
  • sloc: ansic: 208; makefile: 172; sh: 40
file content (51 lines) | stat: -rwxr-xr-x 1,575 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# A shell script to check if the binary size
# has increased beyond a certain threshold
# across commits. Meant to be used in CI with
# git rebase <base branch>^ -x check-size.sh

BIN_NAME=checkpointctl
PREV_SIZE_FILE=prev_size
# Maximum allowable size difference, in bytes
MAX_DIFF=51200

# Build the checkpointctl binary. If the commit is not self-contained,
# the build will fail, in which case there is no point checking for a
# change in the size of the binary.
if ! make; then
	echo "ERROR: Compilation failed at $(git rev-parse --short HEAD)"
	echo "Make sure that the compilation is successful for each commit."
	exit 1
fi

# Fail fast on errors
set -e

# Store the binary size
BIN_SIZE=$(stat -c%s "$BIN_NAME")
# Print the size along with the commit hash
echo "BINARY SIZE ($(git rev-parse --short HEAD)): $BIN_SIZE"

if [[ -f "$PREV_SIZE_FILE" ]]; then
	# Read the previous size from the file
	PREV_SIZE=$(cat "$PREV_SIZE_FILE")
	# Calculate the difference between current and previous size
	DIFF=$((BIN_SIZE - PREV_SIZE))
	if [[ $DIFF -gt $MAX_DIFF ]]; then
		echo "FAIL: size difference of $DIFF B exceeds limit $MAX_DIFF B"
		exit 1
	else
		echo "PASS: size difference of $DIFF B within limit $MAX_DIFF B"
	fi
else
	# This means this is the first run of the script.
	# The original file size will be stored, and used
	# to compare against subsequent values ahead.
	echo "No previous size present, storing current size"
	echo "$BIN_SIZE" > "$PREV_SIZE_FILE"
fi

# Remove the binary to ensure it is
# built again with the next commit
rm -f $BIN_NAME