|
| 1 | +# Define the packages and their corresponding XML entries |
| 2 | +$packages = @{ |
| 3 | + "Microsoft.Playwright" = "MicrosoftPlaywrightVersion" |
| 4 | + "Selenium.Support" = "SeleniumSupportVersion" |
| 5 | + "Selenium.WebDriver" = "SeleniumWebDriverVersion" |
| 6 | + } |
| 7 | + |
| 8 | + # Function to get the latest stable version from NuGet |
| 9 | +function Get-LatestNuGetVersion { |
| 10 | + param ( |
| 11 | + [string]$packageName |
| 12 | + ) |
| 13 | + $packageName = $packageName.ToLower(); |
| 14 | + $url = "https://api.nuget.org/v3-flatcontainer/$packageName/index.json" |
| 15 | + $response = Invoke-RestMethod -Uri $url |
| 16 | + $versions = $response.versions | Where-Object { $_ -notmatch "-" } | ForEach-Object { [System.Version]$_ } |
| 17 | + return ($versions | Sort-Object -Property Major, Minor, Build, Revision -Descending | Select-Object -First 1).ToString() |
| 18 | +} |
| 19 | + |
| 20 | +# Function to update the Versions.props file |
| 21 | +function Update-VersionsProps { |
| 22 | +param ( |
| 23 | + [string]$filePath, |
| 24 | + [hashtable]$versions |
| 25 | +) |
| 26 | +$content = Get-Content -Path $filePath |
| 27 | +foreach ($package in $versions.Keys) { |
| 28 | + $entryName = $packages[$package] |
| 29 | + $version = $versions[$package] |
| 30 | + $pattern = "(?<=<$entryName>)(.*?)(?=</$entryName>)" |
| 31 | + $replacement = $version |
| 32 | + $content = $content -replace $pattern, $replacement |
| 33 | +} |
| 34 | +Set-Content -Path $filePath -Value $content |
| 35 | +} |
| 36 | + |
| 37 | +# Function to check if the Docker image exists |
| 38 | +function Test-DockerImageExists { |
| 39 | +param ( |
| 40 | + [string]$imageName, |
| 41 | + [string]$version |
| 42 | +) |
| 43 | +$url = "https://mcr.microsoft.com/v2/$imageName/tags/list" |
| 44 | +$response = Invoke-RestMethod -Uri $url |
| 45 | +return $response.tags -contains $version |
| 46 | +} |
| 47 | + |
| 48 | +# Function to update the Dockerfile |
| 49 | +function Update-Dockerfile { |
| 50 | +param ( |
| 51 | + [string]$filePath, |
| 52 | + [string]$version |
| 53 | +) |
| 54 | +(Get-Content -Path $filePath) -replace 'FROM mcr.microsoft.com/playwright/dotnet:.* AS final', "FROM mcr.microsoft.com/playwright/dotnet:$version AS final" | Set-Content -Path $filePath |
| 55 | +} |
| 56 | + |
| 57 | +# Get the latest versions of the packages |
| 58 | +$versions = @{} |
| 59 | +foreach ($package in $packages.Keys) { |
| 60 | +$versions[$package] = Get-LatestNuGetVersion -packageName $package |
| 61 | +} |
| 62 | + |
| 63 | +# Print the package versions found |
| 64 | +foreach ($package in $versions.Keys) { |
| 65 | + Write-Host "$($package): $($versions[$package])" |
| 66 | +} |
| 67 | + |
| 68 | +# Update the Versions.props file |
| 69 | +Update-VersionsProps -filePath "eng/Versions.props" -versions $versions |
| 70 | + |
| 71 | +# Check if the Docker image exists |
| 72 | +$playwrightVersion = "v$($versions["Microsoft.Playwright"])-jammy-amd64" |
| 73 | +if (Test-DockerImageExists -imageName "playwright/dotnet" -version $playwrightVersion) { |
| 74 | +# Update the Dockerfile |
| 75 | +Update-Dockerfile -filePath "src/Components/benchmarkapps/Wasm.Performance/dockerfile" -version $playwrightVersion |
| 76 | +} else { |
| 77 | +Write-Error "Docker image for Playwright version $playwrightVersion not found." |
| 78 | +exit 1 |
| 79 | +} |
| 80 | + |
| 81 | +# Check if there are changes |
| 82 | +if (-not (git diff --cached --quiet)) { |
| 83 | + Write-Host "No changes to commit." |
| 84 | + exit 0 |
| 85 | +} |
| 86 | + |
| 87 | +# Create a new branch |
| 88 | +git checkout -b infrastructure/update-selenium-and-typescript-dependencies |
| 89 | + |
| 90 | +# Stage the changes |
| 91 | +git add eng/Versions.props src/Components/benchmarkapps/Wasm.Performance/dockerfile |
| 92 | + |
| 93 | +# Commit the changes |
| 94 | +$commitMessage = @" |
| 95 | +[Infrastructure] Update Selenium and Playwright dependencies $(Get-Date -Format "yyyy-MM-dd") |
| 96 | +* Updated Playwright version to $($versions["Microsoft.Playwright"]) |
| 97 | +* Updated Selenium version to $($versions["Selenium.Support"]) |
| 98 | +* Updated Selenium version to $($versions["Selenium.WebDriver"]) |
| 99 | +"@ |
| 100 | +git commit -m $commitMessage |
| 101 | + |
| 102 | +# Push the branch |
| 103 | +git push origin infrastructure/update-selenium-and-typescript-dependencies |
| 104 | + |
| 105 | +$prBody = $commitMessage + @" |
| 106 | +
|
| 107 | +Please see the [MirroringPackages.md](https://github.com/dotnet/arcade/blob/main/Documentation/MirroringPackages.md) document in the [dotnet/arcade](https://github.com/dotnet/arcade) repository for information on how to mirror these packages on the MS NuGet feed. |
| 108 | +"@ |
| 109 | + |
| 110 | +gh pr create --title "Update Selenium and Playwright dependencies $(Get-Date -Format "yyyy-MM-dd")" --body $prBody --base main --head infrastructure/update-selenium-and-typescript-dependencies |
0 commit comments