2020-04-07 23:43:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-12-04 22:30:56 +01:00
|
|
|
set -e
|
|
|
|
|
2020-04-12 16:35:17 +02:00
|
|
|
PROJECTNAME=qrz
|
|
|
|
RELEASENAME=${PROJECTNAME}
|
2020-04-12 15:25:09 +02:00
|
|
|
VERSION="0"
|
2020-04-08 00:13:49 +02:00
|
|
|
|
2020-04-12 16:35:17 +02:00
|
|
|
GOOPTIONS="-mod=vendor"
|
2020-04-12 15:25:09 +02:00
|
|
|
SRCFILES=cmd/qrz/*.go
|
2020-04-07 23:47:40 +02:00
|
|
|
|
2020-04-12 15:25:09 +02:00
|
|
|
build() {
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Begin of build"
|
2020-04-12 15:25:09 +02:00
|
|
|
if [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Drone tag set, let's do a release"
|
2020-04-12 15:25:09 +02:00
|
|
|
VERSION=$DRONE_TAG
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
|
2020-04-12 15:25:09 +02:00
|
|
|
elif [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Drone not set, let's only do a build"
|
2020-04-12 15:25:09 +02:00
|
|
|
VERSION=$DRONE_COMMIT
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z $VERSION && ! -z $GOOS && ! -z $GOARCH ]]
|
|
|
|
then
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Let's set a release name"
|
2020-04-12 16:35:17 +02:00
|
|
|
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
|
2020-04-12 15:25:09 +02:00
|
|
|
fi
|
2020-05-09 19:09:27 +02:00
|
|
|
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Getting packr2 and building embedded files"
|
|
|
|
go get -u github.com/gobuffalo/packr/v2/packr2
|
2020-05-09 19:20:11 +02:00
|
|
|
|
2020-05-09 19:47:48 +02:00
|
|
|
echo "Building project"
|
2020-12-08 21:05:30 +01:00
|
|
|
go generate ${SRCFILES}
|
2020-04-26 10:15:14 +02:00
|
|
|
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
|
2020-05-09 19:09:27 +02:00
|
|
|
|
2020-04-12 15:25:09 +02:00
|
|
|
if [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "Let's make archives"
|
|
|
|
mkdir -p /build
|
|
|
|
tar -czvf /build/${RELEASENAME}.tar.gz ${PROJECTNAME}
|
2020-04-12 15:25:09 +02:00
|
|
|
fi
|
2020-05-09 19:47:48 +02:00
|
|
|
|
|
|
|
echo "Removing binary file"
|
2020-04-26 10:15:14 +02:00
|
|
|
rm ${PROJECTNAME}
|
2020-12-05 17:44:23 +01:00
|
|
|
|
|
|
|
echo "End of build"
|
2020-04-12 15:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
|
|
|
rm -rf $RELEASEDIR
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
"build")
|
|
|
|
build
|
|
|
|
;;
|
|
|
|
"clean")
|
|
|
|
clean
|
|
|
|
;;
|
|
|
|
*)
|
2020-12-05 17:44:23 +01:00
|
|
|
echo "No options choosen"
|
|
|
|
exit 1
|
2020-04-12 15:25:09 +02:00
|
|
|
;;
|
2020-12-04 22:30:56 +01:00
|
|
|
esac
|