Skip to content

Commit 5c32a41

Browse files
committed
get versions
1 parent 9af2ecd commit 5c32a41

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

.github/workflows/dotnet-desktop.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,68 @@ jobs:
5353
if: startsWith(github.ref, 'refs/tags/')
5454
- shell: powershell
5555
run: '((Get-Content -path ./Ocaramba.Templates.VSIX/source.extension.vsixmanifest -Raw) -replace ''Version="\d\.\d.\d" Language'',''Version="${{ env.templateVersion }}" Language'') | Set-Content -Path ./Ocaramba.Templates.VSIX/source.extension.vsixmanifest'
56+
- name: Run version extractor
57+
id: versions
58+
shell: pwsh
59+
run: |
60+
pwsh ./scripts/get-versions.ps1
61+
62+
- name: Update workflow variables
63+
shell: pwsh
64+
run: |
65+
$file = ".github/workflows/dotnet-desktop.yml"
66+
67+
$vars = @{
68+
SeleniumWebDriverVersion = "${{ steps.versions.outputs.SeleniumWebDriverVersion }}"
69+
SeleniumSupportVersion = "${{ steps.versions.outputs.SeleniumSupportVersion }}"
70+
SeleniumWebdriverChromeDriverVersion = "${{ steps.versions.outputs.SeleniumWebdriverChromeDriverVersion }}"
71+
SeleniumWebDriverGeckoDriverVersion = "${{ steps.versions.outputs.SeleniumWebDriverGeckoDriverVersion }}"
72+
SeleniumWebDriverIEDriverVersion = "${{ steps.versions.outputs.SeleniumWebDriverIEDriverVersion }}"
73+
SeleniumWebDriverMSEdgeDriverVersion = "${{ steps.versions.outputs.SeleniumWebDriverMSEdgeDriverVersion }}"
74+
NUnitVersion = "${{ steps.versions.outputs.NUnitVersion }}"
75+
NUnit3TestAdapterVersion = "${{ steps.versions.outputs.NUnit3TestAdapterVersion }}"
76+
MicrosoftNetTestSdkVersion = "${{ steps.versions.outputs.MicrosoftNetTestSdkVersion }}"
77+
MSTestTestAdapterVersion = "${{ steps.versions.outputs.MSTestTestAdapterVersion }}"
78+
MSTestTestFrameworkVersion = "${{ steps.versions.outputs.MSTestTestFrameworkVersion }}"
79+
NPOIVersion = "${{ steps.versions.outputs.NPOIVersion }}"
80+
NLogVersion = "${{ steps.versions.outputs.NLogVersion }}"
81+
SystemTextJsonVersion = "${{ steps.versions.outputs.SystemTextJsonVersion }}"
82+
SystemTextEncodingsWebVersion = "${{ steps.versions.outputs.SystemTextEncodingsWebVersion }}"
83+
OcarambaVersion = "${{ steps.versions.outputs.OcarambaVersion }}"
84+
}
85+
86+
$content = Get-Content $file
87+
88+
foreach ($k in $vars.Keys) {
89+
$pattern = "^\s*$k:"
90+
$value = $vars[$k]
91+
$content = $content -replace $pattern, "$k: $value"
92+
}
93+
94+
$content | Set-Content $file
95+
96+
- name: Commit changes
97+
run: |
98+
git config user.name "github-actions"
99+
git config user.email "github-actions@github.com"
100+
101+
git add .
102+
if git diff --cached --quiet; then
103+
echo "No changes detected."
104+
exit 0
105+
fi
106+
107+
git commit -m "Auto-sync Ocaramba versions"
108+
git push
109+
110+
- name: Create Pull Request
111+
uses: peter-evans/create-pull-request@v6
112+
with:
113+
token: ${{ secrets.GITHUB_TOKEN }}
114+
commit-message: "Auto-sync Ocaramba versions"
115+
title: "Auto-sync Ocaramba versions"
116+
body: "This PR updates all dependency versions from Ocaramba.csproj and latest Ocaramba tag."
117+
branch: auto/sync-ocaramba-versions
56118
- shell: powershell
57119
run: ./setPackagesVersions.ps1
58120
- name: Setup nuget

scripts/get-versions.ps1

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)