-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.ps1
More file actions
200 lines (175 loc) · 6.19 KB
/
build.ps1
File metadata and controls
200 lines (175 loc) · 6.19 KB
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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Build and run workflow for Patchright .NET
.DESCRIPTION
This script clones playwright-dotnet, patches it with Patchright, and builds the project.
.PARAMETER Cleanup
Remove existing playwright-dotnet directory before starting
.PARAMETER DriverVersion
Specific driver version to use
.PARAMETER PackageVersion
Target package version to build (overrides Version.props)
.PARAMETER IsolatedContextDefault
The default isolated context behavior to use when running the patch.
.EXAMPLE
.\build.ps1
.\build.ps1 -Cleanup
.\build.ps1 -Cleanup -DriverVersion 1.57.0 -PackageVersion 1.57.0
.\build.ps1 -Cleanup -DriverVersion 1.57.0 -PackageVersion 1.57.0 -IsolatedContextDefault $false
#>
param(
[switch]$Cleanup,
[string]$DriverVersion,
[string]$PackageVersion,
[bool]$IsolatedContextDefault = $true # Default to true, can be overridden for unit tests
)
$ErrorActionPreference = "Stop"
# Check prerequisites
function Test-Prerequisites {
Write-Host "Checking prerequisites..." -ForegroundColor Cyan
# Check git
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Error "git is not installed or not in PATH. Please install git first."
exit 1
}
# Check dotnet
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
Write-Error ".NET SDK is not installed or not in PATH. Please install .NET 10 SDK first."
exit 1
}
# Check .NET version
$dotnetVersion = dotnet --version
$majorVersion = [int]($dotnetVersion -split '\.')[0]
if ($majorVersion -lt 10) {
Write-Error ".NET SDK version $dotnetVersion found, but .NET 10 SDK or higher is required."
exit 1
}
Write-Host "[OK] git: $(git --version)" -ForegroundColor Green
Write-Host "[OK] .NET SDK: $dotnetVersion" -ForegroundColor Green
}
# Get latest release version from GitHub
function Get-LatestPlaywrightVersion {
Write-Host "`nFetching latest Playwright .NET release version..." -ForegroundColor Cyan
try {
$apiUrl = "https://api.github.com/repos/microsoft/playwright-dotnet/releases/latest"
$response = Invoke-RestMethod -Uri $apiUrl -Headers @{ "User-Agent" = "Patchright-Build-Script" }
$tagName = $response.tag_name
# Remove 'v' prefix if present and strip build number (keep only major.minor)
$version = $tagName -replace '^v', ''
$versionParts = $version -split '\.'
$majorMinor = "$($versionParts[0]).$($versionParts[1])"
Write-Host "[OK] Latest version: $tagName (using release-$majorMinor)" -ForegroundColor Green
return $majorMinor
}
catch {
Write-Error "Failed to fetch latest release version from GitHub: $_"
exit 1
}
}
# Main workflow
Write-Host "`nPatchright .NET Build Script" -ForegroundColor Yellow
Write-Host "============================`n" -ForegroundColor Yellow
Test-Prerequisites
$version = Get-LatestPlaywrightVersion
$playwrightDir = "playwright-dotnet"
# Cleanup if requested
if ($Cleanup -and (Test-Path $playwrightDir)) {
Write-Host "`nCleaning up existing playwright-dotnet directory..." -ForegroundColor Cyan
Remove-Item -Path $playwrightDir -Recurse -Force
Write-Host "[OK] Cleanup complete" -ForegroundColor Green
}
# Clone repository
if (-not (Test-Path $playwrightDir)) {
Write-Host "`nCloning playwright-dotnet repository..." -ForegroundColor Cyan
git clone https://github.com/microsoft/playwright-dotnet.git
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to clone repository"
exit 1
}
Write-Host "[OK] Repository cloned" -ForegroundColor Green
}
else {
Write-Host "`nPlaywright-dotnet directory already exists, skipping clone" -ForegroundColor Yellow
}
# Checkout release branch
Write-Host "`nChecking out release-$version..." -ForegroundColor Cyan
Push-Location $playwrightDir
try {
git checkout "release-$version"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to checkout release-$version"
exit 1
}
Write-Host "[OK] Checked out release-$version" -ForegroundColor Green
}
finally {
Pop-Location
}
# Run Patchright
Write-Host "`nRunning Patchright..." -ForegroundColor Cyan
dotnet run .\Patchright.cs $IsolatedContextDefault $DriverVersion $PackageVersion
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to run Patchright"
exit 1
}
Write-Host "[OK] Patchright executed successfully" -ForegroundColor Green
# Download drivers
Write-Host "`nDownloading Playwright drivers..." -ForegroundColor Cyan
Push-Location $playwrightDir
try {
dotnet run --project ./src/tools/Playwright.Tooling/Playwright.Tooling.csproj -- download-drivers --basepath .
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to download drivers"
exit 1
}
Write-Host "[OK] Drivers downloaded" -ForegroundColor Green
}
finally {
Pop-Location
}
# Build solution
Write-Host "`nBuilding Playwright solution..." -ForegroundColor Cyan
Push-Location $playwrightDir
try {
dotnet build --configuration Release ./src/Playwright.sln
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build solution"
exit 1
}
Write-Host "[OK] Solution built successfully" -ForegroundColor Green
}
finally {
Pop-Location
}
# Create patch file
Write-Host "`nCreating patch file..." -ForegroundColor Cyan
Push-Location $playwrightDir
try {
git diff -- . ":(exclude)README.md" > ../patchright.patch
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create patch file"
exit 1
}
Write-Host "[OK] Patch file created successfully" -ForegroundColor Green
}
finally {
Pop-Location
}
# Pack project
Write-Host "`nPacking Playwright project..." -ForegroundColor Cyan
Push-Location $playwrightDir
try {
dotnet pack --no-build --configuration Release --output ../nuget ./src/Playwright/Playwright.csproj
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to pack project"
exit 1
}
Write-Host "[OK] Project packed successfully" -ForegroundColor Green
}
finally {
Pop-Location
}
Write-Host "`n============================`n" -ForegroundColor Yellow
Write-Host "Build completed successfully!" -ForegroundColor Green
Write-Host ""