5 Star 41 Fork 8

infra-io / postar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
build.sh 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
水不要鱼 提交于 2024-04-02 11:45 . 调整结构
#!/bin/bash
function prepare() {
mkdir -p "$TARGET" || exit
mkdir -p "$TARGET"/"$PACKAGE" || exit
}
function build_postar() {
local binary_file="postar"
if [[ $GOOS = "windows" ]]; then
binary_file="$binary_file".exe
fi
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -o "$TARGET_PACKAGE"/"$binary_file" "$WORKDIR"/cmd/postar/main.go || exit
echo "$binary_file"
}
function build_postar_admin() {
local binary_file="postar-admin"
if [[ $GOOS = "windows" ]]; then
binary_file="$binary_file".exe
fi
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -o "$TARGET_PACKAGE"/"$binary_file" "$WORKDIR"/cmd/postar-admin/main.go || exit
echo "$binary_file"
}
function package() {
cp "$WORKDIR"/config/postar.toml "$TARGET_PACKAGE"/
cp "$WORKDIR"/config/postar_admin.toml "$TARGET_PACKAGE"/
cp "$WORKDIR"/LICENSE "$TARGET_PACKAGE"/
cd "$TARGET"
local pkg_file="postar-$VERSION-$GOOS-$GOARCH"
if [[ $GOOS = "windows" ]]; then
pkg_file="$pkg_file".zip
zip -qr "$TARGET"/"$pkg_file" "$PACKAGE" || exit
else
pkg_file="$pkg_file".tar.gz
tar -czf "$TARGET"/"$pkg_file" -P "$PACKAGE" || exit
fi
cd "$WORKDIR"
echo "$pkg_file"
}
function clean() {
rm -rf "$TARGET_PACKAGE"
}
# Main
VERSION=$1
GOOS=$2
GOARCH=$3
WORKDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
TARGET="$WORKDIR"/target
PACKAGE="postar-$VERSION-$GOOS-$GOARCH"
TARGET_PACKAGE="$TARGET"/"$PACKAGE"
echo "-----------------------------------------------------------------------"
echo "VERSION: $VERSION, GOOS: $GOOS, GOARCH:$GOARCH"
echo "WORKDIR: $WORKDIR"
echo "TARGET: $TARGET"
echo "TARGET_PACKAGE: $TARGET_PACKAGE"
echo "-----------------------------------------------------------------------"
# Prepare
prepare || exit
echo "Prepare successfully!"
# Build
postar_binary_file=$(build_postar) || exit
echo "Build $postar_binary_file successfully!"
postar_admin_binary_file=$(build_postar_admin) || exit
echo "Build $postar_admin_binary_file successfully!"
# Package
pkg_file=$(package $postar_binary_file $postar_admin_binary_file) || exit
echo "Package $pkg_file successfully!"
# Done
clean || exit
echo "Done!"
echo ""
Go
1
https://gitee.com/infra-io/postar.git
git@gitee.com:infra-io/postar.git
infra-io
postar
postar
master

搜索帮助