diff --git a/docs/RELEASE-0.10-TASKS.md b/docs/RELEASE-0.10-TASKS.md index 60ef897..bd7d7f3 100644 --- a/docs/RELEASE-0.10-TASKS.md +++ b/docs/RELEASE-0.10-TASKS.md @@ -118,8 +118,8 @@ Done first because both share a compact, single-line record formatter. - [x] T6.4 — ARCHITECTURE.md update ### Phase 7 — Portable packaging -- [ ] T7.1 — Windows `.zip` -- [ ] T7.2 — Linux `.tar.gz` (amd64 + arm64) +- [x] T7.1 — Windows `.zip` +- [x] T7.2 — Linux `.tar.gz` (amd64 + arm64) ### Phase 8 — Release docs + version - [ ] T8.1 — version bump + CHANGELOG + ROADMAP + PERFORMANCE diff --git a/scripts/package-linux.sh b/scripts/package-linux.sh new file mode 100644 index 0000000..68b2f8c --- /dev/null +++ b/scripts/package-linux.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Move to the repository root regardless of where the script is invoked from. +cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." + +version="$(sed -n 's/^var Version = "\(.*\)"/\1/p' src/app/version.go | tr -d '\r')" +version="${version:-0.0.0-dev}" + +package_arch() { + local arch="$1" + local binary="dist/linux/gosentry-${version}-linux-${arch}" + local tarball="dist/linux/gosentry-${version}-linux-${arch}.tar.gz" + local staging="dist/linux/_staging-${arch}" + + mkdir -p dist/linux + + if [ "$arch" = "arm64" ]; then + if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then + echo "Skipping linux/arm64: aarch64-linux-gnu-gcc not found." + return 0 + fi + echo "Building linux/arm64..." + CC=aarch64-linux-gnu-gcc \ + CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \ + CGO_CFLAGS="--sysroot=/ -I/usr/include/aarch64-linux-gnu" \ + CGO_LDFLAGS="--sysroot=/ -L/usr/lib/aarch64-linux-gnu" \ + PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig \ + go build -trimpath \ + -ldflags "-s -w -X gitea.mixdep.ru/mix/gosentry/src/app.Version=${version}" \ + -o "$binary" ./cmd/gosentry + else + echo "Building linux/amd64..." + CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ + go build -trimpath \ + -ldflags "-s -w -X gitea.mixdep.ru/mix/gosentry/src/app.Version=${version}" \ + -o "$binary" ./cmd/gosentry + fi + + rm -rf "$staging" + mkdir -p "$staging" + cp "$binary" "$staging/gosentry" + cp README.md "$staging/README.md" + cp docs/CHANGELOG.md "$staging/CHANGELOG.md" + + # -C "$staging" . puts all files at the archive root with no subdirectory. + tar -czf "$tarball" -C "$staging" . + rm -rf "$staging" + + echo "Packaged $tarball" +} + +package_arch amd64 +package_arch arm64 diff --git a/scripts/package-windows.bat b/scripts/package-windows.bat new file mode 100644 index 0000000..1ceb4c2 --- /dev/null +++ b/scripts/package-windows.bat @@ -0,0 +1,41 @@ +@echo off +setlocal enabledelayedexpansion + +REM Double-clicking a .bat file can start it with an arbitrary working directory. +REM Move to the repository root before using relative paths. +cd /d "%~dp0\.." + +for /f "tokens=4" %%V in ('findstr /C:"var Version" src\app\version.go') do set "VERSION=%%~V" +if "%VERSION%"=="" set "VERSION=0.0.0-dev" +set "VERSION=%VERSION:"=%" + +set "ARCH=windows-amd64" +set "EXE_PATH=dist\windows\gosentry-%VERSION%-%ARCH%.exe" +set "ZIP_PATH=dist\windows\gosentry-%VERSION%-%ARCH%.zip" +set "STAGING=dist\windows\_staging-%VERSION%-%ARCH%" + +REM Build the Windows executable via the shared build script. +call scripts\build-windows.bat "%EXE_PATH%" +if errorlevel 1 exit /b 1 + +REM Assemble portable bundle in a staging directory. +if exist "%STAGING%" rmdir /s /q "%STAGING%" +mkdir "%STAGING%" + +copy "%EXE_PATH%" "%STAGING%\gosentry.exe" >nul +copy README.md "%STAGING%\README.md" >nul +copy docs\CHANGELOG.md "%STAGING%\CHANGELOG.md" >nul + +REM Remove any previous zip so Compress-Archive does not append to it. +if exist "%ZIP_PATH%" del /f "%ZIP_PATH%" + +REM Compress the staging contents. Each file lands at the root of the zip so +REM the user can extract directly into any folder and run gosentry.exe. +powershell -NoProfile -Command "Compress-Archive -Path '%STAGING%\*' -DestinationPath '%ZIP_PATH%'" +if errorlevel 1 ( + echo Compress-Archive failed. Ensure PowerShell 5+ is available. + exit /b 1 +) + +rmdir /s /q "%STAGING%" +echo Packaged %ZIP_PATH%