Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions scripts/Setup-BranchRuleset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)" }
)
}
},
Expand Down Expand Up @@ -239,9 +244,6 @@ $rulesetConfig = @{
},
@{
type = "deletion"
},
@{
type = "update"
}
)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions scripts/Setup-GitHubPages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/format.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env pwsh
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Formats all C# code in the repository using dotnet format.
Expand Down
Loading