Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Created May 22, 2014 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfeidau/b9512187bdcfabbd3d2d to your computer and use it in GitHub Desktop.
Save wolfeidau/b9512187bdcfabbd3d2d to your computer and use it in GitHub Desktop.
Go project build files
#!/usr/bin/env bash
#
# Small build script which enables in place building of the project independent of the GOPATH.
#
set -e
# github user
OWNER=wolfeidau
# git repo name
PROJECT_NAME=mqtt-bridgeify
# executable name
BIN_NAME=mqtt-bridgeify
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
GIT_COMMIT="$(git rev-parse HEAD)"
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
VERSION="$(grep "const Version " version.go | sed -E 's/.*"(.+)"$/\1/' )"
# remove working build
# rm -rf .gopath
if [ ! -d ".gopath" ]; then
mkdir -p .gopath/src/github.com/${OWNER}
ln -sf ../../../.. .gopath/src/github.com/${OWNER}/${PROJECT_NAME}
fi
export GOPATH="$(pwd)/.gopath"
# move the working path and build
cd .gopath/src/github.com/${OWNER}/${PROJECT_NAME}
go get -d -v ./...
go build -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" -o ${BIN_NAME}
mv ${BIN_NAME} ./bin
#!/usr/bin/env bash
#
# This script does cross compiling and associated magic.
#
set -e
# git repo name used for linking
PACKAGE_NAME=mqtt-bridgeify
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that dir because we expect that
cd $DIR
# Determine the version that we're building based on the contents
# of packer/version.go.
VERSION=$(grep "const Version " version.go | sed -E 's/.*"(.+)"$/\1/')
VERSIONDIR="${VERSION}"
PREVERSION=$(grep "const VersionPrerelease " version.go | sed -E 's/.*"(.*)"$/\1/')
if [ ! -z $PREVERSION ]; then
PREVERSION="${PREVERSION}.$(date -u +%s)"
VERSIONDIR="${VERSIONDIR}-${PREVERSION}"
fi
echo "Version: ${VERSION} ${PREVERSION}"
# Determine the arch/os combos we're building for
XC_ARCH=${XC_ARCH:-"amd64 arm"}
XC_OS=${XC_OS:-darwin linux}
echo "Arch: ${XC_ARCH}"
echo "OS: ${XC_OS}"
# Make sure that if we're killed, we kill all our subprocseses
trap "kill 0" SIGINT SIGTERM EXIT
# This function builds whatever directory we're in...
goxc \
-arch="$XC_ARCH" \
-os="$XC_OS" \
-d="${DIR}/pkg" \
-pv="${VERSION}" \
-pr="${PREVERSION}" \
-n="${PACKAGE_NAME}" \
$XC_OPTS \
go-install \
xc
# Zip all the packages
mkdir -p ./pkg/${VERSIONDIR}/dist
for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do
PLATFORM_NAME=$(basename ${PLATFORM})
ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}"
if [ $PLATFORM_NAME = "dist" ]; then
continue
fi
pushd ${PLATFORM}
zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./*
popd
done
# Make the checksums
pushd ./pkg/${VERSIONDIR}/dist
shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS
popd
exit 0
all:
scripts/build.sh
dist:
scripts/dist.sh
clean:
rm bin/mqtt-bridgeify || true
rm -rf .gopath || true
test:
go test ./...
.PHONY: all dist clean test
#!/usr/bin/env bash
#
# Given a version number this script will upload the assets to bintray for release.
#
set -e
# git repo name used for linking
REPO_NAME=mqtt-bridgeify
# bintray related stuff
PACKAGE_NAME=mqtt-bridgeify
BINTRAY_OWNER=wolfeidau
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that dir because we expect that
cd $DIR
# Get the version from the command line
VERSION=$1
if [ -z $VERSION ]; then
echo "Please specify a version."
exit 1
fi
# Make sure we have a bintray API key
if [ -z $BINTRAY_API_KEY ]; then
echo "Please set your bintray API key in the BINTRAY_API_KEY env var."
exit 1
fi
# Make sure we have a bintray API key
if [ -z $BINTRAY_USER ]; then
echo "Please set your bintray API user in the BINTRAY_USER env var."
exit 1
fi
for ARCHIVE in ./pkg/${VERSION}/dist/*; do
ARCHIVE_NAME=$(basename ${ARCHIVE})
echo Uploading: $ARCHIVE_NAME
curl \
-T ${ARCHIVE} \
-u${BINTRAY_USER}:${BINTRAY_API_KEY} \
"https://api.bintray.com/content/${BINTRAY_OWNER}/${REPO_NAME}/${PACKAGE_NAME}/${VERSION}/${ARCHIVE_NAME}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment