Skip to content

Commit 304b771

Browse files
authored
devops: run tests through a shared CI environment action (#43735)
1 parent c781173 commit 304b771

4 files changed

Lines changed: 46 additions & 20 deletions

File tree

‎.github/actions/ci-env/action.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'CI environment'
2+
description: >
3+
Prepares how the tests run on this runner. Exports CI_ENV_EXEC, a script a bash step runs the
4+
test command through: under xvfb on Linux, and at normal I/O priority on Windows, where the
5+
self-hosted runners start steps at Low and Firefox storage flushes then stall until the tests
6+
time out (https://github.com/microsoft/playwright/issues/43704). Exports CI_ENV_WINDOWS_NORMAL_IO,
7+
the PowerShell script a pwsh step dot-sources to do the same. The other Playwright repos use this
8+
action as microsoft/playwright/.github/actions/ci-env@main.
9+
runs:
10+
using: composite
11+
steps:
12+
- shell: bash
13+
env:
14+
ACTION_PATH: ${{ github.action_path }}
15+
run: |
16+
dir="${ACTION_PATH//\\//}"
17+
chmod +x "$dir/exec.sh"
18+
echo "CI_ENV_EXEC=$dir/exec.sh" >> "$GITHUB_ENV"
19+
echo "CI_ENV_WINDOWS_NORMAL_IO=$dir/windows-normal-io.ps1" >> "$GITHUB_ENV"

‎.github/actions/ci-env/exec.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Runs the command the way the tests need on this runner: under xvfb on Linux, at normal I/O
3+
# priority on Windows (windows-normal-io.ps1), as it is on macOS.
4+
set -e
5+
case "$(uname -s)" in
6+
Linux)
7+
exec xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- "$@";;
8+
MINGW*|MSYS*|CYGWIN*)
9+
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(dirname "$0")/windows-normal-io.ps1" -ProcessId "$(cat /proc/$$/winpid)"
10+
exec "$@";;
11+
*)
12+
exec "$@";;
13+
esac

.github/actions/run-test/windows-normal-io.ps1 renamed to .github/actions/ci-env/windows-normal-io.ps1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
param([switch]$RunBashCommand)
1+
# Raises a process to normal I/O priority; the processes it starts afterwards inherit it. The
2+
# self-hosted Windows runners start steps at Low, which the driver and the browsers inherit, and
3+
# Firefox storage flushes then stall until the tests time out (microsoft/playwright#43704).
4+
# Dot-source it at the start of a pwsh step to raise that step's shell, or run it with -ProcessId
5+
# from another shell, as exec.sh does for its own Git Bash process before it runs the command.
6+
param([int]$ProcessId = $PID)
27

38
$ErrorActionPreference = 'Stop'
49

@@ -17,31 +22,27 @@ public static class TestProcessIOPriority {
1722
}
1823
'@
1924

25+
$process = [System.Diagnostics.Process]::GetProcessById($ProcessId)
2026
$priority = 0
2127
$length = 0
2228
$status = [TestProcessIOPriority]::NtQueryInformationProcess(
23-
[IntPtr](-1), 33, [ref]$priority, 4, [ref]$length)
29+
$process.Handle, 33, [ref]$priority, 4, [ref]$length)
2430
if ($status -ne 0) {
2531
throw ('Reading I/O priority failed: NTSTATUS 0x{0:X8}' -f $status)
2632
}
2733
$inheritedPriority = $priority
2834
$priority = 2
2935
$status = [TestProcessIOPriority]::NtSetInformationProcess(
30-
[IntPtr](-1), 33, [ref]$priority, 4)
36+
$process.Handle, 33, [ref]$priority, 4)
3137
if ($status -ne 0) {
3238
throw ('Setting normal I/O priority failed: NTSTATUS 0x{0:X8}' -f $status)
3339
}
3440
$status = [TestProcessIOPriority]::NtQueryInformationProcess(
35-
[IntPtr](-1), 33, [ref]$priority, 4, [ref]$length)
41+
$process.Handle, 33, [ref]$priority, 4, [ref]$length)
3642
if ($status -ne 0) {
3743
throw ('Reading I/O priority failed: NTSTATUS 0x{0:X8}' -f $status)
3844
}
3945
if ($priority -ne 2) {
4046
throw "Expected normal I/O priority (2), got $priority"
4147
}
42-
Write-Host "Test launcher I/O priority: $inheritedPriority -> $priority (Normal)"
43-
44-
if ($RunBashCommand) {
45-
& "$env:ProgramFiles\Git\bin\bash.exe" --noprofile --norc -eo pipefail -c $env:PW_TEST_COMMAND
46-
exit $LASTEXITCODE
47-
}
48+
Write-Host "I/O priority of $($process.ProcessName) (${ProcessId}): $inheritedPriority -> $priority (Normal)"

‎.github/actions/run-test/action.yml‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,17 @@ runs:
5454
if: inputs.setup-command != ''
5555
run: ${{ inputs.setup-command }}
5656
shell: bash
57+
- uses: ./.github/actions/ci-env
5758
- name: Run tests
5859
if: inputs.shell == 'bash'
59-
run: |
60-
if [[ "$(uname)" == "Linux" ]]; then
61-
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- ${{ inputs.command }}
62-
elif [[ "$RUNNER_OS" == "Windows" ]]; then
63-
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .github/actions/run-test/windows-normal-io.ps1 -RunBashCommand
64-
else
65-
${{ inputs.command }}
66-
fi
60+
run: $CI_ENV_EXEC ${{ inputs.command }}
6761
shell: bash
6862
env:
6963
PW_TAG: "@${{ inputs.bot-name }}"
70-
PW_TEST_COMMAND: ${{ inputs.command }}
7164
- name: Run tests
7265
if: inputs.shell != 'bash'
7366
run: |
74-
${{ runner.os == 'Windows' && (inputs.shell == 'pwsh' || inputs.shell == 'powershell') && '. .\.github\actions\run-test\windows-normal-io.ps1' || '' }}
67+
${{ runner.os == 'Windows' && (inputs.shell == 'pwsh' || inputs.shell == 'powershell') && '. $env:CI_ENV_WINDOWS_NORMAL_IO' || '' }}
7568
${{ inputs.command }}
7669
shell: ${{ inputs.shell }}
7770
env:

0 commit comments

Comments
 (0)