Files
justme a6f9759238
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline failed
ci: build musl only for arm64 and reuse toolchain cache [CI]
2026-10-21 12:41:58 +08:00

46 lines
2.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 发布一个节点程序:scripts/publish.sh <agent|backend|fleet-enroll> <rid>
# 输出到 backend/artifacts/publish/<project>/<rid>/。linux-x64(Ubuntu noble,glibc)在 NativeAOT SDK 容器里构建(任何主机都可以,包括 Windows),
# 其他 rid 用本机的 dotnet(NativeAOT 不能交叉编译到别的操作系统,所以 win-x64 要在 Windows 上、linux-x64 要在 glibc 的 Linux 上构建)。
set -euo pipefail
project="${1:?usage: publish.sh <agent|backend|fleet-enroll> <rid>}"
rid="${2:?usage: publish.sh <agent|backend|fleet-enroll> <rid>}"
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
case "$project" in
agent) csproj="backend/agent/src/MoShiro.Agent" ;;
backend) csproj="backend/src/MoShiro.Backend" ;;
fleet-enroll) csproj="backend/fleet/tools/fleet-enroll" ;;
*) echo "unknown project: $project" >&2; exit 2 ;;
esac
# 构建信息(程序里显示的 tag、提交、构建时间):没在 git 仓库里就留空
export MOSHIRO_TAG="${MOSHIRO_TAG:-$(git -C "$root" describe --tags --always --dirty 2>/dev/null || true)}"
export MOSHIRO_COMMIT="${MOSHIRO_COMMIT:-$(git -C "$root" rev-parse --short=10 HEAD 2>/dev/null || true)}"
export MOSHIRO_BUILT_AT="${MOSHIRO_BUILT_AT:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
build_env=(-e MOSHIRO_TAG -e MOSHIRO_COMMIT -e MOSHIRO_BUILT_AT)
out="backend/artifacts/publish/$project/$rid"
publish_options=()
if [[ "$project" == backend ]]; then
publish_options+=(-p:OpenApiGenerateDocuments=false)
fi
args=(publish "$csproj" -c Release -r "$rid" -p:PublishAot=true -p:DebugType=none -p:DebugSymbols=false "${publish_options[@]}" -o "/src/$out" --artifacts-path /artifacts -nologo -v q)
case "$rid" in
linux-x64)
docker run --rm "${build_env[@]}" -v "$root:/src" -v moshiro-nuget:/root/.nuget -v "moshiro-artifacts-$rid:/artifacts" -w /src mcr.microsoft.com/dotnet/sdk:10.0-noble-aot dotnet "${args[@]}"
;;
linux-musl-arm64|linux-arm64)
echo "$rid needs an arm64 Alpine builder (native or qemu): run this script on an arm64 host or in CI" >&2
exit 3
;;
*)
cd "$root/backend" # 继承仓库根目录的 global.json
dotnet publish "${csproj#backend/}" -c Release -r "$rid" -p:PublishAot=true -p:DebugType=none -p:DebugSymbols=false "${publish_options[@]}" -o "$root/$out" -nologo -v q
;;
esac
ls -l "$root/$out" | sed -n '1,20p'