diff --git a/scripts/Setup-BranchRuleset.ps1 b/scripts/Setup-BranchRuleset.ps1 index 5110464..d062242 100644 --- a/scripts/Setup-BranchRuleset.ps1 +++ b/scripts/Setup-BranchRuleset.ps1 @@ -108,28 +108,33 @@ Write-Host "📌 Protected branch: $BranchName`n" -ForegroundColor Cyan # Check if ruleset already exists Write-Host "🔍 Checking for existing rulesets..." -ForegroundColor Yellow try { - $matchingRulesets = gh api ` + $rulesetOutput = gh api ` -H "Accept: application/vnd.github+json" ` -H "X-GitHub-Api-Version: 2022-11-28" ` "/repos/$Repository/rulesets" ` --paginate ` - --jq '.[] | select(.name == "Protect main branch")' | ConvertFrom-Json - - $existingRuleset = $matchingRulesets | Select-Object -First 1 - - if ($existingRuleset) { - Write-Host "✅ Ruleset 'Protect main branch' already exists!" -ForegroundColor Green - Write-Host " View it at: https://github.com/$Repository/settings/rules" -ForegroundColor Cyan - $response = Read-Host "`nDo you want to continue anyway? This may fail. (y/N)" - if ($response -ne 'y' -and $response -ne 'Y') { - Write-Host "Exiting." -ForegroundColor Yellow - exit 0 + --jq '.[] | select(.name == "Protect main branch")' 2>&1 + + if ($LASTEXITCODE -ne 0) { + Write-Warning "âš ī¸ Could not check for existing rulesets (API returned exit code $LASTEXITCODE). Continuing..." + } elseif ($rulesetOutput) { + $matchingRulesets = $rulesetOutput | ConvertFrom-Json + $existingRuleset = $matchingRulesets | Select-Object -First 1 + + if ($existingRuleset) { + Write-Host "✅ Ruleset 'Protect main branch' already exists!" -ForegroundColor Green + Write-Host " View it at: https://github.com/$Repository/settings/rules" -ForegroundColor Cyan + $response = Read-Host "`nDo you want to continue anyway? This may fail. (y/N)" + if ($response -ne 'y' -and $response -ne 'Y') { + Write-Host "Exiting." -ForegroundColor Yellow + exit 0 + } } } else { Write-Host "â„šī¸ Ruleset 'Protect main branch' does not exist yet." -ForegroundColor Gray } } catch { - Write-Warning "âš ī¸ Could not check for existing rulesets. Continuing..." + Write-Warning "âš ī¸ Could not check for existing rulesets: $($_.Exception.Message). Continuing..." } # Prompt for repository type @@ -195,7 +200,7 @@ $rulesetConfig = @{ @{ context = "Stage 2: Windows Tests (.NET 5.0-10.0, Framework 4.6.2-4.8.1)" }, @{ context = "Stage 3: macOS Tests (.NET 6.0-10.0)" }, @{ context = "Security Scan (DevSkim)" }, - @{ context = "Security Scan (CodeQL)" } + @{ context = "CodeQL Security Analysis / Security Scan (CodeQL) (csharp) (pull_request)" } ) } }, @@ -239,9 +244,6 @@ $rulesetConfig = @{ }, @{ type = "deletion" - }, - @{ - type = "update" } ) } @@ -251,7 +253,7 @@ $jsonConfig = $rulesetConfig | ConvertTo-Json -Depth 10 # Save to temporary file $tempFile = [System.IO.Path]::GetTempFileName() -$jsonConfig | Out-File -FilePath $tempFile -Encoding UTF8 +$jsonConfig | Out-File -FilePath $tempFile -Encoding utf8NoBOM try { Write-Host "🚀 Creating branch ruleset..." -ForegroundColor Cyan @@ -279,7 +281,7 @@ try { Write-Host " - Stage 2: Windows Tests (.NET 5.0-10.0, Framework 4.6.2-4.8.1)" -ForegroundColor DarkGray Write-Host " - Stage 3: macOS Tests (.NET 6.0-10.0)" -ForegroundColor DarkGray Write-Host " - Security Scan (DevSkim)" -ForegroundColor DarkGray - Write-Host " - Security Scan (CodeQL)" -ForegroundColor DarkGray + Write-Host " - CodeQL Security Analysis / Security Scan (CodeQL) (csharp) (pull_request)" -ForegroundColor DarkGray Write-Host " ✅ Branches must be up to date before merging" -ForegroundColor Gray Write-Host " ✅ Conversation resolution required before merging" -ForegroundColor Gray Write-Host " ✅ Stale reviews dismissed when new commits are pushed" -ForegroundColor Gray diff --git a/scripts/Setup-GitHubPages.ps1 b/scripts/Setup-GitHubPages.ps1 index 40b192e..334266d 100644 --- a/scripts/Setup-GitHubPages.ps1 +++ b/scripts/Setup-GitHubPages.ps1 @@ -351,7 +351,12 @@ if ($needsDocFxConfig) { $originalContent = $content foreach ($placeholder in $replacements.Keys) { - $content = $content -replace [regex]::Escape($placeholder), $replacements[$placeholder] + $pattern = [regex]::Escape($placeholder) + $content = [regex]::Replace( + $content, + $pattern, + [System.Text.RegularExpressions.MatchEvaluator]{ param($m) $replacements[$placeholder] } + ) } if ($content -ne $originalContent) { @@ -535,7 +540,7 @@ try { } | ConvertTo-Json $tempFile = [System.IO.Path]::GetTempFileName() - $pagesConfigUpdate | Out-File -FilePath $tempFile -Encoding UTF8 + $pagesConfigUpdate | Out-File -FilePath $tempFile -Encoding utf8NoBOM try { $updateOutput = gh api --method PUT "/repos/$Repository/pages" --input $tempFile 2>&1 diff --git a/scripts/format.ps1 b/scripts/format.ps1 index 5a65ff0..1c4dc1e 100644 --- a/scripts/format.ps1 +++ b/scripts/format.ps1 @@ -1,4 +1,4 @@ -īģŋ#!/usr/bin/env pwsh +#!/usr/bin/env pwsh <# .SYNOPSIS Formats all C# code in the repository using dotnet format.