-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.bat
More file actions
100 lines (85 loc) · 3.43 KB
/
release.bat
File metadata and controls
100 lines (85 loc) · 3.43 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
@echo off
setlocal enabledelayedexpansion
pushd "%~dp0"
set ROOT=%CD%
title SpaceMouse Pilot — Release
:: ── version (single source of truth: src\version.py) ────────────────────────
for /f %%v in ('python -c "from src.version import VERSION; print(VERSION)"') do set VERSION=%%v
if "%VERSION%"=="" (
echo ERROR: Could not read version from src\version.py
goto :fail
)
set TAG=v%VERSION%
set INSTALLER=%ROOT%\dist\installer\SpaceMousePilot_Setup_%VERSION%.exe
echo.
echo ============================================
echo SpaceMouse Pilot — GitHub Release %TAG%
echo ============================================
echo.
:: ── checks ───────────────────────────────────────────────────────────────────
gh --version >nul 2>&1
if errorlevel 1 (
echo ERROR: GitHub CLI not found.
echo Install from https://cli.github.com/ then run: gh auth login
goto :fail
)
if not exist "%INSTALLER%" (
echo ERROR: Installer not found:
echo %INSTALLER%
echo Run build.bat first.
goto :fail
)
git diff --quiet HEAD >nul 2>&1
if errorlevel 1 (
echo WARNING: You have uncommitted changes.
echo Press any key to release anyway, or Ctrl+C to cancel.
pause >nul
)
:: ── clean up orphaned tags (tags with no release) ────────────────────────────
echo [1/4] Cleaning up orphaned tags...
for /f "delims=" %%t in ('gh release list --json tagName --jq ".[].tagName" 2^>nul') do (
set "HAS_RELEASE_%%t=1"
)
for /f "delims=" %%t in ('git tag') do (
if not defined HAS_RELEASE_%%t (
echo [cleanup] Deleting orphaned tag %%t...
git tag -d %%t >nul 2>&1
git push origin --delete %%t >nul 2>&1
)
)
:: ── tag ──────────────────────────────────────────────────────────────────────
echo [2/4] Tagging %TAG%...
git tag -f %TAG%
if errorlevel 1 ( echo ERROR: Failed to create tag. & goto :fail )
echo [3/4] Pushing tag to origin...
git push origin %TAG% --force
if errorlevel 1 ( echo ERROR: git push failed. & goto :fail )
:: ── release ──────────────────────────────────────────────────────────────────
echo [4/4] Creating GitHub release...
set NOTES=%ROOT%\release_notes.md
python "%ROOT%\tools\write_notes.py" %VERSION% "%NOTES%"
if errorlevel 1 ( echo ERROR: Failed to write release notes. & goto :fail )
gh release view %TAG% >nul 2>&1
if errorlevel 1 (
echo [gh] Creating new release %TAG%...
gh release create %TAG% "%INSTALLER%" --title "SpaceMouse Pilot %TAG%" --notes-file "%NOTES%" --latest
) else (
echo [gh] Release %TAG% already exists, updating...
gh release upload %TAG% "%INSTALLER%" --clobber
gh release edit %TAG% --title "SpaceMouse Pilot %TAG%" --notes-file "%NOTES%" --latest
)
if errorlevel 1 ( echo ERROR: gh release failed. & del "%NOTES%" 2>nul & goto :fail )
del "%NOTES%" 2>nul
echo.
echo Release %TAG% published successfully.
echo.
popd
pause
exit /b 0
:fail
echo.
echo Release failed. See errors above.
echo.
popd
pause
exit /b 1