build: try creating the go bin directory (#19862)

* Try creating the output directory to ensure it always exists

* Use GOBIN path over GOPATH/bin if it is set
This commit is contained in:
Robert 2023-04-17 17:57:17 -05:00 committed by GitHub
parent 42400699c0
commit 750bc180ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

3
changelog/19862.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
build: Prefer GOBIN when set over GOPATH/bin when building the binary
```

View File

@ -50,11 +50,13 @@ ${GO_CMD} build \
# Move all the compiled things to the $GOPATH/bin
OLDIFS=$IFS
IFS=: MAIN_GOPATH=($GOPATH)
IFS=: FIRST=($GOPATH) BIN_PATH=${GOBIN:-${FIRST}/bin}
IFS=$OLDIFS
rm -f ${MAIN_GOPATH}/bin/vault
cp bin/vault ${MAIN_GOPATH}/bin/
# Ensure the go bin folder exists
mkdir -p ${BIN_PATH}
rm -f ${BIN_PATH}/vault
cp bin/vault ${BIN_PATH}
# Done!
echo