-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.cmd
More file actions
339 lines (310 loc) · 8.45 KB
/
Copy pathpublish.cmd
File metadata and controls
339 lines (310 loc) · 8.45 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "REPO_URL=https://github.com/jassermedhat/visioncart-autonomous-checkout.git"
set "DEFAULT_COMMIT_MESSAGE=Update VisionCart project"
pushd "%~dp0" >nul 2>&1
if errorlevel 1 (
echo Error: Could not open the VisionCart project directory.
exit /b 1
)
where git >nul 2>&1
if errorlevel 1 (
echo Error: Git is not installed or is not available on PATH.
popd
exit /b 1
)
git --version >nul 2>&1
if errorlevel 1 (
echo Error: Git is not working correctly.
popd
exit /b 1
)
set "RUN_CHECKS=0"
if "%~1"=="" (
set "COMMIT_MESSAGE=%DEFAULT_COMMIT_MESSAGE%"
) else if /I "%~1"=="--check" (
set "COMMIT_MESSAGE=%DEFAULT_COMMIT_MESSAGE%"
set "RUN_CHECKS=1"
) else (
set "COMMIT_MESSAGE=%~1"
if not "%~2"=="" (
if /I not "%~2"=="--check" goto :usage
set "RUN_CHECKS=1"
)
)
if /I "%~1"=="--check" (
if not "%~2"=="" goto :usage
) else (
if not "%~3"=="" goto :usage
)
where python >nul 2>&1
if errorlevel 1 (
echo Error: Python is required for the VisionCart credential scan.
popd
exit /b 1
)
if not exist ".git\" (
echo Initializing Git repository...
git init
if errorlevel 1 (
echo Git initialization failed.
popd
exit /b 1
)
git branch -M main
if errorlevel 1 (
echo Failed to configure the main branch.
popd
exit /b 1
)
)
for /f "delims=" %%B in ('git branch --show-current 2^>nul') do set "CURRENT_BRANCH=%%B"
if not "%CURRENT_BRANCH%"=="main" (
echo Error: The current branch is "%CURRENT_BRANCH%". Switch to main before publishing.
popd
exit /b 1
)
call :ensure_origin
if errorlevel 1 (
popd
exit /b 1
)
for %%P in (
".env"
".local\publish-safety-probe"
"data\raw\publish-safety-probe"
"data\processed\publish-safety-probe"
"models\publish-safety-probe.pt"
"models\publish-safety-probe.pth"
"models\publish-safety-probe.ckpt"
"models\publish-safety-probe.onnx"
"models\publish-safety-probe.engine"
"frontend\node_modules\publish-safety-probe"
"frontend\dist\publish-safety-probe"
"outputs\publish-safety-probe"
"transactions\publish-safety-probe"
"runs\publish-safety-probe"
"logs\publish-safety-probe"
) do (
git check-ignore -q -- "%%~P"
if errorlevel 1 (
echo Error: Required private/generated path "%%~P" is not ignored.
goto :safety_failed
)
)
for %%P in (
".env.example"
"reports\publish-safety-probe.json"
"assets\demo\publish-safety-probe.jpg"
"assets\ui\publish-safety-probe.png"
"src\visioncart\publish-safety-probe.py"
"frontend\src\publish-safety-probe.ts"
) do (
git check-ignore -q -- "%%~P"
if not errorlevel 1 (
echo Error: Required portfolio path "%%~P" is ignored.
goto :safety_failed
)
)
call :reject_tracked_private
if errorlevel 1 goto :safety_failed
echo Running VisionCart credential scan...
python scripts\security_scan.py --output reports\security_scan.json
if errorlevel 1 (
echo Security validation failed. Nothing was staged or published.
popd
exit /b 1
)
if "%RUN_CHECKS%"=="1" (
echo Running optional VisionCart validation...
python -m pytest -q
if errorlevel 1 goto :validation_failed
python -m ruff check .
if errorlevel 1 goto :validation_failed
python -m compileall -q src scripts app.py run.py
if errorlevel 1 goto :validation_failed
pushd frontend >nul
if errorlevel 1 goto :validation_failed
call npm test
if errorlevel 1 (
popd
goto :validation_failed
)
call npm run typecheck
if errorlevel 1 (
popd
goto :validation_failed
)
call npm run lint
if errorlevel 1 (
popd
goto :validation_failed
)
call npm run build
if errorlevel 1 (
popd
goto :validation_failed
)
popd
)
call :check_remote_main
if errorlevel 1 (
popd
exit /b 1
)
git add .
if errorlevel 1 (
echo Staging failed.
popd
exit /b 1
)
git diff --cached --quiet
set "DIFF_EXIT=%ERRORLEVEL%"
if "%DIFF_EXIT%"=="0" (
echo Nothing to commit. Working tree is up to date.
popd
exit /b 0
)
if not "%DIFF_EXIT%"=="1" (
echo Could not inspect staged changes.
popd
exit /b 1
)
echo.
echo Commit message:
echo %COMMIT_MESSAGE%
echo.
echo Git status:
git status --short
if errorlevel 1 (
echo Could not display Git status.
popd
exit /b 1
)
echo.
echo Files staged:
git diff --cached --name-status
if errorlevel 1 (
echo Could not display staged files.
popd
exit /b 1
)
echo.
call :confirm_publish
if errorlevel 1 goto :cancelled
git commit -m "%COMMIT_MESSAGE%"
if errorlevel 1 (
echo Commit failed. Nothing was pushed.
popd
exit /b 1
)
git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" >nul 2>&1
if errorlevel 1 (
git push -u origin main
) else (
git push origin main
)
if errorlevel 1 (
echo Push failed. The local commit is preserved.
echo The remote may have changed or authentication may be required.
echo Review the remote history and retry without rewriting it.
popd
exit /b 1
)
echo Publish complete.
popd
exit /b 0
:usage
echo Usage: publish.cmd ["commit message"] [--check]
popd
exit /b 1
:cancelled
echo Publish cancelled. No commit or push was created.
popd
exit /b 0
:safety_failed
echo Publishing safety checks failed. Nothing was staged or published.
popd
exit /b 1
:validation_failed
echo Project validation failed. Nothing was staged or published.
popd
exit /b 1
:confirm_publish
set "CONFIRM="
set /p "CONFIRM=Continue with commit and push? [Y/N] "
if /I "%CONFIRM%"=="Y" exit /b 0
exit /b 1
:ensure_origin
git remote get-url origin >nul 2>&1
if errorlevel 1 goto :add_origin
set "ORIGIN_URL="
for /f "delims=" %%R in ('git remote get-url origin 2^>nul') do set "ORIGIN_URL=%%R"
if /I "%ORIGIN_URL%"=="%REPO_URL%" (
echo Existing origin is correct: %ORIGIN_URL%
exit /b 0
)
echo Error: Existing origin points to a different repository.
echo Existing origin: %ORIGIN_URL%
echo Expected origin: %REPO_URL%
echo No remote configuration was changed.
exit /b 1
:add_origin
git remote add origin "%REPO_URL%"
if errorlevel 1 (
echo Failed to configure the origin remote.
exit /b 1
)
echo Configured origin: %REPO_URL%
exit /b 0
:reject_tracked_private
set "TRACKED_PRIVATE_FILE=%TEMP%\visioncart-tracked-%RANDOM%-%RANDOM%.txt"
git ls-files -- ".env" ".local" "data/raw" "data/processed" "models/*.pt" "models/*.pth" "models/*.ckpt" "models/*.onnx" "models/*.engine" "frontend/node_modules" "frontend/dist" "outputs" "transactions" "transactions.jsonl" "transactions.csv" "local_transactions" "logs" "runs" "wandb" "checkpoints" "*.mp3" >"%TRACKED_PRIVATE_FILE%"
if errorlevel 1 (
del "%TRACKED_PRIVATE_FILE%" >nul 2>&1
echo Could not inspect tracked private files.
exit /b 1
)
for %%F in ("%TRACKED_PRIVATE_FILE%") do set "TRACKED_PRIVATE_SIZE=%%~zF"
if "%TRACKED_PRIVATE_SIZE%"=="0" (
del "%TRACKED_PRIVATE_FILE%" >nul 2>&1
exit /b 0
)
echo Error: Private or generated files are already tracked:
type "%TRACKED_PRIVATE_FILE%"
del "%TRACKED_PRIVATE_FILE%" >nul 2>&1
echo Remove these paths from the Git index without deleting local files, then retry.
exit /b 1
:check_remote_main
set "REMOTE_HEAD_FILE=%TEMP%\visioncart-publish-%RANDOM%-%RANDOM%.txt"
git ls-remote --heads origin refs/heads/main >"%REMOTE_HEAD_FILE%" 2>nul
if errorlevel 1 (
del "%REMOTE_HEAD_FILE%" >nul 2>&1
echo Remote history check failed. Verify network access and GitHub authentication.
exit /b 1
)
for %%F in ("%REMOTE_HEAD_FILE%") do set "REMOTE_HEAD_SIZE=%%~zF"
del "%REMOTE_HEAD_FILE%" >nul 2>&1
if "%REMOTE_HEAD_SIZE%"=="0" exit /b 0
git fetch --quiet origin main
if errorlevel 1 (
echo Remote history fetch failed. Nothing was staged or published.
exit /b 1
)
git rev-parse --verify HEAD >nul 2>&1
if errorlevel 1 (
echo Error: origin/main already has history but this local repository has no commits.
echo Integrate the remote history manually before publishing.
exit /b 1
)
git merge-base --is-ancestor origin/main HEAD >nul 2>&1
if not errorlevel 1 exit /b 0
git merge-base --is-ancestor HEAD origin/main >nul 2>&1
if not errorlevel 1 (
echo Error: origin/main contains commits that are not present locally.
echo Update the local branch manually before publishing.
exit /b 1
)
echo Error: Local main and origin/main have diverged.
echo Resolve the history manually before publishing.
exit /b 1