Skip to content

Instantly share code, notes, and snippets.

@gpant
Last active July 7, 2023 02:10
Show Gist options
  • Save gpant/2078fc6d1c77dd14ab30d83e538bddbc to your computer and use it in GitHub Desktop.
Save gpant/2078fc6d1c77dd14ab30d83e538bddbc to your computer and use it in GitHub Desktop.
Go Build Batch File
@echo off
SET @version=0.1.34
SET BINARYNAME=cacti-go-tools
SET BUILDSPATH=builds
SET ARCH[0]=386
SET ARCH[1]=amd64
SET ARCH[2]=arm
SET ARCH[3]=arm64
SET ARCH[4]=ppc64
SET ARCH[5]=ppc64le
SET ARCH[6]=mips
SET ARCH[7]=mipsle
SET ARCH[8]=mips64
SET ARCH[9]=mips64le
SET ARCH[10]=s390x
SET BUILD[0]=darwin
SET BUILD[1]=dragonfly
SET BUILD[2]=freebsd
SET BUILD[3]=linux
SET BUILD[4]=nacl
SET BUILD[5]=netbsd
SET BUILD[6]=openbsd
SET BUILD[7]=plan9
SET BUILD[8]=solaris
SET BUILD[9]=windows
setlocal enabledelayedexpansion
set CGO_ENABLED=0
If EXIST "!BUILDSPATH!" (
echo Build structure is already there
echo.
) ELSE (
echo Creating build structure...
echo.
md !BUILDSPATH!
for /F "tokens=2 delims==" %%a in ('set BUILD[') do (
md !BUILDSPATH!\%%a
)
echo Build structure created
echo.
)
REM Bring code to last version
echo Pulling all commits...
git pull
echo.
REM Create Changelog
echo Building changelog...
git log --oneline --decorate > CHANGELOG
echo Changelog Build Finished
echo.
for /f %%i in ('git rev-parse HEAD') do set @gitrev=%%i
for /f %%i in ('date /t') do set @bdate=%%i
for /f %%i in ('time /t') do set @btime=%%i
for /F "tokens=2 delims==" %%a in ('set BUILD[') do (
for /F "tokens=2 delims==" %%s in ('set ARCH[') do (
SET GOOS=%%a
SET GOARCH=%%s
SET GOARM=6
echo Building !GOOS!/!GOARCH!
SET EXTENSION=""
IF "%%a"=="windows" (
SET EXTENSION=".exe"
)
go build -ldflags "-s -w -X main.version=%@version% -X main.buildstamp=%@bdate%-%@btime% -X main.hash=%@gitrev%" -o !BUILDSPATH!/!GOOS!/!BINARYNAME!_!GOARCH!!EXTENSION!
IF EXIST "!BUILDSPATH!/!GOOS!/!BINARYNAME!_!GOARCH!!EXTENSION!" (
echo Compressing !GOOS!/!GOARCH!
upx -qq !BUILDSPATH!/!GOOS!/!BINARYNAME!_!GOARCH!!EXTENSION!
)
echo.
)
)
echo.
echo Finished Building
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment