-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_invigo.ps1
More file actions
151 lines (119 loc) · 4.15 KB
/
build_invigo.ps1
File metadata and controls
151 lines (119 loc) · 4.15 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
$ErrorActionPreference = "Stop"
# ================= CONFIG =================
$REPO_URL = "https://github.com/TheCodingJsoftware/Invigo.git"
$PROJECT_DIR = "Invigo-Build"
$SPEC_FILE = "Invigo.spec"
$UV = "uv"
$ENV_FILE = Join-Path $PROJECT_DIR ".env"
# ================= LOAD .env =================
if (-not (Test-Path $ENV_FILE)) {
Write-Error ".env file not found at $ENV_FILE"
}
Get-Content $ENV_FILE |
Where-Object { $_ -match "=" -and -not $_.StartsWith("#") } |
ForEach-Object {
$k, $v = $_ -split "=", 2
Set-Variable -Name $k -Value $v -Scope Script
}
$SOFTWARE_API_BASE = $SOFTWARE_API_BASE.Trim().Trim('"')
if (-not $SOFTWARE_API_BASE) {
Write-Error "SOFTWARE_API_BASE not set in .env"
}
# ================= CLONE OR PULL =================
if (-not (Test-Path $PROJECT_DIR)) {
Write-Host "Cloning repository..."
git clone $REPO_URL $PROJECT_DIR
} else {
Write-Host "Pulling latest changes..."
Push-Location $PROJECT_DIR
git pull
Pop-Location
}
# ================= ENTER PROJECT DIR =================
Set-Location $PROJECT_DIR
# ================= ENSURE uv =================
Write-Host "Ensuring uv is installed..."
python -m pip install --upgrade pip | Out-Null
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host "Installing uv..."
pip install uv
}
# ================= VENV =================
if (-not (Test-Path ".venv")) {
Write-Host "Creating virtual environment..."
uv venv
}
Write-Host "Activating virtual environment..."
& ".\.venv\Scripts\Activate.ps1"
# ================= DEPENDENCIES =================
if (Test-Path "pyproject.toml") {
Write-Host "Installing dependencies from pyproject.toml..."
uv pip install .
}
elseif (Test-Path "requirements.txt") {
Write-Host "Installing dependencies from requirements.txt..."
uv pip install -r requirements.txt
}
else {
throw "No pyproject.toml or requirements.txt found"
}
# ================= FETCH CURRENT VERSION =================
Write-Host "Fetching current version..."
$currentVersion = $null
try {
$resp = Invoke-RestMethod "$SOFTWARE_API_BASE/version"
$currentVersion = $resp.version
} catch {}
if ($currentVersion) {
Write-Host "Current version: $currentVersion"
} else {
Write-Host "No existing version found"
}
# ================= AUTO-INCREMENT VERSION =================
if (-not $currentVersion) {
$nextVersion = "0.1.0"
} else {
$p = $currentVersion.Split(".")
$nextVersion = "{0}.{1}.{2}" -f $p[0], $p[1], ([int]$p[2] + 1)
}
$newVersion = Read-Host "Press ENTER to accept [$nextVersion] or type a different version"
if (-not $newVersion) {
$newVersion = $nextVersion
}
$changelog = Read-Host "Enter release notes / changelog"
Write-Host "Using version: $newVersion"
# ================= BUILD =================
Write-Host "Building with PyInstaller..."
pyinstaller $SPEC_FILE
# ================= COPY RESOURCES =================
Write-Host "Copying resources..."
Copy-Item ui\themes dist\ui\themes -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item ui\style dist\ui\style -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item icons dist\icons -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item sounds dist\sounds -Recurse -Force -ErrorAction SilentlyContinue
"LICENSE","README.md","CHANGELOG.md" | ForEach-Object {
if (Test-Path $_) {
Copy-Item $_ dist\ -Force
}
}
# ================= ZIP =================
Write-Host "Zipping dist directory..."
$zipPath = "Invigo.zip"
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
Compress-Archive -Path "dist\*" -DestinationPath $zipPath -Force
if (-not (Test-Path $zipPath)) {
throw "ZIP creation failed"
}
# ================= UPLOAD =================
Write-Host "Uploading Invigo.zip..."
& curl.exe -X POST `
"$SOFTWARE_API_BASE/upload?version=$newVersion&uploaded_by=jared&changelog=$([uri]::EscapeDataString($changelog))" `
-F "file=@$zipPath"
Write-Host "Upload successful"
# ================= VERIFY =================
$verify = Invoke-RestMethod "$SOFTWARE_API_BASE/version"
Write-Host "Server reports version: $($verify.version)"
Write-Host "=== Build complete ==="
Pause