Skip to content

Commit 1e1b884

Browse files
committed
ci: verify build version during build
1 parent 92f04c5 commit 1e1b884

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ endif
5858
ifndef VERSION
5959
$(error VERSION is not set)
6060
endif
61+
./verify_build_version.sh $(VERSION)
6162
mkdir -p $(CURR_DIR)/target/bin
6263
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -x -ldflags='-s -w' -o $(CURR_DIR)/target/bin ./...
6364
@echo "[INFO] Successfully built git-team version v$(VERSION)"

acceptance-tests.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COPY src ./src
1414
COPY main.go .
1515

1616
COPY Makefile .
17+
COPY verify_build_version.sh .
1718
RUN make build
1819

1920
# ----------------------------------------------------------------- #

hookscript-tests.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COPY src ./src
1414
COPY main.go .
1515

1616
COPY Makefile .
17+
COPY verify_build_version.sh .
1718
RUN make build
1819

1920
# ----------------------------------------------------------------- #

verify_build_version.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
if [ -z "${1}" ]; then
4+
>&2 printf "error: no build version provided\n"
5+
exit 1
6+
fi
7+
8+
if [ ! `/usr/bin/env git rev-parse --is-inside-work-tree 2>/dev/null` ]; then
9+
>&2 printf "warn: not inside a git project, build version check skipped\n"
10+
exit 0
11+
fi
12+
13+
BUILD_VERSION=$1
14+
DERIVED_BUILD_VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')
15+
16+
if [ "${BUILD_VERSION}" != "${DERIVED_BUILD_VERSION}" ]; then
17+
>&2 printf "error: provided build version '${BUILD_VERSION}' does not match version derived from git project '${DERIVED_BUILD_VERSION}'\n"
18+
exit 1
19+
fi
20+
21+
printf "info: build version OK\n"
22+
exit 0

0 commit comments

Comments
 (0)