-
Notifications
You must be signed in to change notification settings - Fork 3
588 lines (533 loc) · 25.5 KB
/
release_holopatcher.yml
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
name: HoloPatcher Release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
OS_RUNNERS_JSON: '["windows-2019", "ubuntu-20.04", "macos-12"]'
PYTHON_VERSIONS_JSON: '["3.8"]'
ARCHITECTURES_JSON: '["x86", "x64"]'
INTERPRETERS_JSON: '["python"]'
UPX_VERSION: '4.2.2'
on:
push:
tags:
- '*patcher*'
workflow_dispatch:
permissions:
contents: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.set_env.outputs.os }}
python-version: ${{ steps.set_env.outputs.python-version }}
architecture: ${{ steps.set_env.outputs.architecture }}
python-pypy: ${{ steps.set_env.outputs.python-pypy }}
#qt_version: ${#{ steps.set_env.outputs.qt_version }}
steps:
- name: Set environment variables
id: set_env
run: |
$singleLineJson = '${{ env.OS_RUNNERS_JSON }}' -replace "`r", "" -replace "`n", ""
echo "os<<EOF" >> $env:GITHUB_OUTPUT
echo $singleLineJson >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
$singleLineJson = '${{ env.PYTHON_VERSIONS_JSON }}' -replace "`r", "" -replace "`n", ""
echo "python-version<<EOF" >> $env:GITHUB_OUTPUT
echo $singleLineJson >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
$singleLineJson = '${{ env.ARCHITECTURES_JSON }}' -replace "`r", "" -replace "`n", ""
echo "architecture<<EOF" >> $env:GITHUB_OUTPUT
echo $singleLineJson >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
$singleLineJson = '${{ env.INTERPRETERS_JSON }}' -replace "`r", "" -replace "`n", ""
echo "python-pypy<<EOF" >> $env:GITHUB_OUTPUT
echo $singleLineJson >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
shell: pwsh
build:
needs: setup
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # Disable automatic cancellation of other jobs
matrix:
os: ${{ fromJson(needs.setup.outputs.os) }}
python-version: ${{ fromJson(needs.setup.outputs.python-version) }}
architecture: ${{ fromJson(needs.setup.outputs.architecture) }}
python_pypy: ${{ fromJson(needs.setup.outputs.python-pypy) }}
#qt_version: ['pyqt5', 'pyqt6', 'pyside2', 'pyside6']
include:
- arch: x86
vc_redist2015: "https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe"
vc_redist-latest: "https://aka.ms/vs/17/release/vc_redist.x86.exe"
vc_redist2019: "https://aka.ms/vs/17/release/vc_redist.x86.exe"
- arch: x64
vc_redist2015: "https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe"
vc_redist-latest: "https://aka.ms/vs/17/release/vc_redist.x64.exe"
vc_redist2019: "https://aka.ms/vs/17/release/vc_redist.x64.exe"
exclude:
# unix x86 is definitely not supported.
- os: ubuntu-20.04
architecture: x86
- os: macos-12
architecture: x86
# latest PyPy version as of 17/03/2024 is 3.10.
- python_pypy: 'pypy'
python-version: '3.11'
- python_pypy: 'pypy'
python-version: '3.12'
# PyQt5 doesn't seem to be compatible with PyPy
#- python_pypy: "pypy"
# qt_version: 'pyqt5'
#- python_pypy: "pypy"
# qt_version: 'pyside2'
#- python_pypy: "pypy"
# qt_version: 'pyqt6'
#- python_pypy: "pypy"
# python-version: '3.10'
# os: 'windows-2019'
outputs:
matrix-os: ${{ toJson(matrix.os) }}
matrix-python-version: ${{ toJson(matrix.python-version) }}
steps:
- name: Determine Python version string
id: set-python-version
run: |
if ( "${{ matrix.python_pypy }}" -eq "pypy" ) {
Add-Content -Path $env:GITHUB_ENV -Value "PYTHON_VERSION=pypy-${{ matrix.python-version }}"
} else {
Add-Content -Path $env:GITHUB_ENV -Value "PYTHON_VERSION=${{ matrix.python-version }}"
}
shell: pwsh
- uses: actions/checkout@v4
- name: Test Powershell installer
if: ${{ runner.os != 'Windows' }}
id: setup-powershell
run: |
bash ./install_powershell.sh
shell: bash
- name: Set up pypy ${{ matrix.python-version }}
if: ${{ matrix.python_pypy == 'pypy' }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.architecture }}
- name: Reset APT sources to default
if: ${{ runner.os == 'Linux' }}
run: |
echo "Resetting APT sources to default Ubuntu repositories"
sudo rm /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs) main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu $(lsb_release -cs)-security main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
sudo apt-get update -y
shell: bash
- name: Set UPX download URL
# upx docs express that crashes are happening on ventura and above with upx, don't use on mac.
if: runner.os != 'macOS'
id: upx_setup
run: |
$build = "no"
$archiveName = ""
if ("${{ runner.os }}" -eq "Windows") {
if ("${{ matrix.architecture }}" -eq "x86") {
$archiveName = "upx-${{ env.UPX_VERSION }}-win32.zip"
} else {
$archiveName = "upx-${{ env.UPX_VERSION }}-win64.zip"
}
} elseif ("${{ runner.os }}" -eq "Linux") {
$archiveName = "upx-${{ env.UPX_VERSION }}-amd64_linux.tar.xz"
} elseif ("${{ runner.os }}" -eq "macOS") {
$build = "yes"
$archiveName = "upx-${{ env.UPX_VERSION }}-src.tar.xz"
}
$url = "https://github.com/upx/upx/releases/download/v${{ env.UPX_VERSION }}/$archiveName"
# Write to the GITHUB_OUTPUT environment file
Add-Content -Path $env:GITHUB_OUTPUT -Value "build=$build"
Add-Content -Path $env:GITHUB_OUTPUT -Value "url=$url"
Add-Content -Path $env:GITHUB_OUTPUT -Value "archiveName=$archiveName"
shell: pwsh
- name: Download and prepare UPX
if: runner.os != 'macOS'
run: |
$ext = "${{ runner.os }}" -eq "Windows" ? "zip" : "tar.xz"
$url = "${{ steps.upx_setup.outputs.url }}"
$archiveName = "${{ steps.upx_setup.outputs.archiveName }}"
$outputPath = "upx-dir"
# Use Invoke-WebRequest or curl depending on the OS
if ("${{ runner.os }}" -eq "Windows") {
Invoke-WebRequest -Uri $url -OutFile $archiveName
} elseif ("${{ runner.os }}" -eq "Linux") {
curl -L $url -o $archiveName
}
New-Item -ItemType Directory -Force -Path "upx-dir" -ErrorAction SilentlyContinue
if ("${{ runner.os }}" -ne "macOS") {
if ($ext -eq "zip") {
$fileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($archiveName)
Expand-Archive -Path $archiveName -DestinationPath "temp_folder_upx"
# Ensure upx-dir exists; create it if it doesn't
if (-not (Test-Path -Path "upx-dir")) {
New-Item -ItemType Directory -Path "upx-dir"
}
Get-ChildItem -Path "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Remove-Item "temp_folder_upx" -Recurse -Force -ErrorAction SilentlyContinue
} else {
tar -xvf $archiveName --strip-components=1 -C "upx-dir"
}
Remove-Item $archiveName # Clean up downloaded archive
}
shell: pwsh
- name: Set UPX directory path
if: runner.os != 'macOS'
id: upx_dir
run: |
$upx_dir = "./upx-dir"
$upx_dir = $([System.IO.Path]::GetFullPath('./upx-dir'))
Dir -Recurse $upx_dir | Get-Childitem
echo "UPX_DIR=$upx_dir" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Output "UPX_DIR set to '$upx_dir'"
shell: pwsh
- name: Install Visual Studio 2015 C++ Redistributable
if: runner.os == 'Windows'
run: |
$url = "${{ matrix.vc_redist2015 }}"
$output = "vc_redist.exe"
Invoke-WebRequest -Uri $url -OutFile $output
Start-Process $output -ArgumentList '/install', '/quiet', '/norestart' -Wait
Remove-Item -Path $output
#choco install vcredist2015 -y
shell: pwsh
- name: Install Visual Studio 2019 C++ Redistributable
if: runner.os == 'Windows'
run: |
$url = "${{ matrix.vc_redist2019 }}"
$output = "vc_redist.exe"
Invoke-WebRequest -Uri $url -OutFile $output
Start-Process $output -ArgumentList '/install', '/quiet', '/norestart' -Wait
Remove-Item -Path $output
#choco install vcredist2019 -y
shell: pwsh
- name: Install Visual Studio latest C++ Redistributable
if: runner.os == 'Windows'
run: |
$url = "${{ matrix.vc_redist-latest }}"
$output = "vc_redist.exe"
Invoke-WebRequest -Uri $url -OutFile $output
Start-Process $output -ArgumentList '/install', '/quiet', '/norestart' -Wait
Remove-Item -Path $output
shell: pwsh
- name: Install HoloPatcher dependencies
if: ${{ success() || failure() }}
env:
MATRIX_ARCH: ${{ matrix.architecture }}
id: holopatcher_deps
run: | # known pyinstaller versions that work with upx compressions, not all are available on all python versions.
try {
. ./install_python_venv.ps1 -noprompt -venv_name .venv_holopatcher_${{ matrix.os }}_${{ matrix.python_pypy }}_${{ matrix.python-version }}_${{ matrix.architecture }} -force_python_version ${{ matrix.python-version }}
Write-Host "Python executable path: $pythonExePath"
& $pythonExePath -m pip install --upgrade pip
if ("${{ runner.os }}" -eq "Windows") {
if ("${{ matrix.python-version }}" -eq "3.12") {
pip install pyinstaller --prefer-binary -U
} elseif ("${{ matrix.python-version }}" -eq "3.11") {
pip install "pyinstaller==5.13.2" --prefer-binary
} else {
pip install "pyinstaller==5.4" --prefer-binary
}
} else {
pip install pyinstaller -U --prefer-binary
}
$output = ""
$errorLines = @()
. ./compile/deps_holopatcher.ps1 -noprompt -venv_name .venv_holopatcher_${{ matrix.os }}_${{ matrix.python_pypy }}_${{ matrix.python-version }}_${{ matrix.architecture }} 2>&1 | ForEach-Object {
Write-Output $_.ToString()
$output += $_.ToString() + "`n"
if($_ -match 'ERROR:') {
$errorLines += $_.ToString()
}
}
if ($errorLines.Count -gt 0) {
$errorLines | ForEach-Object { Write-Error $_ }
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=false"
exit 1
} else {
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=true"
}
} catch {
Write-Host -ForegroundColor Red "Detailed Error Report:"
Write-Host -ForegroundColor Red "Message: $($_.Exception.Message)"
# Attempt to provide a more detailed location of the error
if ($_.InvocationInfo -and $_.InvocationInfo.MyCommand) {
Write-Host -ForegroundColor Red "Command Name: $($_.InvocationInfo.MyCommand.Name)"
Write-Host -ForegroundColor Red "Script Name: $($_.InvocationInfo.ScriptName)"
Write-Host -ForegroundColor Red "Line Number: $($_.InvocationInfo.ScriptLineNumber)"
Write-Host -ForegroundColor Red "Line: $($_.InvocationInfo.Line)"
} else {
Write-Host -ForegroundColor Red "No invocation information available."
}
# Extract and display the script stack trace if available
if ($_.ScriptStackTrace) {
Write-Host -ForegroundColor Red "Script Stack Trace:"
Write-Host -ForegroundColor Red $_.ScriptStackTrace
} else {
Write-Host -ForegroundColor Red "No script stack trace available."
}
# Log the error to GitHub Actions output or another logging mechanism
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=false"
exit 1
}
shell: pwsh
- name: HoloPatcher - Adjust RPATH for shared libraries in the virtual environment
if: ${{ (success() || failure()) && runner.os == 'Disabled_Linux' && steps.holopatcher_deps.outputs.success == 'true' }}
run: |
. ./install_python_venv.ps1 -noprompt -venv_name .venv_holopatcher_${{ matrix.os }}_${{ matrix.python_pypy }}_${{ matrix.python-version }}_${{ matrix.architecture }}
# Ensure patchelf is installed
sudo apt-get update && sudo apt-get install -y patchelf
# Find the virtual environment's site-packages directory
$venvPath = $env:VIRTUAL_ENV
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
}
shell: pwsh
- name: Compile HoloPatcher
if: ${{ (success() || failure()) && steps.holopatcher_deps.outputs.success == 'true' }}
run: |
$upxDir = $env:UPX_DIR
Write-Host "Using UPX directory at '$upxDir'"
$output = ""
$env:PYTHONOPTIMIZE = "1"
. ./compile/compile_holopatcher.ps1 -noprompt -venv_name .venv_holopatcher_${{ matrix.os }}_${{ matrix.python_pypy }}_${{ matrix.python-version }}_${{ matrix.architecture }} -upx_dir $upxDir 2>&1 | ForEach-Object {
Write-Output $_.ToString()
$output += $_.ToString() + "`n"
if($_ -match 'ERROR:') {
$errorLines += $_.ToString()
}
}
$warningCount = 0
$output -split "`n" | ForEach-Object {
if ($_ -match 'WARNING: Library not found: could not resolve' -or
$_ -match 'WARNING: Cannot find ' -or
$_ -match 'WARNING: lib not found:' -or
$_ -match 'WARNING: Tcl modules directory' -or
$_ -match 'WARNING: Failed to upx strip') {
$warningCount++
}
}
if ($errorLines.Count -gt 0) {
$errorLines | ForEach-Object { Write-Error $_ }
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=false"
exit 1
} elseif ($warningCount -ge 3) {
Write-Output "Many warnings raised, pyinstaller was probably unsuccessful."
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=false"
exit 1
} else {
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=true"
}
shell: pwsh
- name: HoloPatcher - Create Static Binary
if: ${{ (success() || failure()) && runner.os == 'Disabled_Linux' && steps.holopatcher_deps.outputs.success == 'true' }}
run: |
. ./install_python_venv.ps1 -noprompt -venv_name .venv_holopatcher_${{ matrix.os }}_${{ matrix.python_pypy }}_${{ matrix.python-version }}_${{ matrix.architecture }}
& $pythonExePath -m pip install staticx
staticx ./dist/HoloPatcher ./dist/HoloPatcher-static
# Rename the static binary for clarity and consistency
Write-Output "./dist/HoloPatcher-static --> ./dist/HoloPatcher"
Move-Item -LiteralPath ./dist/HoloPatcher-static -Destination ./dist/HoloPatcher -Force
shell: pwsh
- name: Upload HoloPatcher binaries attempt 1
if: ${{ success() || failure() }}
id: upload_attempt_1
uses: actions/upload-artifact@v4
with:
name: HoloPatcher_${{ runner.os }}_${{ matrix.architecture }}
path: ./dist/**
retention-days: 90
continue-on-error: true
- name: Upload HoloPatcher binaries attempt 2
id: upload_attempt_2
if: ${{ (success() || failure()) && steps.upload_attempt_1.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HoloPatcher_${{ runner.os }}_${{ matrix.architecture }}
path: ./dist/**
retention-days: 90
continue-on-error: true
- name: Upload HoloPatcher binaries attempt 3
id: upload_attempt_3
if: ${{ (success() || failure()) && steps.upload_attempt_2.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HoloPatcher_${{ runner.os }}_${{ matrix.architecture }}
path: ./dist/**
retention-days: 90
continue-on-error: true
- name: Upload HoloPatcher binaries attempt 4
id: upload_attempt_4
if: ${{ (success() || failure()) && steps.upload_attempt_3.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HoloPatcher_${{ runner.os }}_${{ matrix.architecture }}
path: ./dist/**
retention-days: 90
continue-on-error: true
- name: Upload HoloPatcher binaries attempt 5
id: upload_attempt_5
if: ${{ (success() || failure()) && steps.upload_attempt_4.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: HoloPatcher_${{ runner.os }}_${{ matrix.architecture }}
path: ./dist/**
retention-days: 90
package:
needs: build # do not start this job until all 'build' jobs complete
if: ${{ success() || failure() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: published_workflow_builds/
pattern: HoloPatcher_*
- name: Compress into archives
run: |
$originalDir = Get-Location
$sourceFolder = Join-Path -Path $originalDir -ChildPath "published_workflow_builds"
Set-Location $sourceFolder
Get-ChildItem -Path "." -Directory | ForEach-Object {
$folderName = $_.Name
$archiveName = "$folderName.zip"
zip -r -9 $archiveName $folderName
}
Set-Location $originalDir
shell: pwsh
- name: Determine Release Tag Ending with 'patcher'
id: get_tag
run: |
if ($env:GITHUB_EVENT_NAME -eq "workflow_dispatch") {
git fetch --depth=1 origin '+refs/tags/*:refs/tags/*'
# Get all tags ending with 'patcher', then pick the most recent one based on how they're listed
$tag = git tag --list '*patcher*' | Select-Object -Last 1
} else {
git fetch --depth=1 origin '+refs/tags/*:refs/tags/*'
# Get all tags ending with 'patcher', then pick the most recent one based on how they're listed
$tag = git tag --list '*patcher*' | Select-Object -Last 1
}
if (-not $tag) {
echo "No matching tag found ending with 'patcher'."
git tag --list
exit 1
}
echo "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
shell: pwsh
- name: Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.get_tag.outputs.tag }}
files: "published_workflow_builds/*.zip"
fail_on_unmatched_files: true
target_commitish: ${{ github.event_name == 'workflow_dispatch' && github.ref_name || github.head_ref }}
- name: Determine Release ID for fallback upload.
if: ${{ failure() }}
id: get_release_id
run: |
# Filter tags ending with 'patcher', sort them by date, and pick the most recent one
$uri = "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.get_tag.outputs.tag }}"
$headers = @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}"}
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers
$releaseId = $response.id
echo "RELEASE_ID=$releaseId" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh
- name: Upload Archive to Release
if: ${{ failure() }}
run: |
try {
Add-Type -TypeDefinition @"
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
public class GitHubUploader {
public static async Task UploadFileAsync(string filePath, string uploadUrl, string token) {
using (var client = new HttpClient()) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
using (var content = new MultipartFormDataContent()) {
var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filePath));
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
content.Add(fileContent, "file", System.IO.Path.GetFileName(filePath));
var response = await client.PostAsync(uploadUrl, content);
if (!response.IsSuccessStatusCode) {
throw new ApplicationException(await response.Content.ReadAsStringAsync());
}
}
}
}
}
"@
$archivePath = "published_workflow_builds/*.zip"
$releaseId = $env:RELEASE_ID
$token = "${{ secrets.GITHUB_TOKEN }}""
Get-ChildItem -Path $archivePath | ForEach-Object {
$filePath = $_.FullName
$fileName = $_.Name
$uploadUrl = "https://uploads.github.com/repos/$env:GITHUB_REPOSITORY/releases/$releaseId/assets?name=$fileName&label=$fileName"
try {
Write-Host "Attempting to upload $fileName"
[GitHubUploader]::UploadFileAsync($filePath, $uploadUrl, $token).GetAwaiter().GetResult()
Write-Host "Upload successful: $fileName"
} catch {
Write-Host "Failed to upload $fileName : $($_.Exception.Message)"
Write-Host -ForegroundColor Red "Detailed Error Report:"
Write-Host -ForegroundColor Red "Message: $($_.Exception.Message)"
# Attempt to provide a more detailed location of the error
if ($_.InvocationInfo -and $_.InvocationInfo.MyCommand) {
Write-Host -ForegroundColor Red "Command Name: $($_.InvocationInfo.MyCommand.Name)"
Write-Host -ForegroundColor Red "Script Name: $($_.InvocationInfo.ScriptName)"
Write-Host -ForegroundColor Red "Line Number: $($_.InvocationInfo.ScriptLineNumber)"
Write-Host -ForegroundColor Red "Line: $($_.InvocationInfo.Line)"
} else {
Write-Host -ForegroundColor Red "No invocation information available."
}
# Extract and display the script stack trace if available
if ($_.ScriptStackTrace) {
Write-Host -ForegroundColor Red "Script Stack Trace:"
Write-Host -ForegroundColor Red $_.ScriptStackTrace
} else {
Write-Host -ForegroundColor Red "No script stack trace available."
}
}
}
} catch {
Write-Host -ForegroundColor Red "Detailed Error Report:"
Write-Host -ForegroundColor Red "Message: $($_.Exception.Message)"
# Attempt to provide a more detailed location of the error
if ($_.InvocationInfo -and $_.InvocationInfo.MyCommand) {
Write-Host -ForegroundColor Red "Command Name: $($_.InvocationInfo.MyCommand.Name)"
Write-Host -ForegroundColor Red "Script Name: $($_.InvocationInfo.ScriptName)"
Write-Host -ForegroundColor Red "Line Number: $($_.InvocationInfo.ScriptLineNumber)"
Write-Host -ForegroundColor Red "Line: $($_.InvocationInfo.Line)"
} else {
Write-Host -ForegroundColor Red "No invocation information available."
}
# Extract and display the script stack trace if available
if ($_.ScriptStackTrace) {
Write-Host -ForegroundColor Red "Script Stack Trace:"
Write-Host -ForegroundColor Red $_.ScriptStackTrace
} else {
Write-Host -ForegroundColor Red "No script stack trace available."
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "success=false"
exit 1
}
shell: pwsh