2019-10-29 19:27:08 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
if [[ -z ${BINARY} ]] || [[ -z ${VERSION} ]]; then
|
|
|
|
echo "Missing required env var: BINARY=X VERSION=X $(basename $0)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-11-20 21:35:59 +02:00
|
|
|
|
2020-03-29 13:53:22 +02:00
|
|
|
# Check for Go version 1.14.*
|
2019-10-29 19:27:08 +02:00
|
|
|
GO_VERSION=$(go version | awk '{print $3}')
|
2020-03-29 13:53:22 +02:00
|
|
|
if [[ ! "${GO_VERSION}" =~ ^go1.14.* ]]; then
|
|
|
|
echo "Go version must be >= go1.14"
|
2019-10-29 19:27:08 +02:00
|
|
|
exit 1
|
2017-11-20 21:35:59 +02:00
|
|
|
fi
|
2019-10-29 19:27:08 +02:00
|
|
|
|
2019-11-26 18:38:22 +02:00
|
|
|
ARCHS=(darwin-amd64 linux-amd64 linux-arm64 linux-armv6 freebsd-amd64 windows-amd64)
|
2019-10-29 19:27:08 +02:00
|
|
|
|
|
|
|
mkdir -p release
|
|
|
|
|
|
|
|
# Create architecture specific release dirs
|
|
|
|
for ARCH in "${ARCHS[@]}"; do
|
2020-08-25 17:41:14 +02:00
|
|
|
mkdir -p release/${BINARY}-${VERSION}.${ARCH}
|
2019-10-29 19:27:08 +02:00
|
|
|
|
|
|
|
GO_OS=$(echo $ARCH | awk -F- '{print $1}')
|
|
|
|
GO_ARCH=$(echo $ARCH | awk -F- '{print $2}')
|
|
|
|
|
|
|
|
# Create architecture specific binaries
|
|
|
|
if [[ ${GO_ARCH} == "armv6" ]]; then
|
2020-01-28 11:05:04 +02:00
|
|
|
GO111MODULE=on GOOS=${GO_OS} GOARCH=arm GOARM=6 CGO_ENABLED=0 go build -ldflags="-X main.VERSION=${VERSION}" \
|
2020-08-25 17:41:14 +02:00
|
|
|
-o release/${BINARY}-${VERSION}.${ARCH}/${BINARY} github.com/oauth2-proxy/oauth2-proxy
|
2019-10-29 19:27:08 +02:00
|
|
|
else
|
2020-01-28 11:05:04 +02:00
|
|
|
GO111MODULE=on GOOS=${GO_OS} GOARCH=${GO_ARCH} CGO_ENABLED=0 go build -ldflags="-X main.VERSION=${VERSION}" \
|
2020-08-25 17:41:14 +02:00
|
|
|
-o release/${BINARY}-${VERSION}.${ARCH}/${BINARY} github.com/oauth2-proxy/oauth2-proxy
|
2019-10-29 19:27:08 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd release
|
|
|
|
|
|
|
|
# Create sha256sum for architecture specific binary
|
2020-08-25 17:41:14 +02:00
|
|
|
sha256sum ${BINARY}-${VERSION}.${ARCH}/${BINARY} > ${BINARY}-${VERSION}.${ARCH}-sha256sum.txt
|
2019-10-29 19:27:08 +02:00
|
|
|
|
|
|
|
# Create tar file for architecture specific binary
|
2020-08-25 17:41:14 +02:00
|
|
|
tar -czvf ${BINARY}-${VERSION}.${ARCH}.tar.gz ${BINARY}-${VERSION}.${ARCH}
|
2019-10-29 19:27:08 +02:00
|
|
|
|
|
|
|
cd ..
|
2017-11-20 21:35:59 +02:00
|
|
|
done
|