2018-06-09 21:57:32 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -ueo pipefail
|
|
|
|
|
2017-11-21 11:24:04 +01:00
|
|
|
# Copyright (C) 2016-2017 Vincent Ambo <mail@tazj.in>
|
|
|
|
#
|
|
|
|
# This file is part of Kontemplate.
|
|
|
|
#
|
|
|
|
# Kontemplate is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
2017-05-08 11:12:00 +02:00
|
|
|
readonly GIT_HASH="$(git rev-parse --short HEAD)"
|
|
|
|
readonly LDFLAGS="-X main.gitHash=${GIT_HASH} -w -s"
|
2018-06-26 12:30:41 +02:00
|
|
|
readonly VERSION="1.7.0-${GIT_HASH}"
|
2017-05-08 11:12:00 +02:00
|
|
|
|
2017-08-22 18:29:20 +02:00
|
|
|
function binary-name() {
|
|
|
|
local os="${1}"
|
|
|
|
local target="${2}"
|
|
|
|
if [ "${os}" = "windows" ]; then
|
|
|
|
echo -n "${target}/kontemplate.exe"
|
|
|
|
else
|
|
|
|
echo -n "${target}/kontemplate"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-08 11:12:00 +02:00
|
|
|
function build-for() {
|
|
|
|
local os="${1}"
|
|
|
|
local arch="${2}"
|
|
|
|
local target="release/${os}/${arch}"
|
2017-08-22 18:29:20 +02:00
|
|
|
local bin=$(binary-name "${os}" "${target}")
|
2017-05-08 11:12:00 +02:00
|
|
|
|
|
|
|
echo "Building kontemplate for ${os}-${arch} in ${target}"
|
|
|
|
|
|
|
|
mkdir -p "${target}"
|
|
|
|
|
|
|
|
env GOOS="${os}" GOARCH="${arch}" go build \
|
|
|
|
-ldflags "${LDFLAGS}" \
|
2017-08-22 18:29:20 +02:00
|
|
|
-o "${bin}" \
|
2017-05-08 11:12:00 +02:00
|
|
|
-tags netgo
|
|
|
|
}
|
|
|
|
|
|
|
|
function sign-for() {
|
|
|
|
local os="${1}"
|
|
|
|
local arch="${2}"
|
|
|
|
local target="release/${os}/${arch}"
|
2017-08-22 18:37:54 +02:00
|
|
|
local bin=$(binary-name "${os}" "${target}")
|
2017-05-08 11:12:00 +02:00
|
|
|
local tar="release/kontemplate-${VERSION}-${os}-${arch}.tar.gz"
|
|
|
|
|
|
|
|
echo "Packing release into ${tar}"
|
2017-08-22 18:37:54 +02:00
|
|
|
tar czvf "${tar}" -C "${target}" $(basename "${bin}")
|
|
|
|
|
|
|
|
local hash=$(sha256sum "${tar}")
|
|
|
|
echo "Signing kontemplate release tarball for ${os}-${arch} with SHA256 ${hash}"
|
|
|
|
gpg --armor --detach-sig --sign "${tar}"
|
2017-05-08 11:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case "${1}" in
|
|
|
|
"build")
|
|
|
|
# Build releases for various operating systems:
|
|
|
|
build-for "linux" "amd64"
|
|
|
|
build-for "darwin" "amd64"
|
|
|
|
build-for "windows" "amd64"
|
|
|
|
build-for "freebsd" "amd64"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
"sign")
|
2017-08-22 18:37:54 +02:00
|
|
|
# Bundle and sign releases:
|
2017-05-08 11:12:00 +02:00
|
|
|
sign-for "linux" "amd64"
|
|
|
|
sign-for "darwin" "amd64"
|
|
|
|
sign-for "windows" "amd64"
|
|
|
|
sign-for "freebsd" "amd64"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|