Skip to content

Commit

Permalink
Merge pull request #14 from puellanivis/patch/masher-updates
Browse files Browse the repository at this point in the history
Masher updates
  • Loading branch information
puellanivis authored Sep 26, 2019
2 parents 1a642e6 + 2d44a0a commit 588cabb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
26 changes: 20 additions & 6 deletions masher/mash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=""
Expand All @@ -180,9 +191,12 @@ fi
PROJECT="${PWD##*/}"
if [[ -n $BUILDSTAMP ]]; then
DEPS=$( go list -f "{{.Deps}}" | grep -c -e "\<lib/util\>" )
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

Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions masher/masher
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%%,*}
Expand Down Expand Up @@ -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=""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 588cabb

Please sign in to comment.