-
-
Notifications
You must be signed in to change notification settings - Fork 1
329 lines (287 loc) · 13 KB
/
Copy pathbuild-installer.yml
File metadata and controls
329 lines (287 loc) · 13 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
name: Build Installer
on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-staging'
workflow_dispatch:
inputs:
version:
description: 'Version (e.g., 1.0.0 or 1.0.0-staging)'
required: false
default: ''
staging:
description: 'Staging build (no server upload)'
type: boolean
default: false
env:
PYREVIT_VERSION: "5.3.1.25308"
PYREVIT_URL: "https://github.com/pyrevitlabs/pyRevit/releases/download/v5.3.1.25308%2B1659/pyRevit_5.3.1.25308_signed.exe"
permissions:
contents: write
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: version
shell: pwsh
run: |
if ("${{ github.event.inputs.version }}" -ne "") {
$version = "${{ github.event.inputs.version }}"
} elseif ($env:GITHUB_REF -match "refs/tags/v(.+)") {
$version = $matches[1]
} else {
$version = "0.0.1-dev"
}
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
# Determine if this is a staging build
$isStaging = $false
if ("${{ github.event.inputs.staging }}" -eq "true") {
$isStaging = $true
} elseif ($version -match "-staging$") {
$isStaging = $true
}
echo "IS_STAGING=$isStaging" >> $env:GITHUB_OUTPUT
Write-Host "Version: $version, Staging: $isStaging"
- name: Prepare build directory
shell: pwsh
run: |
New-Item -ItemType Directory -Path "build" -Force
Copy-Item -Path "pyrevit.extension" -Destination "build\CPSK.extension" -Recurse
Copy-Item -Path "installer\scripts\*" -Destination "build\" -Force
# Copy requirements.txt, version.yaml and config.py to root (not extension!)
Copy-Item -Path "requirements.txt" -Destination "build\" -Force
Copy-Item -Path "version.yaml" -Destination "build\" -Force
Copy-Item -Path "config.py" -Destination "build\" -Force
- name: Remove dev tools from build
shell: pwsh
run: |
$libDir = "build\CPSK.extension\lib"
# Remove dev tools not needed in production
$devTools = @("pyrevit_checker.py")
foreach ($tool in $devTools) {
$path = Join-Path $libDir $tool
if (Test-Path $path) {
Remove-Item $path -Force
Write-Host "Removed: $tool (dev tool)"
}
}
Write-Host "Files in lib:"
Get-ChildItem $libDir | ForEach-Object { Write-Host " $($_.Name)" }
- name: Set DEBUG=False in config.py
shell: pwsh
run: |
$configFile = "build\config.py"
$content = Get-Content $configFile -Raw -Encoding UTF8
$content = $content -replace 'DEBUG\s*=\s*True', 'DEBUG = False'
[System.IO.File]::WriteAllText($configFile, $content, [System.Text.UTF8Encoding]::new($false))
Write-Host "Set DEBUG = False in config.py"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Minify Python code
shell: pwsh
run: |
Write-Host "Installing python-minifier..."
pip install python-minifier
$libDir = "build\CPSK.extension\lib"
Write-Host "=== Minifying Python files in $libDir ==="
# Encoding declaration required for IronPython with non-ASCII characters
$encodingDecl = "# -*- coding: utf-8 -*-`n"
# Files to minify (lib modules)
Get-ChildItem "$libDir\*.py" | ForEach-Object {
if ($_.Name -ne "__init__.py") {
$originalSize = $_.Length
Write-Host "Minifying: $($_.Name) ($originalSize bytes)"
# Minify with Python 2 compatible settings (no transforms that could break IronPython)
$tempFile = "$($_.FullName).min"
python -m python_minifier $_.FullName --remove-literal-statements --no-remove-annotations --no-hoist-literals --no-rename-locals --no-convert-posargs-to-args -o $tempFile
if (Test-Path $tempFile) {
# Add encoding declaration back (minifier removes comments)
$content = Get-Content $tempFile -Raw -Encoding UTF8
$content = $encodingDecl + $content
[System.IO.File]::WriteAllText($_.FullName, $content, [System.Text.UTF8Encoding]::new($false))
Remove-Item $tempFile -Force
$newSize = (Get-Item $_.FullName).Length
$reduction = [math]::Round((1 - $newSize / $originalSize) * 100)
Write-Host " [OK] $originalSize -> $newSize bytes (-$reduction%)"
} else {
Write-Host " [WARN] Minification failed, keeping original"
}
}
}
Write-Host "=== Minification complete ==="
- name: Install Inno Setup
shell: pwsh
run: |
choco install innosetup -y
- name: Build Installer
shell: pwsh
run: |
$version = "${{ steps.version.outputs.VERSION }}"
$pyrevitVersion = "${{ env.PYREVIT_VERSION }}"
$pyrevitUrl = "${{ env.PYREVIT_URL }}"
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" `
/DMyAppVersion="$version" `
/DPyRevitVersion="$pyrevitVersion" `
/DPyRevitUrl="$pyrevitUrl" `
/O"." `
"installer\setup.iss"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: CPSK-Tools-Installer
path: "CPSK_Tools_*.exe"
retention-days: 30
- name: Generate release notes
if: startsWith(github.ref, 'refs/tags/')
id: release_notes
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = "${{ steps.version.outputs.VERSION }}"
$lastTag = git describe --tags --abbrev=0 HEAD~1 2>$null
# Get authors
if ($lastTag) {
$authors = git log --pretty=format:"%an" "$lastTag..HEAD" --no-merges | Sort-Object -Unique | Where-Object { $_ -ne "github-actions[bot]" -and $_ -ne "" }
} else {
$authors = git log --pretty=format:"%an" -10 --no-merges | Sort-Object -Unique | Where-Object { $_ -ne "github-actions[bot]" -and $_ -ne "" }
}
# Try to get PR description (smart approach)
$prBody = ""
$prAuthor = ""
$prNumber = ""
$mergeCommit = git log --merges --pretty=format:"%s" -1 2>$null
if ($mergeCommit -match "Merge pull request #(\d+)") {
$prNumber = $matches[1]
Write-Host "Found merged PR #$prNumber"
try {
# Get PR body and author
$prData = gh pr view $prNumber --json body,author 2>$null | ConvertFrom-Json
$prBody = $prData.body
$prAuthor = $prData.author.login
Write-Host "PR author: @$prAuthor"
# Clean PR body - remove technical sections
$opts = [System.Text.RegularExpressions.RegexOptions]::Singleline
$prBody = [regex]::Replace($prBody, '## Связанные Issues.*?((?=##)|$)', '', $opts)
$prBody = [regex]::Replace($prBody, '## Чеклист.*?((?=##)|$)', '', $opts)
$prBody = [regex]::Replace($prBody, '## Скриншоты.*?((?=##)|$)', '', $opts)
$prBody = [regex]::Replace($prBody, '## Описание\s*\r?\n\s*(Краткое описание изменений\.?)?\s*', '', $opts)
$prBody = [regex]::Replace($prBody, '## Тип изменения.*?((?=##)|$)', '', $opts)
$prBody = [regex]::Replace($prBody, 'Closes #\(номер issue\)', '', $opts)
$prBody = [regex]::Replace($prBody, 'Если применимо.*UI\.?', '', $opts)
$prBody = [regex]::Replace($prBody, '<img[^>]*>', '', $opts)
$prBody = [regex]::Replace($prBody, 'Краткое описание изменений\.?', '', $opts)
# Remove multiple empty lines
$prBody = [regex]::Replace($prBody, '(\r?\n){3,}', "`n`n")
$prBody = $prBody.Trim()
Write-Host "Using PR description"
} catch {
Write-Host "Could not get PR body: $_"
}
}
# Build content section
if ($prBody) {
$changes = $prBody
} else {
# Fallback to commits
Write-Host "No PR found, using commits"
if ($lastTag) {
$commitList = git log --pretty=format:"- %s" "$lastTag..HEAD" --no-merges | Where-Object { $_ -notmatch "Release v" }
} else {
$commitList = git log --pretty=format:"- %s" -10 --no-merges | Where-Object { $_ -notmatch "Release v" }
}
$changes = "### Изменения`n" + ($commitList -join "`n")
}
# Build authors section
$authorsSection = ""
if ($prAuthor) {
# PR author with GitHub link
$authorsSection = "### Авторы`n- [@$prAuthor](https://github.com/$prAuthor)"
# Add commit authors if different
$otherAuthors = $authors | Where-Object { $_ -ne $prAuthor }
if ($otherAuthors) {
$authorsSection += "`n" + (($otherAuthors | ForEach-Object { "- $_" }) -join "`n")
}
} elseif ($authors) {
$authorsSection = "### Авторы`n" + (($authors | ForEach-Object { "- $_" }) -join "`n")
}
# Server notes
$serverNotes = "## CPSK Tools v$version`n`n$changes"
if ($authorsSection) {
$serverNotes += "`n`n$authorsSection"
}
$serverNotes += "`n`n### Требования`n- Windows 10/11`n- Autodesk Revit 2021-2025"
$serverNotes | Out-File -FilePath "release_notes.txt" -Encoding UTF8
# GitHub notes (with install instructions)
$githubNotes = "## CPSK Tools v$version`n`n"
$githubNotes += "### Установка`n1. Скачайте ``CPSK_Tools_v$version.exe```n2. Запустите установщик`n3. Перезапустите Revit`n`n"
$githubNotes += $changes
if ($authorsSection) {
$githubNotes += "`n`n$authorsSection"
}
$githubNotes += "`n`n### Требования`n- Windows 10/11`n- Autodesk Revit 2021-2025"
$githubNotes | Out-File -FilePath "github_release_notes.txt" -Encoding UTF8
Write-Host "=== Release notes generated ==="
- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
name: "CPSK Tools v${{ steps.version.outputs.VERSION }}"
body_path: github_release_notes.txt
files: "CPSK_Tools_*.exe"
draft: false
prerelease: ${{ steps.version.outputs.IS_STAGING == 'True' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to release server
if: startsWith(github.ref, 'refs/tags/') && steps.version.outputs.IS_STAGING != 'True'
shell: pwsh
run: |
$version = "${{ steps.version.outputs.VERSION }}"
$token = "${{ secrets.RELEASE_API_TOKEN }}"
if (-not $token) {
Write-Host "WARNING: RELEASE_API_TOKEN secret not set, skipping upload"
exit 0
}
$exeFile = Get-ChildItem -Path "." -Filter "CPSK_Tools_*.exe" | Select-Object -First 1
if (-not $exeFile) {
Write-Host "ERROR: No exe file found"
exit 1
}
# Read release notes from file
$releaseNotes = Get-Content -Path "release_notes.txt" -Raw -Encoding UTF8
Write-Host "Uploading $($exeFile.Name) to release server..."
$headers = @{
"Authorization" = "Bearer $token"
}
$form = @{
version = $version
exe_file = Get-Item $exeFile.FullName
release_notes = $releaseNotes
git_tag = "v$version"
git_commit = "${{ github.sha }}"
github_release_url = "https://github.com/${{ github.repository }}/releases/tag/v$version"
min_revit_version = "2021"
max_revit_version = "2025"
}
try {
$response = Invoke-RestMethod -Uri "https://rocket-tools.ru/api/rocketrevit/releases/upload/" `
-Method POST `
-Headers $headers `
-Form $form
Write-Host "Upload successful!"
Write-Host "Response: $($response | ConvertTo-Json)"
} catch {
Write-Host "ERROR: Upload failed: $_"
Write-Host "Response: $($_.ErrorDetails.Message)"
# Don't fail the build if upload fails - GitHub release is already created
Write-Host "WARNING: Server upload failed, but GitHub release was created successfully"
}