-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env sh | ||
set -o pipefail -o nounset -o errexit -o errtrace | ||
|
||
# Find our .git directory | ||
ROOT_DIR="$(pwd)" | ||
while [ ! -d "${ROOT_DIR}/.git" ]; do | ||
|
||
ROOT_DIR="$(dirname ${ROOT_DIR})" | ||
if [ "x${ROOT_DIR}" == "x/" ]; then | ||
echo "Cannot find .git directory, I use that as reference for the commands." | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Determine our projectname | ||
NAME="$(basename $(pwd))" | ||
|
||
# Checking if we have any tags to start with, the cid is Git's magical initial repo hash | ||
TAGS=$(git rev-list --tags --count 4b825dc642cb6eb9a060e54bf8d69288fbee4904) | ||
if [ ${TAGS} -eq 0 ]; | ||
then | ||
echo "No tags detected for ${ROOT_DIR}, please create a tag first!" | ||
exit 1; | ||
fi | ||
|
||
# Figuring out what tag's we're on | ||
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1 4b825dc642cb6eb9a060e54bf8d69288fbee4904)) | ||
PREV_TAG=$(git tag --sort version:refname | tail -2 | head -1 || true) | ||
|
||
if [ "x${LATEST_TAG}" == "x" -a "x${PREV_TAG}" == "x" ]; | ||
then | ||
echo "No tag has been found?" | ||
exit 1 | ||
fi | ||
echo "Previous tag is: ${PREV_TAG}" | ||
echo "Building a release for tag: ${LATEST_TAG}" | ||
|
||
# Falling back to the first commit, if we only have one tag | ||
if [ "x${PREV_TAG}" == "x${LATEST_TAG}" ]; | ||
then | ||
PREV_TAG=$(git rev-list --max-parents=0 HEAD) | ||
fi | ||
|
||
echo 'Installing dependencies ...' | ||
# Dependencies | ||
go get -u github.com/c4milo/github-release | ||
go get -u github.com/mitchellh/gox | ||
|
||
# Cleanup | ||
rm -rf build dist && mkdir -p build dist | ||
|
||
# Build | ||
GOARM=6 gox -ldflags "-s -w -X main.Version=${LATEST_TAG}" \ | ||
-rebuild \ | ||
-output "build/{{.Dir}}-${LATEST_TAG}-{{.OS}}-{{.Arch}}/${NAME}" \ | ||
. | ||
|
||
# Archive | ||
HERE=$(pwd) | ||
BUILDDIR=${HERE}/build | ||
for DIR in $(ls build/); | ||
do | ||
OUTDIR="${HERE}/dist" | ||
OUTFILENAME="${DIR}.tar.gz" | ||
OUTFILE="${OUTDIR}/${OUTFILENAME}" | ||
cd ${BUILDDIR}/${DIR} && \ | ||
tar -czf ${OUTFILE} * && \ | ||
cd ${OUTDIR} && \ | ||
shasum -a 512 ${OUTFILENAME} > ${OUTFILE}.sha512 | ||
done | ||
cd ${HERE} | ||
|
||
# Building the changelog | ||
DIFF_REF="${PREV_TAG}..${LATEST_TAG}" | ||
CHANGELOG="$(printf '# %s\n%s' 'Changelog' "$(git log ${DIFF_REF} --oneline --no-merges --reverse)")" | ||
echo "Building the changelog based on these two ref's: '${DIFF_REF}'" | ||
github-release yazgazan/${NAME} ${LATEST_TAG} "$(git rev-parse --abbrev-ref HEAD)" "${CHANGELOG}" 'dist/*'; |