Skip to content

Commit bd66521

Browse files
committed
Added task to patch Lucene.Net.Expressions.csproj with a conditional expression so it can be overridden from the command line
1 parent 6e55d8d commit bd66521

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/Lucene-Net-Performance-Regression.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,46 @@ jobs:
126126
127127
Add-Content $env:GITHUB_OUTPUT "antlr4JarPath=$antlrJar"
128128
129+
- name: Patch Antlr4ToolPath condition in Lucene.Net.Expressions.csproj
130+
shell: pwsh
131+
run: |
132+
$projFile = "src/Lucene.Net.Expressions/Lucene.Net.Expressions.csproj"
133+
if (-not (Test-Path $projFile)) {
134+
Write-Warning "Project file not found: $projFile"
135+
exit 0
136+
}
137+
138+
[xml]$xml = Get-Content $projFile
139+
$nodes = $xml.SelectNodes("//Antlr4ToolPath")
140+
if ($nodes.Count -eq 0) {
141+
Write-Host "No Antlr4ToolPath element found. No change needed."
142+
exit 0
143+
}
144+
145+
$modified = $false
146+
foreach ($node in $nodes) {
147+
if (-not $node.Attributes["Condition"]) {
148+
$attr = $xml.CreateAttribute("Condition")
149+
$attr.Value = " '$(Antlr4ToolPath)' == '' "
150+
$node.Attributes.Append($attr) | Out-Null
151+
$modified = $true
152+
Write-Host "Added missing Condition attribute to Antlr4ToolPath."
153+
}
154+
}
155+
156+
if ($modified) {
157+
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
158+
$writer = [System.IO.StreamWriter]::new($projFile, $false, $utf8NoBom)
159+
try {
160+
$xml.Save($writer)
161+
} finally {
162+
$writer.Close()
163+
}
164+
Write-Host "Patched $projFile successfully."
165+
} else {
166+
Write-Host "Condition already present. No changes made."
167+
}
168+
129169
- name: Restore
130170
run: dotnet restore
131171

0 commit comments

Comments
 (0)