|
| 1 | +# replace_workflow-local.ps1 |
| 2 | + |
| 3 | +$ErrorActionPreference = "Stop" |
| 4 | + |
| 5 | +$TEMPLATE_REPO = "https://github.com/Geonovum/NL-ReSpec-template" |
| 6 | +$TEMP_DIR = "NL-ReSpec-template-temp" |
| 7 | +$LOCAL_DIR = Get-Location |
| 8 | + |
| 9 | +Write-Host "➡️ Clonen van NL-ReSpec-template..." |
| 10 | +git clone $TEMPLATE_REPO $TEMP_DIR |
| 11 | + |
| 12 | +if (-not (Test-Path $TEMP_DIR)) { |
| 13 | + Write-Error "❌ Het clonen van NL-ReSpec-template is mislukt." |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +Write-Host "🔄 Ophalen van remote branches..." |
| 18 | +git fetch --all |
| 19 | +# Haal alle remote branches op behalve HEAD/merge/etc. |
| 20 | +$BRANCHES = git branch -r | Where-Object {$_ -notmatch "->"} | ForEach-Object { $_.Trim() -replace "^origin/", "" } | Sort-Object -Unique |
| 21 | + |
| 22 | +$README_NOTICE = @" |
| 23 | +⚠️ Deze repository is automatisch bijgewerkt naar de nieuwste workflow. |
| 24 | +Voor vragen, neem contact op met [Linda van den Brink](mailto:l.vandenbrink@geonovum.nl) of [Wilko Quak](mailto:w.quak@geonovum.nl). |
| 25 | +
|
| 26 | +Als je een nieuwe publicatie wilt starten, lees dan eerst de instructies in de README van de NL-ReSpec-template: |
| 27 | +[https://github.com/Geonovum/NL-ReSpec-template](https://github.com/Geonovum/NL-ReSpec-template). |
| 28 | +"@ |
| 29 | + |
| 30 | +foreach ($BRANCH in $BRANCHES) { |
| 31 | + Write-Host "🔁 Verwerken van branch: $BRANCH" |
| 32 | + git checkout $BRANCH |
| 33 | + git pull origin $BRANCH |
| 34 | + |
| 35 | + Write-Host "🧹 Vervangen van .github/workflows..." |
| 36 | + Remove-Item -Recurse -Force ".github/workflows" -ErrorAction SilentlyContinue |
| 37 | + if (-not (Test-Path ".github")) { New-Item ".github" -ItemType Directory | Out-Null } |
| 38 | + Copy-Item -Recurse "$TEMP_DIR/.github/workflows" ".github/" |
| 39 | + |
| 40 | + # README.md aanpassen |
| 41 | + $readmeFile = "README.md" |
| 42 | + $noticeRegex = "automatisch bijgewerkt naar de nieuwste workflow" |
| 43 | + |
| 44 | + if (Test-Path $readmeFile) { |
| 45 | + $readmeContent = Get-Content $readmeFile -Raw |
| 46 | + if ($readmeContent -notmatch $noticeRegex) { |
| 47 | + $newContent = "$README_NOTICE`r`n`r`n$readmeContent" |
| 48 | + Set-Content $readmeFile $newContent |
| 49 | + Write-Host "📘 README.md aangepast." |
| 50 | + } else { |
| 51 | + Write-Host "📘 README.md bevat al de melding." |
| 52 | + } |
| 53 | + } else { |
| 54 | + Set-Content $readmeFile $README_NOTICE |
| 55 | + Write-Host "📘 README.md aangemaakt." |
| 56 | + } |
| 57 | + |
| 58 | + # Check for changes |
| 59 | + $status = git status --porcelain |
| 60 | + if ($status) { |
| 61 | + git add .github/workflows README.md |
| 62 | + git commit -m "Update workflows en README vanuit NL-ReSpec-template" |
| 63 | + git push origin $BRANCH |
| 64 | + Write-Host "✅ Branch '$BRANCH' bijgewerkt en gepusht." |
| 65 | + } else { |
| 66 | + Write-Host "ℹ️ Geen wijzigingen in branch '$BRANCH'." |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +# Opruimen |
| 71 | +Remove-Item -Recurse -Force $TEMP_DIR |
| 72 | +git checkout main |
| 73 | + |
| 74 | +Write-Host "Alle branches zijn verwerkt en bijgewerkt." |
0 commit comments