2018-07-19 10:47:05 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set +e
|
|
|
|
|
|
|
|
usage(){
|
|
|
|
echo "Usage: compile.sh <code path> <code tag> <main.go path> <binary name>"
|
2022-02-09 05:13:05 +01:00
|
|
|
echo "e.g: compile.sh github.com/helm/chartmuseum v0.14.0 cmd/chartmuseum chartm"
|
2018-07-19 10:47:05 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# != 4 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2019-07-17 08:38:08 +02:00
|
|
|
GIT_PATH="$1"
|
2018-07-19 10:47:05 +02:00
|
|
|
VERSION="$2"
|
|
|
|
MAIN_GO_PATH="$3"
|
|
|
|
BIN_NAME="$4"
|
|
|
|
|
2019-07-17 08:38:08 +02:00
|
|
|
#Get the source code
|
|
|
|
git clone $GIT_PATH src_code
|
|
|
|
ls
|
|
|
|
SRC_PATH=$(pwd)/src_code
|
2018-07-19 10:47:05 +02:00
|
|
|
set -e
|
|
|
|
|
|
|
|
#Checkout the released tag branch
|
2019-07-17 08:38:08 +02:00
|
|
|
cd $SRC_PATH
|
|
|
|
git checkout tags/$VERSION -b $VERSION
|
2018-07-19 10:47:05 +02:00
|
|
|
|
2020-06-15 18:20:18 +02:00
|
|
|
#Patch
|
|
|
|
for p in $(ls /go/bin/*.patch); do
|
|
|
|
git apply $p || exit /b 1
|
|
|
|
done
|
|
|
|
|
2018-07-19 10:47:05 +02:00
|
|
|
#Compile
|
2019-07-17 08:38:08 +02:00
|
|
|
cd $SRC_PATH/$MAIN_GO_PATH && go build -a -o $BIN_NAME
|
2018-07-19 10:47:05 +02:00
|
|
|
mv $BIN_NAME /go/bin/
|