sylixos-uploader/build.sh

43 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# 检查是否在 Git 仓库中
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Error: Not inside a Git repository."
exit 1
fi
# 获取最近的 tag
TAG=$(git describe --tags --abbrev=0 2>/dev/null)
# 获取最后一次提交的 SHA
COMMIT_SHA=$(git rev-parse --short HEAD)
# 检查是否有未提交的更改
if [ -n "$(git status --porcelain)" ]; then
DIRTY="-dirty"
else
DIRTY=""
fi
# 决定版本信息
if [ -n "$TAG" ]; then
VERSION="$TAG$DIRTY"
else
VERSION="$COMMIT_SHA$DIRTY"
fi
# 输出版本信息
echo "Injecting version: $VERSION"
# 将版本信息注入到 Go 构建中
GO_LDFLAGS="-X 'sylixos-uploader/common.Version=$VERSION'"
echo "Building with flags: $GO_LDFLAGS"
OS=linux ARCH=amd64
GOOS=${OS} GOARCH=${ARCH} CGO_ENABLED=0 go build -o "sylixos-uploader-${OS}-${ARCH}-${VERSION}" -ldflags "$GO_LDFLAGS"
OS=linux ARCH=arm64
GOOS=${OS} GOARCH=${ARCH} CGO_ENABLED=0 go build -o "sylixos-uploader-${OS}-${ARCH}-${VERSION}" -ldflags "$GO_LDFLAGS"
exit 0