Skip to content

[CI] Handle failure to download Playwright dependencies #9493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions .github/workflows/cache-playwright-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
name: Cache Playwright Dependencies

on:
# Run daily at 2:00 AM UTC to refresh the cache
schedule:
- cron: '0 2 * * *'
# Allow manual triggering
workflow_dispatch:

jobs:
cache-ubuntu:
name: Cache Playwright Dependencies (Ubuntu)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get date for cache key
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Cache Playwright dependencies
id: playwright-cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/artifacts/bin/playwright-deps
key: playwright-deps-ubuntu-latest-${{ steps.date.outputs.date }}
restore-keys: |
playwright-deps-ubuntu-latest-

# Install with retries if cache miss
- name: Download and install Playwright dependencies with retries
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash
env:
CI: false
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/artifacts/bin/playwright-deps
NUGET_ENABLE_ENHANCED_HTTP_RETRY: true
NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT: 6
NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS: 1000
NUGET_RETRY_HTTP_429: true
run: |
retry_count=3
retry_delay=10
attempt=1
success=false

while [[ $attempt -le $retry_count && $success == false ]]; do
echo "Attempt $attempt of $retry_count to install Playwright browsers"

./build.sh -restore -build -projects tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj /p:InstallBrowsersForPlaywright=true && success=true

if [[ $success == false ]]; then
if [[ $attempt -lt $retry_count ]]; then
echo "Installation failed. Waiting $retry_delay seconds before retry..."
sleep $retry_delay
# Exponential backoff
retry_delay=$((retry_delay * 2))
else
echo "All attempts failed."
exit 1
fi
fi

((attempt++))
done

echo "Playwright browsers installed successfully!"

cache-windows:
name: Cache Playwright Dependencies (Windows)
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get date for cache key
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $env:GITHUB_OUTPUT
shell: bash

- name: Cache Playwright dependencies
id: playwright-cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}\artifacts\bin\playwright-deps
key: playwright-deps-windows-latest-${{ steps.date.outputs.date }}
restore-keys: |
playwright-deps-windows-latest-

# Install with retries if cache miss
- name: Download and install Playwright dependencies with retries
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: pwsh
env:
CI: false
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}\artifacts\bin\playwright-deps
NUGET_ENABLE_ENHANCED_HTTP_RETRY: true
NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT: 6
NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS: 1000
NUGET_RETRY_HTTP_429: true
run: |
$retryCount = 3
$retryDelay = 10
$attempt = 1
$success = $false

while ($attempt -le $retryCount -and -not $success) {
Write-Host "Attempt $attempt of $retryCount to install Playwright browsers"

try {
& .\build.cmd -restore -build -projects tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj /p:InstallBrowsersForPlaywright=true
if ($LASTEXITCODE -eq 0) {
$success = $true
}
}
catch {
Write-Host "Exception occurred: $_"
}

if (-not $success) {
if ($attempt -lt $retryCount) {
Write-Host "Installation failed. Waiting $retryDelay seconds before retry..."
Start-Sleep -Seconds $retryDelay
# Exponential backoff
$retryDelay *= 2
}
else {
Write-Host "All attempts failed."
exit 1
}
}

$attempt++
}

Write-Host "Playwright browsers installed successfully!"

cache-macos:
name: Cache Playwright Dependencies (macOS)
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get date for cache key
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Cache Playwright dependencies
id: playwright-cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/artifacts/bin/playwright-deps
key: playwright-deps-macos-latest-${{ steps.date.outputs.date }}
restore-keys: |
playwright-deps-macos-latest-

# Install with retries if cache miss
- name: Download and install Playwright dependencies with retries
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash
env:
CI: false
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/artifacts/bin/playwright-deps
NUGET_ENABLE_ENHANCED_HTTP_RETRY: true
NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT: 6
NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS: 1000
NUGET_RETRY_HTTP_429: true
run: |
retry_count=3
retry_delay=10
attempt=1
success=false

while [[ $attempt -le $retry_count && $success == false ]]; do
echo "Attempt $attempt of $retry_count to install Playwright browsers"

./build.sh -restore -build -projects tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj /p:InstallBrowsersForPlaywright=true && success=true

if [[ $success == false ]]; then
if [[ $attempt -lt $retry_count ]]; then
echo "Installation failed. Waiting $retry_delay seconds before retry..."
sleep $retry_delay
# Exponential backoff
retry_delay=$((retry_delay * 2))
else
echo "All attempts failed."
exit 1
fi
fi

((attempt++))
done

echo "Playwright browsers installed successfully!"
15 changes: 14 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -40,15 +40,27 @@ on:
required: false
type: string
default: "ubuntu-latest"
# Skip setting up Playwright cache (default is false)
skipPlaywrightCache:
required: false
type: boolean
default: false

jobs:
setup-playwright:
uses: ./.github/workflows/setup-playwright-cache.yml
if: ${{ !inputs.skipPlaywrightCache }}
with:
os: ${{ inputs.os }}

test:
needs: setup-playwright
runs-on: ${{ inputs.os }}
timeout-minutes: 60
name: ${{ inputs.testShortName }}
env:
DOTNET_ROOT: ${{ github.workspace }}/.dotnet
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/artifacts/bin/playwright-deps
steps:
- name: Validate arguments
shell: pwsh
@@ -152,7 +164,7 @@ jobs:
env:
CI: false
run: |
${{ env.BUILD_SCRIPT }} -restore -ci -build -projects ${{ env.TEST_PROJECT_PATH }}
${{ env.BUILD_SCRIPT }} -restore -ci -build -projects ${{ env.TEST_PROJECT_PATH }} /p:InstallBrowsersForPlaywright=false

- name: Build and archive test project
if: ${{ inputs.requiresNugets }}
@@ -161,6 +173,7 @@ jobs:
run: >
${{ env.BUILD_SCRIPT }} -restore -ci -build -projects ${{ env.TEST_PROJECT_PATH }}
/p:PrepareForHelix=true
/p:InstallBrowsersForPlaywright=false
/bl:${{ github.workspace }}/artifacts/log/Debug/PrepareForHelix.binlog

# Workaround for bug in Azure Functions Worker SDK. See https://github.com/Azure/azure-functions-dotnet-worker/issues/2969.
88 changes: 88 additions & 0 deletions .github/workflows/setup-playwright-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Setup Playwright Cache

on:
workflow_call:
inputs:
os:
required: true
type: string

jobs:
setup-playwright-cache:
runs-on: ${{ inputs.os }}
name: Setup Playwright Cache (${{ inputs.os }})
outputs:
playwright-cache-hit: ${{ steps.playwright-cache.outputs.cache-hit }}
steps:
- name: Setup vars (Linux/macOS)
if: ${{ inputs.os == 'ubuntu-latest' || inputs.os == 'macos-latest' }}
run: |
echo "DOTNET_SCRIPT=./dotnet.sh" >> $GITHUB_ENV
echo "BUILD_SCRIPT=./build.sh" >> $GITHUB_ENV
echo "PLAYWRIGHT_DEPS_PATH=${{ github.workspace }}/artifacts/bin/playwright-deps" >> $GITHUB_ENV

- name: Setup vars (Windows)
if: ${{ inputs.os == 'windows-latest' }}
run: |
echo "DOTNET_SCRIPT=.\dotnet.cmd" >> $env:GITHUB_ENV
echo "BUILD_SCRIPT=.\build.cmd" >> $env:GITHUB_ENV
echo "PLAYWRIGHT_DEPS_PATH=${{ github.workspace }}\artifacts\bin\playwright-deps" >> $env:GITHUB_ENV

- name: Get date for cache key
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Playwright dependencies
id: playwright-cache
uses: actions/cache@v4
with:
path: ${{ env.PLAYWRIGHT_DEPS_PATH }}
key: playwright-deps-${{ inputs.os }}-${{ steps.date.outputs.date }}
restore-keys: |
playwright-deps-${{ inputs.os }}-

# Set retry count and delay for Playwright installation
- name: Install Playwright dependencies with retries
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash
env:
CI: false
PLAYWRIGHT_BROWSERS_PATH: ${{ env.PLAYWRIGHT_DEPS_PATH }}
BUILD_SCRIPT: ${{ env.BUILD_SCRIPT }}
# Set Nuget retry variables to be more resilient to download issues
NUGET_ENABLE_ENHANCED_HTTP_RETRY: true
NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT: 6
NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS: 1000
NUGET_RETRY_HTTP_429: true
run: |
retry_count=3
retry_delay=10
attempt=1
success=false

while [[ $attempt -le $retry_count && $success == false ]]; do
echo "Attempt $attempt of $retry_count to install Playwright browsers"

if [[ "${{ inputs.os }}" == "windows-latest" ]]; then
$BUILD_SCRIPT -restore -build -projects tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj /p:InstallBrowsersForPlaywright=true && success=true
else
$BUILD_SCRIPT -restore -build -projects tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj /p:InstallBrowsersForPlaywright=true && success=true
fi

if [[ $success == false ]]; then
if [[ $attempt -lt $retry_count ]]; then
echo "Installation failed. Waiting $retry_delay seconds before retry..."
sleep $retry_delay
# Exponential backoff
retry_delay=$((retry_delay * 2))
else
echo "All attempts failed."
exit 1
fi
fi

((attempt++))
done

echo "Playwright browsers installed successfully!"
Loading
Oops, something went wrong.