-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·132 lines (108 loc) · 2.98 KB
/
release.sh
File metadata and controls
executable file
·132 lines (108 loc) · 2.98 KB
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
128
129
130
131
132
#!/bin/bash
# Simple bash script to build basic chantools for all the platforms
# we support with the golang cross-compiler.
#
# Copyright (c) 2016 Company 0, LLC.
# Use of this source code is governed by the ISC
# license.
set -e
PKG="github.com/lightninglabs/chantools"
DOCKER_USER="guggero"
PACKAGE=chantools
# green prints one line of green text (if the terminal supports it).
function green() {
echo -e "\e[0;32m${1}\e[0m"
}
# red prints one line of red text (if the terminal supports it).
function red() {
echo -e "\e[0;31m${1}\e[0m"
}
# build_release builds the actual release binaries.
# arguments: <version-tag> <build-system(s)> <ldflags>
function build_release() {
local tag=$1
local sys=$2
local ldflags=$3
green " - Packaging vendor"
go mod vendor
tar -czf vendor.tar.gz vendor
maindir=$PACKAGE-$tag
mkdir -p $maindir
cp vendor.tar.gz $maindir/
rm vendor.tar.gz
rm -r vendor
package_source="${maindir}/${PACKAGE}-source-${tag}.tar"
git archive -o "${package_source}" HEAD
gzip -f "${package_source}" >"${package_source}.gz"
cd "${maindir}"
for i in $sys; do
os=$(echo $i | cut -f1 -d-)
arch=$(echo $i | cut -f2 -d-)
arm=
if [[ $arch == "armv6" ]]; then
arch=arm
arm=6
elif [[ $arch == "armv7" ]]; then
arch=arm
arm=7
fi
dir="${PACKAGE}-${i}-${tag}"
mkdir "${dir}"
pushd "${dir}"
green " - Building: ${os} ${arch} ${arm}"
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" ${PKG}/cmd/chantools
popd
if [[ $os == "windows" ]]; then
zip -r "${dir}.zip" "${dir}"
else
tar -cvzf "${dir}.tar.gz" "${dir}"
fi
rm -r "${dir}"
done
shasum -a 256 * >manifest-$tag.txt
}
# docker_release builds the Docker images for all supported platforms.
# arguments: <version-tag>
function docker_release() {
local tag=$1
docker buildx build \
--platform linux/arm64,linux/amd64 \
--tag $DOCKER_USER/$PACKAGE:$tag \
--tag $DOCKER_USER/$PACKAGE:latest --output "type=registry" .
docker buildx build \
-f docker/umbrel.Dockerfile \
--platform linux/arm64,linux/amd64 \
--build-arg VERSION=$tag \
--tag $DOCKER_USER/$PACKAGE:$tag-umbrel \
--tag $DOCKER_USER/$PACKAGE:latest-umbrel --output "type=registry" .
}
# usage prints the usage of the whole script.
function usage() {
red "Usage: "
red "release.sh build-release <version-tag> <build-system(s)> <ldflags>"
}
# Whatever sub command is passed in, we need at least 2 arguments.
if [ "$#" -lt 2 ]; then
usage
exit 1
fi
# Extract the sub command and remove it from the list of parameters by shifting
# them to the left.
SUBCOMMAND=$1
shift
# Call the function corresponding to the specified sub command or print the
# usage if the sub command was not found.
case $SUBCOMMAND in
build-release)
green "Building release"
build_release "$@"
;;
docker-release)
green "Building docker release"
docker_release "$@"
;;
*)
usage
exit 1
;;
esac