Big refactor
This commit is contained in:
109
build.sh
Executable file
109
build.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
|
||||
appName="zurg"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
|
||||
if [ "$1" = "dev" ]; then
|
||||
version="dev"
|
||||
else
|
||||
version=$(git describe --abbrev=0 --tags)
|
||||
fi
|
||||
|
||||
echo "app version: $version"
|
||||
|
||||
ldflags="\
|
||||
-w -s \
|
||||
-X 'github.com/debridmediamanager/zurg/internal/version.BuiltAt=$builtAt' \
|
||||
-X 'github.com/debridmediamanager/zurg/internal/version.GoVersion=$goVersion' \
|
||||
-X 'github.com/debridmediamanager/zurg/internal/version.GitCommit=$gitCommit' \
|
||||
-X 'github.com/debridmediamanager/zurg/internal/version.Version=$version' \
|
||||
"
|
||||
|
||||
BuildDev() {
|
||||
# rm -rf .git/
|
||||
xgo -targets=linux/amd64,windows/amd64,darwin/arm64 -out "$appName" -ldflags="$ldflags" ./cmd/zurg
|
||||
mkdir -p "dist"
|
||||
mv zurg-* dist
|
||||
cd dist
|
||||
upx -9 ./zurg-linux-amd64
|
||||
upx -9 ./zurg-windows*
|
||||
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
||||
cat md5.txt
|
||||
}
|
||||
|
||||
BuildDocker() {
|
||||
go build -o ./bin/zurg -ldflags="$ldflags" .
|
||||
}
|
||||
|
||||
BuildRelease() {
|
||||
# rm -rf .git/
|
||||
mkdir -p "build"
|
||||
muslflags="--extldflags '-static -fpic' $ldflags"
|
||||
BASE="https://musl.nn.ci/"
|
||||
FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross arm-linux-musleabihf-cross mips-linux-musl-cross mips64-linux-musl-cross mips64el-linux-musl-cross mipsel-linux-musl-cross powerpc64le-linux-musl-cross s390x-linux-musl-cross)
|
||||
for i in "${FILES[@]}"; do
|
||||
url="${BASE}${i}.tgz"
|
||||
curl -L -o "${i}.tgz" "${url}"
|
||||
sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local
|
||||
done
|
||||
OS_ARCHES=(linux-musl-amd64 linux-musl-arm64 linux-musl-arm linux-musl-mips linux-musl-mips64 linux-musl-mips64le linux-musl-mipsle linux-musl-ppc64le linux-musl-s390x)
|
||||
CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc arm-linux-musleabihf-gcc mips-linux-musl-gcc mips64-linux-musl-gcc mips64el-linux-musl-gcc mipsel-linux-musl-gcc powerpc64le-linux-musl-gcc s390x-linux-musl-gcc)
|
||||
for i in "${!OS_ARCHES[@]}"; do
|
||||
os_arch=${OS_ARCHES[$i]}
|
||||
cgo_cc=${CGO_ARGS[$i]}
|
||||
echo building for ${os_arch}
|
||||
export GOOS=${os_arch%%-*}
|
||||
export GOARCH=${os_arch##*-}
|
||||
export CC=${cgo_cc}
|
||||
export CGO_ENABLED=1
|
||||
go build -o ./build/$appName-$os_arch -ldflags="$muslflags" .
|
||||
done
|
||||
xgo -out "$appName" -ldflags="$ldflags" .
|
||||
# why? Because some target platforms seem to have issues with upx compression
|
||||
upx -9 ./zurg-linux-amd64
|
||||
upx -9 ./zurg-windows*
|
||||
mv zurg-* build
|
||||
}
|
||||
|
||||
MakeRelease() {
|
||||
cd build
|
||||
mkdir compress
|
||||
for i in $(find . -type f -name "$appName-linux-*"); do
|
||||
cp "$i" zurg
|
||||
tar -czvf compress/"$i".tar.gz zurg
|
||||
rm -f zurg
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-darwin-*"); do
|
||||
cp "$i" zurg
|
||||
tar -czvf compress/"$i".tar.gz zurg
|
||||
rm -f zurg
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-windows-*"); do
|
||||
cp "$i" zurg.exe
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip zurg.exe
|
||||
rm -f zurg.exe
|
||||
done
|
||||
cd compress
|
||||
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
||||
cat md5.txt
|
||||
cd ../..
|
||||
}
|
||||
|
||||
if [ "$1" = "dev" ]; then
|
||||
if [ "$2" = "docker" ]; then
|
||||
BuildDocker
|
||||
else
|
||||
BuildDev
|
||||
fi
|
||||
elif [ "$1" = "release" ]; then
|
||||
if [ "$2" = "docker" ]; then
|
||||
BuildDocker
|
||||
else
|
||||
BuildRelease
|
||||
MakeRelease
|
||||
fi
|
||||
else
|
||||
echo -e "Parameter error"
|
||||
fi
|
||||
Reference in New Issue
Block a user