-
Notifications
You must be signed in to change notification settings - Fork 0
/
createRelease.sh
executable file
·77 lines (65 loc) · 2.22 KB
/
createRelease.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
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}" \
./cmd/bacom
# 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/*';