diff --git a/.gitignore b/.gitignore index 43d1884..97f87c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.claude agent.md config.json +*.exe # SQLite database files. They live on a network share (Y:), and git/cloud # sync touching them while a WAL database is open corrupts the WAL index and diff --git a/build-linux-x86_64.bat b/build-linux-x86_64.bat new file mode 100644 index 0000000..6c1980f --- /dev/null +++ b/build-linux-x86_64.bat @@ -0,0 +1,33 @@ +@echo off +setlocal enabledelayedexpansion + +echo Building for Linux (amd64)... + +:: Get git commit hash (shortened to 7 characters, can also use full) +for /f %%i in ('git rev-parse --short HEAD') do set COMMIT=%%i + +:: Get UTC time +for /f %%i in ('powershell -Command "Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'"') do set BUILD_DATE=%%i + +:: Set environment variables for Linux build +set GOOS=linux +set GOARCH=amd64 +set CGO_ENABLED=0 + +:: Build -ldflags +set LDFLAGS=-X main.BuildTime=%BUILD_DATE% -X main.CommitHash=%COMMIT% + +:: Set output file name +set OUTPUT=nukumizu-linux-amd64 + +echo Commit: %COMMIT% +echo BuildDate: %BUILD_DATE% +echo Output: %OUTPUT% + +go build -ldflags "%LDFLAGS%" -o "%OUTPUT%" . + +if %errorlevel% equ 0 ( + echo Build succeeded: %OUTPUT% +) else ( + echo Build failed. +) \ No newline at end of file diff --git a/build-win-x86_64.bat b/build-win-x86_64.bat new file mode 100644 index 0000000..1be7130 --- /dev/null +++ b/build-win-x86_64.bat @@ -0,0 +1,33 @@ +@echo off +setlocal enabledelayedexpansion + +echo Building for Windows (amd64)... + +:: Get git commit hash (shortened to 7 characters, can also use full) +for /f %%i in ('git rev-parse --short HEAD') do set COMMIT=%%i + +:: Get UTC time +for /f %%i in ('powershell -Command "Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'"') do set BUILD_DATE=%%i + +:: Set environment variables for Windows build +set GOOS=windows +set GOARCH=amd64 +set CGO_ENABLED=0 + +:: Build -ldflags +set LDFLAGS=-X main.BuildTime=%BUILD_DATE% -X main.CommitHash=%COMMIT% + +:: Set output file name +set OUTPUT=nukumizu-windows-amd64.exe + +echo Commit: %COMMIT% +echo BuildDate: %BUILD_DATE% +echo Output: %OUTPUT% + +go build -ldflags "%LDFLAGS%" -o "%OUTPUT%" . + +if %errorlevel% equ 0 ( + echo Build succeeded: %OUTPUT% +) else ( + echo Build failed. +) \ No newline at end of file diff --git a/main.go b/main.go index a5e2f6c..1c110dc 100644 --- a/main.go +++ b/main.go @@ -21,14 +21,22 @@ import ( "nukumizu-backend/utils" ) +// CommitHash and BuildTime are set at build time using -ldflags. +var ( + CommitHash string + BuildTime string +) + // SoftwareInfo holds build metadata. type SoftwareInfo struct { Name string Version string Developer string BuildVer int16 + CommitHash string Description string BuildType string + BuildTime string } var softwareInfo = SoftwareInfo{ @@ -36,8 +44,10 @@ var softwareInfo = SoftwareInfo{ Version: "0.1.0", Developer: "Madobi Nanami", BuildVer: 1, + CommitHash: CommitHash, Description: "Remote server monitoring and command execution subsystem for Komari", BuildType: "Debug", + BuildTime: BuildTime, } func main() { @@ -46,7 +56,7 @@ func main() { flag.Parse() // Log startup banner. - postLog.Info(fmt.Sprintf("%s Ver.%s.%d.%s Developed by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer)) + postLog.Info(fmt.Sprintf("%s Ver.%s.%d.%s.%s Developed by %s at %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.CommitHash, softwareInfo.Developer, softwareInfo.BuildTime)) // Load configuration. cfg, err := config.LoadConfig(*configPath) diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..a3263a3 --- /dev/null +++ b/run.bat @@ -0,0 +1,12 @@ +@echo off +setlocal enabledelayedexpansion + +:: Get git commit hash (shortened to 7 characters, can also use full) +for /f %%i in ('git rev-parse --short HEAD') do set COMMIT=%%i + +:: Get UTC time +for /f %%i in ('powershell -Command "Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'"') do set BUILD_DATE=%%i + +:: Build -ldflags +set LDFLAGS=-X main.BuildTime=%BUILD_DATE% -X main.CommitHash=%COMMIT% +go run -ldflags "%LDFLAGS%" . \ No newline at end of file