-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bat
More file actions
158 lines (132 loc) · 4.17 KB
/
build.bat
File metadata and controls
158 lines (132 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
@echo off
setlocal enabledelayedexpansion
echo ============================================================
echo Pitcher Cross-Platform Build Script
echo ============================================================
if not exist VERSION (
echo ERROR: VERSION file not found
exit /b 1
)
set /p VERSION= < VERSION
if "!VERSION!"=="" (
echo ERROR: VERSION file is empty
exit /b 1
)
set VDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
if not exist dist mkdir dist
if not exist releases mkdir releases
echo.
echo [Build Server] windows amd64
go build -ldflags "-s -w" -o dist\pitcher-server-!VERSION!-windows-amd64.exe .\cmd\server\
if errorlevel 1 goto :fail
echo [Build Frontend]
if not exist web\node_modules (
cd web & call npm install & cd ..
)
cd web
call npm run build
if errorlevel 1 goto :fail
cd ..
echo.
echo ============================================================
echo Building Agent: all platforms
echo ============================================================
set BUILD_LOG=build_agent.log
echo. > %BUILD_LOG%
set AGENT_ARCHS=amd64 arm64 386 arm
set AGENT_PLATS=windows linux darwin
for %%p in (%AGENT_PLATS%) do (
for %%a in (%AGENT_ARCHS%) do (
set SKIP_BUILD=0
if %%p==darwin if %%a==386 (
echo [SKIP] darwin/386 - not supported
set SKIP_BUILD=1
)
if %%p==windows if %%a==arm (
echo [SKIP] windows/arm - not supported
set SKIP_BUILD=1
)
if %%p==darwin if %%a==arm (
echo [SKIP] darwin/arm - not supported
set SKIP_BUILD=1
)
if !SKIP_BUILD!==1 (
echo [SKIP] %%p/%%a
) else (
set OUTFILE=dist\pitcher-agent-!VERSION!-%%p-%%a.exe
if %%p==linux set OUTFILE=dist\pitcher-agent-!VERSION!-linux-%%a
if %%p==darwin set OUTFILE=dist\pitcher-agent-!VERSION!-darwin-%%a
echo [Build] %%p/%%a - !OUTFILE!
pushd agent
set GOOS=%%p
set GOARCH=%%a
go build -ldflags "-s -w" -o ..\!OUTFILE! .\cmd\
set BUILD_CODE=!errorlevel!
popd
if !BUILD_CODE! neq 0 (
echo [FAIL] %%p/%%a >> ..\%BUILD_LOG%
) else (
echo [OK] !OUTFILE!
)
)
)
)
echo.
echo ============================================================
echo Generating releases manifest
echo ============================================================
set MANIFEST_TMP=releases\manifest.tmp
echo { > %MANIFEST_TMP%
echo "version": "!VERSION!", >> %MANIFEST_TMP%
echo "build_date": "%VDATE%", >> %MANIFEST_TMP%
echo "files": [ >> %MANIFEST_TMP%
set FIRST=1
for %%f in (dist\pitcher-agent-!VERSION!-*) do (
if not defined FIRST (
echo ,>> %MANIFEST_TMP%
)
set FIRST=
set FN=%%~nxf
for %%s in ("%%f") do set FSIZE=%%~zs
for %%a in (amd64 arm64 386 arm) do (
echo !FN! | find "-linux-%%a" >nul && (
set FOS=linux
set FARCH=%%a
)
echo !FN! | find "-darwin-%%a" >nul && (
set FOS=darwin
set FARCH=%%a
)
echo !FN! | find "-windows-%%a.exe" >nul && (
set FOS=windows
set FARCH=%%a
)
)
for /f "delims=" %%h in ('powershell -NoProfile -Command "(Get-FileHash -Path '%%f' -Algorithm SHA256).Hash"') do set SHA256=%%h
echo { >> %MANIFEST_TMP%
echo "filename": "!FN!", >> %MANIFEST_TMP%
echo "os": "!FOS!", >> %MANIFEST_TMP%
echo "arch": "!FARCH!", >> %MANIFEST_TMP%
echo "size": !FSIZE!, >> %MANIFEST_TMP%
echo "sha256": "!SHA256!" >> %MANIFEST_TMP%
echo } >> %MANIFEST_TMP%
)
echo ] >> %MANIFEST_TMP%
echo } >> %MANIFEST_TMP%
move /Y %MANIFEST_TMP% releases\manifest.json
echo.
echo ============================================================
echo All builds complete!
echo ============================================================
echo Server: dist\pitcher-server-!VERSION!-windows-amd64.exe
echo Agent binaries:
dir /b dist\pitcher-agent-!VERSION!-*
echo.
echo Releases manifest: releases\manifest.json
goto :end
:fail
echo.
echo Build failed!
exit /b 1
:end
endlocal