forked from kvc-code/kontemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-release.sh
executable file
·127 lines (111 loc) · 3.56 KB
/
build-release.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -eo pipefail
# Copyright (C) 2016-2019 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.
readonly GIT_HASH="$(git rev-parse --short HEAD)"
readonly LDFLAGS="-X main.gitHash=${GIT_HASH} -w -s"
readonly VERSION="1.10.1-${GIT_HASH}"
function binary-name() {
local os="${1}"
local target="${2}"
if [ "${os}" = "windows" ]; then
echo -n "${target}/kontemplate.exe"
else
echo -n "${target}/kontemplate"
fi
}
function build-for() {
local os="${1}"
local arch="${2}"
local goarm="${3}"
local target="release/${os}/${arch}"
local bin=$(binary-name "${os}" "${target}")
echo "Building kontemplate for ${os}-${arch} in ${target}"
mkdir -p "${target}"
env GOOS="${os}" GOARCH="${arch}" GOARM="${goarm}" go build \
-ldflags "${LDFLAGS}" \
-o "${bin}" \
-tags netgo
}
function sign-for() {
local os="${1}"
local arch="${2}"
local target="release/${os}/${arch}"
local bin=$(binary-name "${os}" "${target}")
local tar="release/kontemplate-${VERSION}-${os}-${arch}.tar.gz"
echo "Packing release into ${tar}"
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}"
}
function make-fat() {
local os="darwin"
local arch="fatbin"
local target="release/${os}/${arch}"
local bin=$(binary-name "${os}" "${target}")
local name=$(basename ${bin})
local tar="release/kontemplate-${VERSION}-${os}-${arch}.tar.gz"
echo "Packing release into ${tar}"
mkdir -p "${target}"
# build Fat Binary - only works on macOS
lipo -create -output "${bin}" "release/${os}/amd64/$(basename ${bin})" "release/${os}/arm64/$(basename ${bin})"
tar czvf "${tar}" -C "${target}" $(basename "${bin}")
local hash=$(sha256sum "${tar}")
echo "Signing kontemplate release tarball for ${os}-${arch} with SHA256 ${hash}"
gpg --default-key "ksquaredkey@users.noreply.github.com" --armor --detach-sig --sign "${tar}"
}
case "${1}" in
"init")
# set up environment
rm -rf release
rm -rf go.mod go.sum
go mod init github.com/ksquaredkey/kontemplate
go mod tidy
exit 0
;;
"build")
# Build releases for various operating systems:
# Linux x86_64
build-for "linux" "amd64"
# Linux AWS Graviton2
build-for "linux" "arm64"
# Raspberry Pi
build-for "linux" "arm" "5"
# macOS x86_64
build-for "darwin" "amd64"
# macOS M1
build-for "darwin" "arm64"
# Windows
build-for "windows" "amd64"
# FreeBSD
build-for "freebsd" "amd64"
exit 0
;;
"sign")
# Bundle and sign releases:
# Linux x86_64
sign-for "linux" "amd64"
# Linux AWS Graviton2
sign-for "linux" "arm64"
# Raspberry Pi
sign-for "linux" "arm" "GOARM=5"
# macOS x86_64
sign-for "darwin" "amd64"
# macOS M1
sign-for "darwin" "arm64"
# macOS Fat Binary
make-fat
# Windows x86_64
sign-for "windows" "amd64"
# FreeBSD x86_64
sign-for "freebsd" "amd64"
exit 0
;;
esac