|
| 1 | +name: ui-tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + msys2-runtime-artifact-name: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +env: |
| 11 | + AUTOHOTKEY_VERSION: 2.0.19 |
| 12 | + WT_VERSION: 1.22.11141.0 |
| 13 | + WIN32_OPENSSH_VERSION: 9.8.3.0p2-Preview |
| 14 | + |
| 15 | +jobs: |
| 16 | + ui-tests: |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + # Corresponds to Windows Server versions |
| 21 | + # See https://github.com/actions/runner-images?tab=readme-ov-file#available-images |
| 22 | + os: [windows-2022, windows-2025] |
| 23 | + |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + steps: |
| 26 | + - uses: actions/download-artifact@v5 |
| 27 | + with: |
| 28 | + name: ${{ inputs.msys2-runtime-artifact-name }} |
| 29 | + path: ${{ runner.temp }}/artifacts |
| 30 | + - name: replace MSYS2 runtime |
| 31 | + run: | |
| 32 | + $p = Get-ChildItem -Recurse "${env:RUNNER_TEMP}\artifacts" | where {$_.Name -eq "msys-2.0.dll"} | Select -ExpandProperty VersionInfo | Select -First 1 -ExpandProperty FileName |
| 33 | + cp $p "c:/Program Files/Git/usr/bin/msys-2.0.dll" |
| 34 | +
|
| 35 | + - uses: actions/cache/restore@v4 |
| 36 | + id: restore-wt |
| 37 | + with: |
| 38 | + key: wt-${{ env.WT_VERSION }} |
| 39 | + path: ${{ runner.temp }}/wt.zip |
| 40 | + - name: Download Windows Terminal |
| 41 | + if: steps.restore-wt.outputs.cache-hit != 'true' |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + curl -fLo "$RUNNER_TEMP/wt.zip" \ |
| 45 | + https://github.com/microsoft/terminal/releases/download/v$WT_VERSION/Microsoft.WindowsTerminal_${WT_VERSION}_x64.zip |
| 46 | + - uses: actions/cache/save@v4 |
| 47 | + if: steps.restore-wt.outputs.cache-hit != 'true' |
| 48 | + with: |
| 49 | + key: wt-${{ env.WT_VERSION }} |
| 50 | + path: ${{ runner.temp }}/wt.zip |
| 51 | + - name: Install Windows Terminal |
| 52 | + shell: bash |
| 53 | + working-directory: ${{ runner.temp }} |
| 54 | + run: | |
| 55 | + "$WINDIR/system32/tar.exe" -xf "$RUNNER_TEMP/wt.zip" && |
| 56 | + cygpath -aw terminal-$WT_VERSION >>$GITHUB_PATH |
| 57 | + - uses: actions/cache/restore@v4 |
| 58 | + id: restore-ahk |
| 59 | + with: |
| 60 | + key: ahk-${{ env.AUTOHOTKEY_VERSION }} |
| 61 | + path: ${{ runner.temp }}/ahk.zip |
| 62 | + - name: Download AutoHotKey2 |
| 63 | + if: steps.restore-ahk.outputs.cache-hit != 'true' |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + curl -L -o "$RUNNER_TEMP/ahk.zip" \ |
| 67 | + https://github.com/AutoHotkey/AutoHotkey/releases/download/v$AUTOHOTKEY_VERSION/AutoHotkey_$AUTOHOTKEY_VERSION.zip |
| 68 | + - uses: actions/cache/save@v4 |
| 69 | + if: steps.restore-ahk.outputs.cache-hit != 'true' |
| 70 | + with: |
| 71 | + key: ahk-${{ env.AUTOHOTKEY_VERSION }} |
| 72 | + path: ${{ runner.temp }}/ahk.zip |
| 73 | + - name: Install AutoHotKey2 |
| 74 | + shell: bash |
| 75 | + run: | |
| 76 | + mkdir -p "$RUNNER_TEMP/ahk" && |
| 77 | + "$WINDIR/system32/tar.exe" -C "$RUNNER_TEMP/ahk" -xf "$RUNNER_TEMP/ahk.zip" && |
| 78 | + cygpath -aw "$RUNNER_TEMP/ahk" >>$GITHUB_PATH |
| 79 | + - uses: actions/setup-node@v5 # the hook uses node for the background process |
| 80 | + - uses: actions/cache/restore@v4 |
| 81 | + id: restore-win32-openssh |
| 82 | + with: |
| 83 | + key: win32-openssh-${{ env.WIN32_OPENSSH_VERSION }} |
| 84 | + path: ${{ runner.temp }}/win32-openssh.zip |
| 85 | + - name: Download Win32-OpenSSH |
| 86 | + if: steps.restore-win32-openssh.outputs.cache-hit != 'true' |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + curl -fLo "$RUNNER_TEMP/win32-openssh.zip" \ |
| 90 | + https://github.com/PowerShell/Win32-OpenSSH/releases/download/v$WIN32_OPENSSH_VERSION/OpenSSH-Win64.zip |
| 91 | + - uses: actions/cache/save@v4 |
| 92 | + if: steps.restore-win32-openssh.outputs.cache-hit != 'true' |
| 93 | + with: |
| 94 | + key: win32-openssh-${{ env.WIN32_OPENSSH_VERSION }} |
| 95 | + path: ${{ runner.temp }}/win32-openssh.zip |
| 96 | + - name: Unpack Win32-OpenSSH |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + "$WINDIR/system32/tar.exe" -C "$RUNNER_TEMP" -xvf "$RUNNER_TEMP/win32-openssh.zip" && |
| 100 | + echo "OPENSSH_FOR_WINDOWS_DIRECTORY=$(cygpath -aw "$RUNNER_TEMP/OpenSSH-Win64")" >>$GITHUB_ENV |
| 101 | +
|
| 102 | + - uses: actions/checkout@v5 |
| 103 | + with: |
| 104 | + sparse-checkout: | |
| 105 | + ui-tests |
| 106 | + - name: Run UI tests |
| 107 | + id: ui-tests |
| 108 | + timeout-minutes: 10 |
| 109 | + working-directory: ui-tests |
| 110 | + run: | |
| 111 | + $exitCode = 0 |
| 112 | + & "${env:RUNNER_TEMP}\ahk\AutoHotKey64.exe" /ErrorStdOut /force background-hook.ahk "$PWD\bg-hook" 2>&1 | Out-Default |
| 113 | + if (!$?) { $exitCode = 1; echo "::error::Test failed!" } else { echo "::notice::Test log" } |
| 114 | + type bg-hook.log |
| 115 | + $env:LARGE_FILES_DIRECTORY = "${env:RUNNER_TEMP}\large" |
| 116 | + & "${env:RUNNER_TEMP}\ahk\AutoHotKey64.exe" /ErrorStdOut /force ctrl-c.ahk "$PWD\ctrl-c" 2>&1 | Out-Default |
| 117 | + if (!$?) { $exitCode = 1; echo "::error::Ctrl+C Test failed!" } else { echo "::notice::Ctrl+C Test log" } |
| 118 | + type ctrl-c.log |
| 119 | + exit $exitCode |
| 120 | + - name: Show logs |
| 121 | + if: always() |
| 122 | + working-directory: ui-tests |
| 123 | + run: | |
| 124 | + type bg-hook.log |
| 125 | + type ctrl-c.log |
| 126 | + - name: Take screenshot, if canceled |
| 127 | + id: take-screenshot |
| 128 | + if: cancelled() || failure() |
| 129 | + shell: powershell |
| 130 | + run: | |
| 131 | + Add-Type -TypeDefinition @" |
| 132 | + using System; |
| 133 | + using System.Runtime.InteropServices; |
| 134 | +
|
| 135 | + public class DpiHelper { |
| 136 | + [DllImport("user32.dll")] |
| 137 | + public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext); |
| 138 | +
|
| 139 | + [DllImport("Shcore.dll")] |
| 140 | + public static extern int GetDpiForMonitor(IntPtr hmonitor, int dpiType, out uint dpiX, out uint dpiY); |
| 141 | +
|
| 142 | + [DllImport("User32.dll")] |
| 143 | + public static extern IntPtr MonitorFromPoint(System.Drawing.Point pt, uint dwFlags); |
| 144 | +
|
| 145 | + [DllImport("user32.dll")] |
| 146 | + public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); |
| 147 | +
|
| 148 | + public static uint GetDPI() { |
| 149 | + // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4 |
| 150 | + SetProcessDpiAwarenessContext((IntPtr)(-4)); |
| 151 | +
|
| 152 | + uint dpiX, dpiY; |
| 153 | + IntPtr monitor = MonitorFromPoint(new System.Drawing.Point(0, 0), 2); // MONITOR_DEFAULTTONEAREST |
| 154 | + GetDpiForMonitor(monitor, 0, out dpiX, out dpiY); // MDT_EFFECTIVE_DPI |
| 155 | + return (dpiX + dpiY) / 2; |
| 156 | + } |
| 157 | + } |
| 158 | + "@ -ReferencedAssemblies "System.Drawing.dll" |
| 159 | +
|
| 160 | + # First, minimize the Console window in which this script is running |
| 161 | + $hwnd = (Get-Process -Id $PID).MainWindowHandle |
| 162 | + $SW_MINIMIZE = 6 |
| 163 | +
|
| 164 | + [DpiHelper]::ShowWindow($hwnd, $SW_MINIMIZE) |
| 165 | +
|
| 166 | + # Now, get the DPI |
| 167 | + $dpi = [DpiHelper]::GetDPI() |
| 168 | +
|
| 169 | + # This function takes a screenshot and saves it as a PNG file |
| 170 | + [Reflection.Assembly]::LoadWithPartialName("System.Drawing") |
| 171 | + function screenshot([Drawing.Rectangle]$bounds, $path) { |
| 172 | + $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height |
| 173 | + $graphics = [Drawing.Graphics]::FromImage($bmp) |
| 174 | + $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size) |
| 175 | + $bmp.Save($path) |
| 176 | + $graphics.Dispose() |
| 177 | + $bmp.Dispose() |
| 178 | + } |
| 179 | + Add-Type -AssemblyName System.Windows.Forms |
| 180 | + $screen = [System.Windows.Forms.Screen]::PrimaryScreen |
| 181 | + $bounds = [Drawing.Rectangle]::FromLTRB(0, 0, $screen.Bounds.Width * $dpi / 96, $screen.Bounds.Height * $dpi / 96) |
| 182 | + screenshot $bounds "ui-tests/screenshot.png" |
| 183 | + - name: Upload test results |
| 184 | + if: always() |
| 185 | + uses: actions/upload-artifact@v4 |
| 186 | + with: |
| 187 | + name: ui-tests-${{ matrix.os }} |
| 188 | + path: ui-tests |
0 commit comments