2020-05-24 18:42:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-12-04 21:16:27 +01:00
|
|
|
set -e
|
|
|
|
|
2020-05-24 18:42:01 +02:00
|
|
|
PROJECTNAME=dip
|
|
|
|
RELEASENAME=${PROJECTNAME}
|
|
|
|
VERSION="0"
|
|
|
|
|
|
|
|
GOOPTIONS="-mod=vendor"
|
2020-12-04 21:05:10 +01:00
|
|
|
SRCFILES=cmd/dip/*.go
|
2020-05-24 18:42:01 +02:00
|
|
|
|
|
|
|
build() {
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Begin of build"
|
2020-05-24 18:42:01 +02:00
|
|
|
if [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Drone tag set, let's do a release"
|
2020-05-24 18:42:01 +02:00
|
|
|
VERSION=$DRONE_TAG
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "${PROJECTNAME} ${VERSION}" > /build/VERSION
|
2020-05-24 18:42:01 +02:00
|
|
|
elif [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Drone not set, let's only do a build"
|
2020-05-24 18:42:01 +02:00
|
|
|
VERSION=$DRONE_COMMIT
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z $VERSION && ! -z $GOOS && ! -z $GOARCH ]]
|
|
|
|
then
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Let's set a release name"
|
2020-05-24 18:42:01 +02:00
|
|
|
RELEASENAME=${PROJECTNAME}-${VERSION}-${GOOS}-${GOARCH}
|
|
|
|
fi
|
|
|
|
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Getting packr2 and building embedded files"
|
|
|
|
go get -u github.com/gobuffalo/packr/v2/packr2
|
|
|
|
packr2
|
2020-05-24 18:42:01 +02:00
|
|
|
|
|
|
|
echo "Building project"
|
|
|
|
go build -o ${PROJECTNAME} ${GOOPTIONS} ${SRCFILES}
|
|
|
|
|
|
|
|
if [[ ! -z $DRONE_TAG ]]
|
|
|
|
then
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "Let's make archives"
|
|
|
|
mkdir -p /build
|
|
|
|
tar -czvf /build/${RELEASENAME}.tar.gz ${PROJECTNAME}
|
2020-05-24 18:42:01 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Removing binary file"
|
|
|
|
rm ${PROJECTNAME}
|
2020-12-04 21:05:10 +01:00
|
|
|
|
|
|
|
echo "End of build"
|
2020-05-24 18:42:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
|
|
|
rm -rf $RELEASEDIR
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
"build")
|
|
|
|
build
|
|
|
|
;;
|
|
|
|
"clean")
|
|
|
|
clean
|
|
|
|
;;
|
|
|
|
*)
|
2020-12-04 21:05:10 +01:00
|
|
|
echo "No options choosen"
|
|
|
|
exit 1
|
2020-05-24 18:42:01 +02:00
|
|
|
;;
|
2020-12-04 21:05:10 +01:00
|
|
|
esac
|