-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.sh
executable file
·51 lines (47 loc) · 1.55 KB
/
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
#!/bin/bash
set -e
# ensure deps
dep ensure -v
# get version from git
version="$(git describe | cut -d '-' -f 1)"
goversion="$(go version | cut -d' ' -f3 | cut -c 3-)"
bindest='./release/bin'
targets='linux/amd64,linux/arm64,darwin-10.6/amd64'
# cross compile all binaries
for pkg in $(ls -d ./cmd/*); do
binary="${pkg#./cmd/}"
if [ "$binary" == "polisatomicswap" ]; then
# xgo required because of CGO requirements
xgo -out "$binary-$version" -go "$goversion" \
-dest "$bindest" -targets "$targets" "$pkg"
else
# compile them manually ourselves, much faster
for target in $(echo "$targets" | tr , \\n); do
os="$(echo "$target" | cut -d/ -f 1 | cut -d- -f 1)"
arch="$(echo "$target" | cut -d/ -f 2 | cut -d- -f 1)"
env GOOS="$os" GOARCH="$arch" go build \
-o "${bindest}/${binary}-${version}-$(echo "$target" | tr / -)" "$pkg"
done
fi
done
# package tools per target
for target in $(echo "$targets" | tr / - | tr , \\n); do
echo Packaging "$target"...
# create workspace
folder="release/atomicswap-${version}-${target}"
rm -rf "$folder"
mkdir -p "$folder"
# move all tools
for tool in ${bindest}/*${target}; do
tool="$(basename "$tool")"
name="$(echo "$tool" | cut -d- -f1)"
mv "${bindest}/${tool}" "${folder}/${name}"
done
# add other artifacts
cp -r LICENSE README.md "$folder"
# zip
(
zip -rq "release/atomicswap-${version}-${target}.zip" \
"release/atomicswap-${version}-${target}"
)
done