Skip to content

Commit 0dd67d9

Browse files
Update release-images.yml
Signed-off-by: Igor Mundstein <3512138+IgorMundstein@users.noreply.github.com>
1 parent b79800d commit 0dd67d9

1 file changed

Lines changed: 61 additions & 20 deletions

File tree

.github/workflows/release-images.yml

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
name: Update Release Images
1+
name: Update doc images
22

33
on:
4-
workflow_dispatch:
54
release:
65
types: [published]
6+
workflow_dispatch:
77

88
permissions:
99
contents: write
1010
pull-requests: write
11+
packages: read
1112

1213
concurrency:
1314
group: update-release-images
@@ -16,7 +17,7 @@ concurrency:
1617
jobs:
1718
update-main-window-screenshot:
1819
name: Update Main Window Screenshot
19-
runs-on: ubuntu-latest
20+
runs-on: windows-latest
2021

2122
steps:
2223
- name: checkout-repository
@@ -26,42 +27,82 @@ jobs:
2627
ref: main
2728
token: ${{ secrets.PAT_TOKEN }}
2829

29-
- name: download-screenshot-artifact
30-
id: download-screenshot
31-
uses: actions/download-artifact@v4
32-
with:
33-
name: release-window-screenshot
34-
path: ./ui-window
35-
continue-on-error: true
30+
- name: Download signed EXE from release
31+
id: download-exe
32+
env:
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
TAG: ${{ github.event.release.tag_name }}
35+
shell: pwsh
36+
run: |
37+
gh release download $env:TAG --pattern "WinMemoryCleaner.exe"
38+
if (-not (Test-Path ".\WinMemoryCleaner.exe")) {
39+
Write-Host "::error::Failed to download WinMemoryCleaner.exe from release $env:TAG"
40+
exit 1
41+
}
42+
Write-Host "Downloaded signed WinMemoryCleaner.exe"
43+
44+
- name: Capture window screenshot from SIGNED exe
45+
id: capture_screenshot
46+
shell: pwsh
47+
run: |
48+
$ErrorActionPreference = "Stop"
49+
$appPath = ".\WinMemoryCleaner.exe"
50+
$windowScreenshotPath = "$pwd\main-window-raw.png"
51+
$proc = Start-Process -FilePath $appPath -PassThru
52+
$maxWaitMs = 15000; $elapsed = 0
53+
while ($proc.MainWindowHandle -eq 0 -and $elapsed -lt $maxWaitMs) {
54+
Start-Sleep -Milliseconds 200; $proc.Refresh(); $elapsed += 200
55+
}
56+
if ($proc.MainWindowHandle -eq 0) {
57+
Write-Host "::error::Main window not found for signed EXE."
58+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
59+
exit 1
60+
}
61+
Add-Type -AssemblyName System.Drawing
62+
$sig = 'using System; using System.Runtime.InteropServices; public static class Win32 { [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); }'
63+
Add-Type -TypeDefinition $sig -Language CSharp
64+
[void][Win32]::SetForegroundWindow([IntPtr]$proc.MainWindowHandle)
65+
$rect = New-Object Win32+RECT
66+
if (-not [Win32]::GetWindowRect([IntPtr]$proc.MainWindowHandle, [ref]$rect)) {
67+
Write-Host "::error::GetWindowRect failed."
68+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue; exit 1
69+
}
70+
$width = $rect.Right - $rect.Left; $height = $rect.Bottom - $rect.Top
71+
if ($width -le 0 -or $height -le 0) {
72+
Write-Host "::error::Invalid window size: $($width)x$($height)"
73+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue; exit 1
74+
}
75+
$wbmp = New-Object System.Drawing.Bitmap $width, $height
76+
$wgfx = [System.Drawing.Graphics]::FromImage($wbmp)
77+
$wgfx.CopyFromScreen($rect.Left, $rect.Top, 0, 0, (New-Object System.Drawing.Size($width, $height)))
78+
$wbmp.Save($windowScreenshotPath, [System.Drawing.Imaging.ImageFormat]::Png)
79+
$wgfx.Dispose(); $wbmp.Dispose()
80+
Stop-Process -Id $proc.Id -Force
3681
3782
- name: check-screenshot-exists
3883
id: check-screenshot
3984
shell: bash
4085
run: |
41-
if [ -f "./ui-window/main-window-raw.png" ]; then
86+
if [ -f "./main-window-raw.png" ]; then
4287
echo "screenshot_exists=true" >> $GITHUB_OUTPUT
4388
else
89+
echo "::error::Screenshot was not created."
4490
echo "screenshot_exists=false" >> $GITHUB_OUTPUT
91+
exit 1
4592
fi
4693
4794
- name: install-imagemagick
4895
if: steps.check-screenshot.outputs.screenshot_exists == 'true'
49-
run: |
50-
set -euo pipefail
51-
sudo apt-get update
52-
sudo apt-get install -y imagemagick
53-
if ! command -v magick; then
54-
echo "::error::ImageMagick (magick) was not installed successfully."
55-
exit 1
56-
fi
96+
run: choco install imagemagick
97+
shell: pwsh
5798

5899
- name: process-screenshot-image
59100
if: steps.check-screenshot.outputs.screenshot_exists == 'true'
60101
shell: bash
61102
run: |
62103
set -euo pipefail
63104
mkdir -p docs/assets/images
64-
FILE="./ui-window/main-window-raw.png"
105+
FILE="./main-window-raw.png"
65106
if ! identify -format "%w %h" "$FILE" > /dev/null; then
66107
echo "::error::Failed to read image $FILE with ImageMagick."
67108
exit 1

0 commit comments

Comments
 (0)