diff --git a/masher/mash.sh b/masher/mash.sh index 80ab2b4..f9622ec 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -8,12 +8,18 @@ while [[ "$#" -gt 0 ]]; do --cache=*) export GOCACHE="$val" ;; + --buildver=*) + BUILDVER="$val" + ;; --timestamp=*) TIMESTAMP="$val" ;; --id=*) ID="$val" ;; + --private=*) + export GOPRIVATE="$val" + ;; --linux) LINUX="true" @@ -68,6 +74,11 @@ while [[ "$#" -gt 0 ]]; do shift done +if [[ -d ./vendor ]]; then + export GOFLAGS="-mod=vendor" + VENDOR="true" +fi + if [[ $ESCAPE == "true" ]]; then exec /bin/bash "$@" exit 1 @@ -153,7 +164,7 @@ if [[ $PACKAGE != "main" ]]; then exit 0 fi -if [[ $NOCOMPILE != "true" ]]; then +if [[ $VENDOR != "true" && $NOCOMPILE != "true" ]]; then echo getting dependencies... if [[ -r Gopkg.toml ]]; then DEP_UP="" @@ -180,9 +191,12 @@ fi PROJECT="${PWD##*/}" if [[ -n $BUILDSTAMP ]]; then DEPS=$( go list -f "{{.Deps}}" | grep -c -e "\" ) - GOFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" + LDFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" + if [[ $BUILDVER != "" ]]; then + LDFLAGS="$LDFLAGS -X main.Version=$BUILDVER" + fi if [[ $DEPS -ne 0 ]]; then - GOFLAGS="$GOFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP" + LDFLAGS="$LDFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP" fi fi @@ -196,7 +210,7 @@ if [[ $LINUX == "true" ]]; then OUT="bin/linux.x86_64" echo Compiling ${OUT}/${PROJECT} [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=linux GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${GOFLAGS}" || exit 1 + GOOS=linux GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${LDFLAGS}" || exit 1 [[ "$DEB" != "false" ]] && DEB="true" fi @@ -205,14 +219,14 @@ if [[ $DARWIN == "true" ]]; then OUT="bin/darwin.x86_64" echo Compiling ${OUT}/${PROJECT} [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=darwin GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${GOFLAGS}" || exit 1 + GOOS=darwin GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${LDFLAGS}" || exit 1 fi if [[ $WINDOWS == "true" ]]; then OUT="bin/windows.x86_64" echo Compiling ${OUT}/${PROJECT}.exe [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=windows GOARCH=amd64 go build -o "${OUT}/${PROJECT}.exe" "${GOFLAGS}" || exit 1 + GOOS=windows GOARCH=amd64 go build -o "${OUT}/${PROJECT}.exe" "${LDFLAGS}" || exit 1 fi if [[ ( $DEB == "true" ) && ( -r debian/control ) && ( -x bin/linux.x86_64/${PROJECT} ) ]]; then diff --git a/masher/masher b/masher/masher index 212b4f5..77f83d1 100755 --- a/masher/masher +++ b/masher/masher @@ -169,6 +169,7 @@ if [[ $? -eq 0 ]]; then HASHID=$(git rev-parse --short HEAD) HEAD=$(git symbolic-ref HEAD 2>> /dev/null || git rev-parse HEAD) BRANCH=$(basename ${HEAD}) + BUILD_VERSION=$(git describe --tag --abbrev=2 2> /dev/null) ;; esac else @@ -246,11 +247,19 @@ echo "PRJPATH='$PRJPATH'" echo "PROJECT='$PROJECT'" echo "BRANCH='$BRANCH'" echo "HASHID='$HASHID'" +if [[ -n "$BUILD_VERSION" ]]; then + echo "BUILD_VERSION='$BUILD_VERSION'" + BUILD_VERSION="--buildver=$BUILD_VERSION" +fi +if [[ -n "$GOPRIVATE" ]]; then + echo "PRIVATE='$GOPRIVATE'" + PRIVATE="--private=$GOPRIVATE" +fi TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S") echo Using image: $IMAGE -echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE --timestamp=$TIMESTAMP --id=$HASHID $@ +echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE $BUILD_VERSION --timestamp=$TIMESTAMP --id=$HASHID $@ DOCKER_VERSION="$(docker --version)" DOCKER_VERSION=${DOCKER_VERSION%%,*} @@ -284,8 +293,9 @@ LIBS="" [[ -d "${BASE}/.mash/cache" ]] || mkdir -p "${BASE}/.mash/cache" CACHE="--cache=${SRCROOT}/.mash/cache" -# vgo +# go modules [[ -d "${BASE}/.mash/mod" ]] || mkdir -p "${BASE}/.mash/mod" +[[ -d "${BASE}/.mash/sumdb" ]] || mkdir -p "${BASE}/.mash/sumdb" # godep stuff DEP_CACHE="" @@ -344,11 +354,12 @@ ${EXEC} docker run ${FLAGS} --rm \ --user "${RUNAS}" \ --volume "${BASE}:${SRCROOT}:rw" \ --volume "${BASE}/.mash/mod:/go/pkg/mod:rw" \ + --volume "${BASE}/.mash/sumdb:/go/pkg/sumdb:rw" \ $DEP_CACHE \ $LIBS \ --workdir "${SRCROOT}/${PRJPATH}" \ ${IMAGE} \ - /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 + /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE $BUILD_VERSION --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 if [[ $PROD == "true" ]]; then make push || exit 1