ModernUO/publish.sh
Kamron Batman ec4d6a7a85
feat: Adds Build Tool for Publishing/Setup (#2392)
## Summary

Replaces the basic `publish.cmd`/`publish.sh` scripts with an interactive **BuildTool** — a C# console app using [Spectre.Console](https://spectreconsole.net/) that guides users through publishing, prerequisite checking, and cross-compilation.

### Why
The community found the existing publish scripts unhelpful for newcomers. They worked but didn't walk users through the process, didn't check prerequisites, and provided no feedback when things went wrong.

### What's New

**Interactive BuildTool** (`Projects/BuildTool/`)
- NativeAOT-compiled C# console app with true-color ASCII logo and ModernUO brand gold/silver palette
- Guided publish wizard with step-by-step back navigation (Ctrl+C or menu "Back" to go to previous step)
- Prerequisite checking: .NET SDK version, VC++ Redistributable (Windows), native libraries (Linux/macOS)
- .NET SDK auto-install offer via Microsoft's official install scripts
- Platform detection: Windows 10 vs 11 (build number), macOS codenames, Linux distro + kernel version
- Cross-compilation support: skips native library checks, shows target prerequisites after build
- Non-interactive mode for CI: `--config Release --skip-prereqs`
- Backward-compatible positional args: `publish.cmd release win x64` still works

**Shell Wrappers** (`publish.cmd`, `publish.ps1`, `publish.sh`)
- Try native BuildTool binary first (downloaded from GitHub Releases)
- Fall back to `dotnet run --project Projects/BuildTool` if unavailable
- SDK bootstrapping: offer to install .NET if not found

**CI/CD Updates**
- Build/test workflows target `Projects/Application/Application.csproj` instead of the solution (excludes BuildTool and test projects from publish)
- New `build-tool-release.yml` workflow builds NativeAOT binaries for win-x64, win-arm64, osx-arm64, linux-x64, linux-arm64
- Minimum SDK bumped to 10.0.201 (required for Serialization Generator 2.14.3 / Roslyn 5.3.0)

**Other Changes**
- Solution converted from `.sln` to `.slnx`
- Updated README with interactive mode instructions and deployment guidance

## Screenshots

<img width="320" height="378" alt="image" src="https://github.com/user-attachments/assets/83c057c5-3992-4dbd-99fa-0e3c24ef6428" />

<img width="749" height="554" alt="image" src="https://github.com/user-attachments/assets/e4ee4d6f-71d4-47f9-86b6-8fd1ca3c3e7a" />
2026-03-28 21:21:50 -07:00

93 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
set -e
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
# Determine platform for native binary
detect_platform() {
local os arch
case "$(uname -s)" in
Darwin) os="osx" ;;
*) os="linux" ;;
esac
case "$(uname -m)" in
aarch64|arm64) arch="arm64" ;;
*) arch="x64" ;;
esac
echo "${os}-${arch}"
}
PLATFORM="$(detect_platform)"
TOOL_BINARY="$REPO_ROOT/tools/build-tool"
BUILD_TOOL_PROJECT="$REPO_ROOT/Projects/BuildTool/BuildTool.csproj"
# Try to download native binary from GitHub Release
download_build_tool() {
local asset_name="build-tool-${PLATFORM}"
local tools_dir="$REPO_ROOT/tools"
echo -e "\033[34mDownloading build tool...\033[0m"
# Get latest release asset URL
local release_url="https://api.github.com/repos/modernuo/ModernUO/releases/tags/build-tool-latest"
local release_json
release_json=$(curl -fsSL --connect-timeout 10 -H "User-Agent: ModernUO-BuildTool" "$release_url" 2>/dev/null) || return 1
local download_url
download_url=$(echo "$release_json" | grep -o "\"browser_download_url\"[[:space:]]*:[[:space:]]*\"[^\"]*${asset_name}[^\"]*\"" | head -1 | grep -o 'https://[^"]*') || return 1
if [ -z "$download_url" ]; then
return 1
fi
mkdir -p "$tools_dir"
curl -fsSL --connect-timeout 10 -o "$TOOL_BINARY" "$download_url" || return 1
chmod +x "$TOOL_BINARY"
return 0
}
has_dotnet() {
command -v dotnet >/dev/null 2>&1
}
# CentOS/RHEL globalization workaround
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
centos|rhel)
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
;;
esac
fi
# Try native binary first
if [ -x "$TOOL_BINARY" ]; then
exec "$TOOL_BINARY" "$@"
fi
# Try to download native binary
if download_build_tool 2>/dev/null; then
exec "$TOOL_BINARY" "$@"
fi
# Fall back to dotnet run
if has_dotnet; then
if [ -f "$BUILD_TOOL_PROJECT" ]; then
echo -e "\033[33mUsing dotnet run fallback...\033[0m"
exec dotnet run --project "$BUILD_TOOL_PROJECT" -- "$@"
else
echo "Error: BuildTool project not found at: $BUILD_TOOL_PROJECT" >&2
exit 1
fi
fi
# Nothing works
echo ""
echo -e "\033[31mError: Could not run the build tool.\033[0m"
echo ""
echo -e "\033[33mThe .NET 10 SDK is required. Download it from:\033[0m"
echo -e "\033[36m https://dotnet.microsoft.com/download/dotnet/10.0\033[0m"
echo ""
exit 1