|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | + |
| 3 | +# ------------------------------------------------------------ |
| 4 | +# CONFIG |
| 5 | +# ------------------------------------------------------------ |
| 6 | +$csprojUrl = "https://raw.githubusercontent.com/Accenture/Ocaramba/master/Ocaramba/Ocaramba.csproj" |
| 7 | +$repoApiTags = "https://api.github.com/repos/Accenture/Ocaramba/tags" |
| 8 | + |
| 9 | +# GitHub Actions output file |
| 10 | +$OutputFile = $env:GITHUB_OUTPUT |
| 11 | +if (-not $OutputFile) { |
| 12 | + Write-Host "GITHUB_OUTPUT not set. Running locally?" |
| 13 | + $OutputFile = "./local_output.txt" |
| 14 | +} |
| 15 | + |
| 16 | +# ------------------------------------------------------------ |
| 17 | +# FUNCTIONS |
| 18 | +# ------------------------------------------------------------ |
| 19 | + |
| 20 | +function Get-PackageVersionsFromCsproj { |
| 21 | + param([string]$Url) |
| 22 | + |
| 23 | + Write-Host "Downloading csproj from $Url ..." |
| 24 | + $xml = [xml](Invoke-WebRequest -Uri $Url -UseBasicParsing).Content |
| 25 | + |
| 26 | + $packages = @{} |
| 27 | + foreach ($pkg in $xml.Project.ItemGroup.PackageReference) { |
| 28 | + $packages[$pkg.Include] = $pkg.Version |
| 29 | + } |
| 30 | + return $packages |
| 31 | +} |
| 32 | + |
| 33 | +function Get-LatestOcarambaTag { |
| 34 | + param([string]$ApiUrl) |
| 35 | + |
| 36 | + Write-Host "Fetching latest Ocaramba tag..." |
| 37 | + $tags = Invoke-RestMethod -Uri $ApiUrl -Headers @{ "User-Agent" = "PowerShell" } |
| 38 | + return $tags[0].name |
| 39 | +} |
| 40 | + |
| 41 | +function Emit-Output { |
| 42 | + param( |
| 43 | + [string]$Name, |
| 44 | + [string]$Value |
| 45 | + ) |
| 46 | + Write-Host " → $Name=$Value" |
| 47 | + Add-Content -Path $OutputFile -Value "$Name=$Value" |
| 48 | +} |
| 49 | + |
| 50 | +# ------------------------------------------------------------ |
| 51 | +# EXECUTION |
| 52 | +# ------------------------------------------------------------ |
| 53 | + |
| 54 | +Write-Host "Extracting package versions..." |
| 55 | +$pkg = Get-PackageVersionsFromCsproj -Url $csprojUrl |
| 56 | + |
| 57 | +Write-Host "Getting latest Ocaramba version..." |
| 58 | +$ocarambaVersion = Get-LatestOcarambaTag -ApiUrl $repoApiTags |
| 59 | + |
| 60 | +# Mapping between csproj package names and GitHub Actions output names |
| 61 | +$map = @{ |
| 62 | + "Selenium.WebDriver" = "SeleniumWebDriverVersion" |
| 63 | + "Selenium.Support" = "SeleniumSupportVersion" |
| 64 | + "Selenium.WebDriver.ChromeDriver" = "SeleniumWebdriverChromeDriverVersion" |
| 65 | + "Selenium.WebDriver.GeckoDriver" = "SeleniumWebDriverGeckoDriverVersion" |
| 66 | + "Selenium.WebDriver.IEDriver" = "SeleniumWebDriverIEDriverVersion" |
| 67 | + "Selenium.WebDriver.MSEdgeDriver" = "SeleniumWebDriverMSEdgeDriverVersion" |
| 68 | + |
| 69 | + "NUnit" = "NUnitVersion" |
| 70 | + "NUnit3TestAdapter" = "NUnit3TestAdapterVersion" |
| 71 | + |
| 72 | + "Microsoft.NET.Test.Sdk" = "MicrosoftNetTestSdkVersion" |
| 73 | + "MSTest.TestAdapter" = "MSTestTestAdapterVersion" |
| 74 | + "MSTest.TestFramework" = "MSTestTestFrameworkVersion" |
| 75 | + |
| 76 | + "NPOI" = "NPOIVersion" |
| 77 | + "NLog" = "NLogVersion" |
| 78 | + |
| 79 | + "System.Text.Json" = "SystemTextJsonVersion" |
| 80 | + "System.Text.Encodings.Web" = "SystemTextEncodingsWebVersion" |
| 81 | +} |
| 82 | + |
| 83 | +Write-Host "`nEmitting GitHub Actions outputs..." |
| 84 | + |
| 85 | +foreach ($k in $map.Keys) { |
| 86 | + if ($pkg.ContainsKey($k)) { |
| 87 | + Emit-Output -Name $map[$k] -Value $pkg[$k] |
| 88 | + } else { |
| 89 | + Write-Warning "Package $k not found in csproj!" |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +Emit-Output -Name "OcarambaVersion" -Value $ocarambaVersion |
| 94 | + |
| 95 | +Write-Host "`n✅ DONE — GitHub Actions outputs generated." |
0 commit comments