Skip to content

Commit f5fd50b

Browse files
committed
New build method
1 parent d630de4 commit f5fd50b

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

build_invigo.ps1

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
# ================= CONFIG =================
4+
$REPO_URL = "https://github.com/TheCodingJsoftware/Invigo.git"
5+
$PROJECT_DIR = "Invigo-Build"
6+
$SPEC_FILE = "Invigo.spec"
7+
$UV = "uv"
8+
$ENV_FILE = Join-Path $PROJECT_DIR ".env"
9+
10+
# ================= LOAD .env =================
11+
if (-not (Test-Path $ENV_FILE)) {
12+
Write-Error ".env file not found at $ENV_FILE"
13+
}
14+
15+
Get-Content $ENV_FILE |
16+
Where-Object { $_ -match "=" -and -not $_.StartsWith("#") } |
17+
ForEach-Object {
18+
$k, $v = $_ -split "=", 2
19+
Set-Variable -Name $k -Value $v -Scope Script
20+
}
21+
22+
$SOFTWARE_API_BASE = $SOFTWARE_API_BASE.Trim().Trim('"')
23+
24+
if (-not $SOFTWARE_API_BASE) {
25+
Write-Error "SOFTWARE_API_BASE not set in .env"
26+
}
27+
28+
# ================= CLONE OR PULL =================
29+
if (-not (Test-Path $PROJECT_DIR)) {
30+
Write-Host "Cloning repository..."
31+
git clone $REPO_URL $PROJECT_DIR
32+
} else {
33+
Write-Host "Pulling latest changes..."
34+
Push-Location $PROJECT_DIR
35+
git pull
36+
Pop-Location
37+
}
38+
39+
# ================= ENTER PROJECT DIR =================
40+
Set-Location $PROJECT_DIR
41+
42+
# ================= ENSURE uv =================
43+
Write-Host "Ensuring uv is installed..."
44+
python -m pip install --upgrade pip | Out-Null
45+
46+
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
47+
Write-Host "Installing uv..."
48+
pip install uv
49+
}
50+
51+
# ================= VENV =================
52+
if (-not (Test-Path ".venv")) {
53+
Write-Host "Creating virtual environment..."
54+
uv venv
55+
}
56+
57+
Write-Host "Activating virtual environment..."
58+
& ".\.venv\Scripts\Activate.ps1"
59+
60+
# ================= DEPENDENCIES =================
61+
if (Test-Path "pyproject.toml") {
62+
Write-Host "Installing dependencies from pyproject.toml..."
63+
uv pip install .
64+
}
65+
elseif (Test-Path "requirements.txt") {
66+
Write-Host "Installing dependencies from requirements.txt..."
67+
uv pip install -r requirements.txt
68+
}
69+
else {
70+
throw "No pyproject.toml or requirements.txt found"
71+
}
72+
73+
# ================= FETCH CURRENT VERSION =================
74+
Write-Host "Fetching current version..."
75+
76+
$currentVersion = $null
77+
try {
78+
$resp = Invoke-RestMethod "$SOFTWARE_API_BASE/version"
79+
$currentVersion = $resp.version
80+
} catch {}
81+
82+
if ($currentVersion) {
83+
Write-Host "Current version: $currentVersion"
84+
} else {
85+
Write-Host "No existing version found"
86+
}
87+
88+
# ================= AUTO-INCREMENT VERSION =================
89+
if (-not $currentVersion) {
90+
$nextVersion = "0.1.0"
91+
} else {
92+
$p = $currentVersion.Split(".")
93+
$nextVersion = "{0}.{1}.{2}" -f $p[0], $p[1], ([int]$p[2] + 1)
94+
}
95+
96+
$newVersion = Read-Host "Press ENTER to accept [$nextVersion] or type a different version"
97+
if (-not $newVersion) {
98+
$newVersion = $nextVersion
99+
}
100+
101+
$changelog = Read-Host "Enter release notes / changelog"
102+
103+
Write-Host "Using version: $newVersion"
104+
105+
# ================= BUILD =================
106+
Write-Host "Building with PyInstaller..."
107+
pyinstaller $SPEC_FILE
108+
109+
# ================= COPY RESOURCES =================
110+
Write-Host "Copying resources..."
111+
112+
Copy-Item ui\themes dist\ui\themes -Recurse -Force -ErrorAction SilentlyContinue
113+
Copy-Item ui\style dist\ui\style -Recurse -Force -ErrorAction SilentlyContinue
114+
Copy-Item icons dist\icons -Recurse -Force -ErrorAction SilentlyContinue
115+
Copy-Item sounds dist\sounds -Recurse -Force -ErrorAction SilentlyContinue
116+
117+
"LICENSE","README.md","CHANGELOG.md" | ForEach-Object {
118+
if (Test-Path $_) {
119+
Copy-Item $_ dist\ -Force
120+
}
121+
}
122+
123+
# ================= ZIP =================
124+
Write-Host "Zipping dist directory..."
125+
126+
$zipPath = "Invigo.zip"
127+
if (Test-Path $zipPath) {
128+
Remove-Item $zipPath -Force
129+
}
130+
131+
Compress-Archive -Path "dist\*" -DestinationPath $zipPath -Force
132+
133+
if (-not (Test-Path $zipPath)) {
134+
throw "ZIP creation failed"
135+
}
136+
137+
# ================= UPLOAD =================
138+
Write-Host "Uploading Invigo.zip..."
139+
140+
& curl.exe -X POST `
141+
"$SOFTWARE_API_BASE/upload?version=$newVersion&uploaded_by=jared&changelog=$([uri]::EscapeDataString($changelog))" `
142+
-F "file=@$zipPath"
143+
144+
Write-Host "Upload successful"
145+
146+
# ================= VERIFY =================
147+
$verify = Invoke-RestMethod "$SOFTWARE_API_BASE/version"
148+
Write-Host "Server reports version: $($verify.version)"
149+
150+
Write-Host "=== Build complete ==="
151+
Pause

0 commit comments

Comments
 (0)