weather/ci-build.sh

61 lines
1.0 KiB
Bash
Raw Permalink Normal View History

2020-04-26 10:39:15 +02:00
#!/bin/bash
PROJECTNAME=weather
RELEASENAME=${PROJECTNAME}
VERSION="0"
GOOPTIONS="-mod=vendor"
SRCFILES=cmd/weather/*.go
build() {
2020-12-04 20:04:44 +01:00
echo "Begin of build"
2020-04-26 10:39:15 +02:00
if [[ ! -z $DRONE_TAG ]]
then
2020-12-04 20:04:44 +01:00
echo "Drone tag set, let's do a release"
2020-04-26 10:39:15 +02:00
VERSION=$DRONE_TAG
2020-12-04 20:04:44 +01:00
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
2020-04-26 10:39:15 +02:00
elif [[ ! -z $DRONE_TAG ]]
then
2020-12-04 20:04:44 +01:00
echo "Drone not set, let's only do a build"
2020-04-26 10:39:15 +02:00
VERSION=$DRONE_COMMIT
fi
if [[ ! -z $VERSION && ! -z $GOOS && ! -z $GOARCH ]]
then
2020-12-04 20:04:44 +01:00
echo "Let's set a release name"
2020-04-26 10:39:15 +02:00
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
fi
2020-12-04 20:04:44 +01:00
echo "Building project"
2020-04-26 10:39:15 +02:00
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
2020-12-04 20:04:44 +01:00
2020-04-26 10:39:15 +02:00
if [[ ! -z $DRONE_TAG ]]
then
2020-12-04 20:04:44 +01:00
echo "Let's make archives"
mkdir -p /build
tar -czvf /build/${RELEASENAME}.tar.gz ${PROJECTNAME}
2020-04-26 10:39:15 +02:00
fi
2020-12-04 20:04:44 +01:00
echo "Removing binary file"
2020-04-26 10:39:15 +02:00
rm ${PROJECTNAME}
2020-12-04 20:04:44 +01:00
echo "End of build"
2020-04-26 10:39:15 +02:00
}
clean() {
rm -rf $RELEASEDIR
}
case $1 in
"build")
build
;;
"clean")
clean
;;
*)
2020-12-04 20:04:44 +01:00
echo "No options choosen"
exit 1
2020-04-26 10:39:15 +02:00
;;
esac