forked from guidowb/cf-targets-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-all.sh
executable file
·78 lines (60 loc) · 2.59 KB
/
build-all.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
BUILD=$(date -Iseconds -u)
PRERELEASE="dev"
if [[ "$1" = "release" ]] ; then
PRERELEASE=""
TAG="$2"
: ${TAG:?"Usage: build_all.sh [release] [TAG]"}
git rev-parse --verify --quiet $TAG > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$TAG exists, remove it or increment"
exit 1
fi
VERSION_CORE=$(echo "$TAG" | sed 's/^v//')
else
VERSION_CORE=$(git describe --tags --abbrev=0 | sed 's/^v//')
fi
VERSION_CORE=(${VERSION_CORE//./ })
declare LINUX64_SHA1 OSX_AMD64_SHA1 OSX_ARM64_SHA1
function build_semver() {
TAG="${VERSION_CORE[0]}.${VERSION_CORE[1]}.${VERSION_CORE[2]}"
[[ -n ${PRERELEASE} ]] && TAG="${TAG}-${PRERELEASE}"
# [[ -n ${BUILD} ]] && TAG="${TAG}+${BUILD}"
}
function build_for() {
echo "Building plugin for $GOOS $GOARCH..."
eval "${CHECKSUM}=\"\""
VERSION_FLAGS="-X 'main.Major=${VERSION_CORE[0]}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.Minor=${VERSION_CORE[1]}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.Patch=${VERSION_CORE[2]}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.PrRls=${PRERELEASE}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.Build=${BUILD}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.GoArch=${GOARCH}'"
VERSION_FLAGS="${VERSION_FLAGS} -X 'main.GoOs=${GOOS}'"
CGO_ENABLED=0 GOARCH=${GOARCH} GOOS=${GOOS} go build -o ./bin/cf-targets-plugin-${GOOS}-${GOARCH} -ldflags "${VERSION_FLAGS}"
if [[ $? -eq 0 ]]; then
eval "${CHECKSUM}=\"$(openssl sha1 -r bin/cf-targets-plugin-${GOOS}-${GOARCH})\""
else
eval "${CHECKSUM}=\"cf-targets-plugin-${GOOS}-${GOARCH} failed to compile\""
fi
}
mkdir -p bin
CHECKSUM="LINUX64_SHA1" GOOS=linux GOARCH=amd64 build_for
CHECKSUM="OSX_AMD64_SHA1" GOOS=darwin GOARCH=amd64 build_for
CHECKSUM="OSX_ARM64_SHA1" GOOS=darwin GOARCH=arm64 build_for
CHECKSUM="WIN64_SHA1" GOOS=windows GOARCH=amd64 build_for
build_semver
cat repo-index.yml |
sed -e "s:osx-amd64-sha1:$OSX_AMD64_SHA1:" -e "s:osx-arm64-sha1:$OSX_ARM64_SHA1:" \
-e "s:win64-sha1:$WIN64_SHA1:" -e "s:linux64-sha1:$LINUX64_SHA1:" \
-e "s:_TAG_:$TAG:" -e "s/_BUILD-TAG_/$BUILD/"
#Link local build to give developer easy access to the plugin for installing
localExecutable="bin/cf-targets-plugin-$(go env GOOS)-$(go env GOARCH)"
rm -f ./cf-targets-plugin
[[ -x ${localExecutable} ]] && ln -s ${localExecutable} ./cf-targets-plugin
if [[ "$1" = "release" ]] ; then
git commit -am "Build version $TAG"
git tag -a $TAG
echo "Tagged release, 'git push --tags' to move it to github, and copy the output above"
echo "to the cli repo you plan to deploy in"
fi