-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·99 lines (81 loc) · 2.81 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·99 lines (81 loc) · 2.81 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
#!/bin/bash
RELEASE_VERSION=
buildpath=
# Create a scratch tree to stage the package filesystem for fpm. It lives in the
# system temp dir, not $buildpath, so it never lands among the release artifacts.
function setuptree() {
b=$( mktemp -d ) || return 1
mkdir -p $b/gh-ost
mkdir -p $b/gh-ost/usr/bin
echo $b
}
function build {
GOOS=$1
GOARCH=$2
if ! go version | egrep -q 'go1\.(1[5-9]|[2-9][0-9]{1})' ; then
echo "go version must be 1.15 or above"
exit 1
fi
echo "Building ${GOOS}-${GOARCH} binary"
export GOOS
export GOARCH
CGO_ENABLED="${CGO_ENABLED:-0}" go build -ldflags "$ldflags" -o "$buildpath/$target" go/cmd/gh-ost/main.go
if [ $? -ne 0 ]; then
echo "Build failed for ${GOOS} ${GOARCH}."
exit 1
fi
(cd $buildpath && tar cfz ./gh-ost-${GOOS}-${GOARCH}.tar.gz $target)
# build RPM and deb packages for Linux
if [ "$GOOS" == "linux" ] ; then
echo "Creating Distro full packages"
case "$GOARCH" in
amd64) rpm_arch=x86_64 ; deb_arch=amd64 ;;
arm64) rpm_arch=aarch64 ; deb_arch=arm64 ;;
*) rpm_arch=$GOARCH ; deb_arch=$GOARCH ;;
esac
builddir=$(setuptree)
cp $buildpath/$target $builddir/gh-ost/usr/bin
cd $buildpath
fpm_opts=(
-v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost
-m 'GitHub' --description "GitHub's Online Schema Migrations for MySQL "
--url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0"
-C "$builddir/gh-ost" --prefix=/
)
fpm "${fpm_opts[@]}" -t rpm -a "${rpm_arch}" -p "gh-ost.${rpm_arch}.rpm" --rpm-rpmbuild-define "_build_id_links none" --rpm-os linux .
fpm "${fpm_opts[@]}" -t deb -a "${deb_arch}" -p "gh-ost.${deb_arch}.deb" --deb-no-default-config-files .
cd -
fi
# Drop the bare binary so only tarballs and packages are published as release assets
rm -f "$buildpath/$target"
}
main() {
if [ -z "${RELEASE_VERSION}" ] ; then
RELEASE_VERSION=$(git describe --abbrev=0 --tags | tr -d 'v')
fi
if [ -z "${RELEASE_VERSION}" ] ; then
echo "RELEASE_VERSION must be set"
exit 1
fi
if [ -z "${GIT_COMMIT}" ]; then
GIT_COMMIT=$(git rev-parse HEAD)
fi
buildpath=/tmp/gh-ost-release
target=gh-ost
ldflags="-X main.AppVersion=${RELEASE_VERSION} -X main.GitCommit=${GIT_COMMIT}"
mkdir -p ${buildpath}
rm -rf ${buildpath:?}/*
build linux amd64
build linux arm64
build darwin amd64
build darwin arm64
# Generate a SHA256SUMS manifest with basenames only, so a downloaded set can be
# verified in place with `sha256sum -c SHA256SUMS` (no absolute build paths leak in).
# The name has no gh-ost prefix, so it self-excludes from the gh-ost* glob below.
echo "Checksums:"
( cd "$buildpath" && shasum -a256 gh-ost* | tee SHA256SUMS )
echo "Release assets:"
ls -1 "$buildpath"
echo "Build Success!"
}
main "$@"