Skip to content

Commit 453a020

Browse files
authored
Refactor script of update_docs. So it generates correct version in doc (#2009)
Signed-off-by: Lubron Zhan <[email protected]>
1 parent 19a97b8 commit 453a020

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

scripts/build_funcs.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ HOST_GOOS=$(go env GOOS)
2121
HOST_GOARCH=$(go env GOARCH)
2222

2323
# --tags allows detecting non-annotated tags as well as annotated ones
24-
GIT_VERSION=$(git describe --always --dirty --tags)
24+
GIT_VERSION=${VERSION:-"$(git describe --always --dirty --tags)"}
25+
# PRE_DEFINED_VERSION is used when building binary and tagging image. Fallback to GIT_VERSION if not set.
26+
# This is useful when automate creating documents. Otherwise the version in the doc will be git shas.
27+
PRE_DEFINED_VERSION=${PRE_DEFINED_VERSION:-$GIT_VERSION}
2528
IMAGE_VERSION=$(git describe --always --dirty --tags)
2629
IMAGE_TAG=$(echo "$IMAGE_VERSION" | cut -d. -f1,2)
2730
IMAGE_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/\///g')
@@ -143,7 +146,7 @@ gen_dockerfile_for_os_arch(){
143146
# Onlhy doing one arch so this could be hardcoded, likewise we could handle the
144147
# base image differently. Wanted something here for parity with linux in case we expand it though.
145148
sed -e 's|BINARY|build/windows/amd64/sonobuoy.exe|g' DockerfileWindows > "$dockerfile"
146-
else
149+
else
147150
echo "Windows ARCH unknown"
148151
fi
149152
else
@@ -155,7 +158,7 @@ gen_dockerfile_for_os_arch(){
155158
build_container_os_arch_version(){
156159
dockerfile="build/$1/$2/Dockerfile"
157160
gen_dockerfile_for_os_arch "$1" "$2"
158-
if [ "$1" = "windows" ]; then
161+
if [ "$1" = "windows" ]; then
159162
buildx_container_windows_version $3
160163
else
161164
build_container_dockerfile_arch "$dockerfile" $2
@@ -178,7 +181,7 @@ windows_containers() {
178181

179182
# Builds a binary for a specific goos/goarch.
180183
build_binary_GOOS_GOARCH() {
181-
LDFLAGS="-s -w -X $GOTARGET/pkg/buildinfo.Version=$GIT_VERSION -X $GOTARGET/pkg/buildinfo.GitSHA=$GIT_REF_LONG"
184+
LDFLAGS="-s -w -X $GOTARGET/pkg/buildinfo.Version=$PRE_DEFINED_VERSION -X $GOTARGET/pkg/buildinfo.GitSHA=$GIT_REF_LONG"
182185
args=(${VERBOSE:+-v} -ldflags "${LDFLAGS}" "$GOTARGET")
183186
if [ "$VERBOSE" ]; then args+=("-v"); fi;
184187

@@ -209,7 +212,7 @@ build_binaries() {
209212

210213
# Builds sonobuoy using the local goos/goarch.
211214
native() {
212-
LDFLAGS="-s -w -X $GOTARGET/pkg/buildinfo.Version=$GIT_VERSION -X $GOTARGET/pkg/buildinfo.GitSHA=$GIT_REF_LONG"
215+
LDFLAGS="-s -w -X $GOTARGET/pkg/buildinfo.Version=$PRE_DEFINED_VERSION -X $GOTARGET/pkg/buildinfo.GitSHA=$GIT_REF_LONG"
213216
args=(-ldflags "${LDFLAGS}" "$GOTARGET")
214217
CGO_ENABLED=0 GOOS="$HOST_GOOS" GOARCH="$HOST_GOARCH" go build -buildvcs=false -o sonobuoy "${args[@]}"
215218
mkdir -p ./build/$HOST_GOOS/$HOST_GOARCH

scripts/update_docs.sh

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ done
3131
# Using local build for this portion rather than docer to avoid having to use a go build image, long build with go modules, etc.
3232
# Refresh CLI docs to ensure the docs are up to date when copied for the next version.
3333
echo "Refreshing CLI docs in main docs..."
34+
# Set PRE_DEFINED_VERSION so that sonobuoy is built with this exact version, not version of a dirty git tag.
35+
PRE_DEFINED_VERSION="$VERSION"
3436
source "${DIR}/scripts/build_funcs.sh"; update_cli_docs
3537
echo "Done. Beginning to generate docs for specified version..."
3638

0 commit comments

Comments
 (0)