qrz/ci-build.sh

67 lines
1.2 KiB
Bash
Raw Normal View History

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"
2021-11-13 11:49:43 +01:00
SRCFILES=cmd/${PROJECTNAME}/*.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"
2021-11-13 11:51:23 +01:00
if [[ ! -z ${DRONE_TAG} ]]
2020-04-12 15:25:09 +02:00
then
2020-12-05 17:44:23 +01:00
echo "Drone tag set, let's do a release"
2021-11-13 11:51:23 +01:00
VERSION=${DRONE_TAG}
2020-12-05 17:44:23 +01:00
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
2021-11-13 12:58:33 +01:00
else
2020-12-05 17:44:23 +01:00
echo "Drone not set, let's only do a build"
2021-11-13 11:51:23 +01:00
VERSION=${DRONE_COMMIT}
2020-04-12 15:25:09 +02:00
fi
2021-11-13 11:51:23 +01:00
if [[ ! -z ${VERSION} && ! -z ${GOOS} && ! -z ${GOARCH} ]]
2020-04-12 15:25:09 +02:00
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:47:48 +02:00
echo "Building project"
go generate ${SRCFILES}
2020-04-26 10:15:14 +02:00
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
2021-11-13 11:51:23 +01:00
if [[ ! -z ${DRONE_TAG} ]]
2020-04-12 15:25:09 +02:00
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() {
2021-11-13 11:51:23 +01:00
rm -rf ${RELEASEDIR}
2021-11-13 11:49:43 +01:00
for i in ${PROJECTNAME} "cmd/${PROJECTNAME}/packrd" "cmd/${PROJECTNAME}/main-packr.go"
2020-12-26 17:31:13 +01:00
do
2021-11-13 11:51:23 +01:00
rm -rf ${i}
2020-12-26 17:31:13 +01:00
done
2020-04-12 15:25:09 +02:00
}
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