|
| 1 | +#!/usr/bin/env sh |
| 2 | +set -o pipefail -o nounset -o errexit -o errtrace |
| 3 | + |
| 4 | +# Find our .git directory |
| 5 | +ROOT_DIR="$(pwd)" |
| 6 | +while [ ! -d "${ROOT_DIR}/.git" ]; do |
| 7 | + |
| 8 | + ROOT_DIR="$(dirname ${ROOT_DIR})" |
| 9 | + if [ "x${ROOT_DIR}" == "x/" ]; then |
| 10 | + echo "Cannot find .git directory, I use that as reference for the commands." |
| 11 | + exit 1 |
| 12 | + fi |
| 13 | +done |
| 14 | + |
| 15 | +# Determine our projectname |
| 16 | +NAME="$(basename $(pwd))" |
| 17 | + |
| 18 | +# Checking if we have any tags to start with, the cid is Git's magical initial repo hash |
| 19 | +TAGS=$(git rev-list --tags --count 4b825dc642cb6eb9a060e54bf8d69288fbee4904) |
| 20 | +if [ ${TAGS} -eq 0 ]; |
| 21 | +then |
| 22 | + echo "No tags detected for ${ROOT_DIR}, please create a tag first!" |
| 23 | + exit 1; |
| 24 | +fi |
| 25 | + |
| 26 | +# Figuring out what tag's we're on |
| 27 | +LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1 4b825dc642cb6eb9a060e54bf8d69288fbee4904)) |
| 28 | +PREV_TAG=$(git tag --sort version:refname | tail -2 | head -1 || true) |
| 29 | + |
| 30 | +if [ "x${LATEST_TAG}" == "x" -a "x${PREV_TAG}" == "x" ]; |
| 31 | +then |
| 32 | + echo "No tag has been found?" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +echo "Previous tag is: ${PREV_TAG}" |
| 36 | +echo "Building a release for tag: ${LATEST_TAG}" |
| 37 | + |
| 38 | +# Falling back to the first commit, if we only have one tag |
| 39 | +if [ "x${PREV_TAG}" == "x${LATEST_TAG}" ]; |
| 40 | +then |
| 41 | + PREV_TAG=$(git rev-list --max-parents=0 HEAD) |
| 42 | +fi |
| 43 | + |
| 44 | +echo 'Installing dependencies ...' |
| 45 | +# Dependencies |
| 46 | +go get -u github.com/c4milo/github-release |
| 47 | +go get -u github.com/mitchellh/gox |
| 48 | + |
| 49 | +# Cleanup |
| 50 | +rm -rf build dist && mkdir -p build dist |
| 51 | + |
| 52 | +# Build |
| 53 | +GOARM=6 gox -ldflags "-s -w -X main.Version=${LATEST_TAG}" \ |
| 54 | + -rebuild \ |
| 55 | + -output "build/{{.Dir}}-${LATEST_TAG}-{{.OS}}-{{.Arch}}/${NAME}" \ |
| 56 | + . |
| 57 | + |
| 58 | +# Archive |
| 59 | +HERE=$(pwd) |
| 60 | +BUILDDIR=${HERE}/build |
| 61 | +for DIR in $(ls build/); |
| 62 | +do |
| 63 | + OUTDIR="${HERE}/dist" |
| 64 | + OUTFILENAME="${DIR}.tar.gz" |
| 65 | + OUTFILE="${OUTDIR}/${OUTFILENAME}" |
| 66 | + cd ${BUILDDIR}/${DIR} && \ |
| 67 | + tar -czf ${OUTFILE} * && \ |
| 68 | + cd ${OUTDIR} && \ |
| 69 | + shasum -a 512 ${OUTFILENAME} > ${OUTFILE}.sha512 |
| 70 | +done |
| 71 | +cd ${HERE} |
| 72 | + |
| 73 | +# Building the changelog |
| 74 | +DIFF_REF="${PREV_TAG}..${LATEST_TAG}" |
| 75 | +CHANGELOG="$(printf '# %s\n%s' 'Changelog' "$(git log ${DIFF_REF} --oneline --no-merges --reverse)")" |
| 76 | +echo "Building the changelog based on these two ref's: '${DIFF_REF}'" |
| 77 | +github-release yazgazan/${NAME} ${LATEST_TAG} "$(git rev-parse --abbrev-ref HEAD)" "${CHANGELOG}" 'dist/*'; |
0 commit comments