mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-18 19:55:40 +00:00
77 lines
2.2 KiB
Bash
Executable File
77 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
GO="${GO:-go}"
|
|
RELEASE_LDFLAGS="-s -w $LDFLAGS"
|
|
RELEASE_TAGS="bindata $TAGS"
|
|
RELEASE_PATH_PREFIX="${DIST}/binaries/gitea-${VERSION##*/}"
|
|
|
|
RELEASE_PLATFORMS_DEFAULT=(
|
|
linux/amd64 linux/arm-5 linux/arm-6 linux/arm64 linux/riscv64 \
|
|
windows/amd64 windows/arm64 \
|
|
darwin/amd64 darwin/arm64 \
|
|
freebsd/amd64
|
|
)
|
|
|
|
RELEASE_PLATFORMS_GOGIT=(windows/amd64 windows/arm64)
|
|
|
|
build() {
|
|
echo "building ${*} ..."
|
|
local target="${1:?}"
|
|
local variant="${2:-}"
|
|
|
|
local goos="${target%%/*}"
|
|
local goarch="${target##*/}"
|
|
local goarm=""
|
|
if [[ "$goarch" == arm-* ]]; then
|
|
goarm="${goarch#arm-}"
|
|
goarch="arm"
|
|
fi
|
|
|
|
local tags="${RELEASE_TAGS}"
|
|
local suffix
|
|
if [[ "$variant" == "gogit" ]]; then
|
|
tags="gogit${tags:+ ${tags}}"
|
|
suffix="-gogit-${target//\//-}"
|
|
else
|
|
suffix="-${target//\//-}"
|
|
fi
|
|
|
|
local output="${RELEASE_PATH_PREFIX}${suffix}"
|
|
local args=()
|
|
if [[ "$goos" == "windows" ]]; then
|
|
output="${output}.exe"
|
|
fi
|
|
args+=(-tags "$tags")
|
|
args+=(-ldflags "$RELEASE_LDFLAGS")
|
|
echo " args: ${args[*]}"
|
|
echo " output: ${output}"
|
|
# must disable CGO (host compiler & linker) to get host-independent static builds
|
|
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" GOARM="$goarm" "$GO" build "${args[@]}" -o "$output" .
|
|
}
|
|
|
|
main() {
|
|
# When building release binaries, some TAGS (bindata) are needed by the release script,
|
|
# so here it needs to use the TAGS to generate the assets (embed bindata).
|
|
echo "generating assets with tags=${RELEASE_TAGS}"
|
|
"$GO" generate -tags "${RELEASE_TAGS}" ./...
|
|
local platform="${1:-}"
|
|
for target in "${RELEASE_PLATFORMS_DEFAULT[@]}"; do
|
|
if [[ -z "$platform" || "$target" == "$platform/"* ]]; then
|
|
build "$target"
|
|
fi
|
|
done
|
|
|
|
# Only build with gogit for main-nightly, disable gogit for stable releases since there seems no real requirement for them.
|
|
# If no real requirement (no user feedbacks), we can completely remove gogit support in the future.
|
|
if [ "$VERSION" = "main-nightly" ]; then
|
|
for target in "${RELEASE_PLATFORMS_GOGIT[@]}"; do
|
|
if [[ -z "$platform" || "$target" == "$platform/"* ]]; then
|
|
build "$target" "gogit"
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
main "$@"
|