@@ -2,68 +2,81 @@ $ErrorActionPreference = "Stop"
22
33$TEMPLATE_REPO = " https://github.com/Geonovum/NL-ReSpec-template"
44$TEMP_DIR = " NL-ReSpec-template-temp"
5- $LOCAL_DIR = Get-Location
5+
6+ if (Test-Path $TEMP_DIR ) {
7+ Write-Host " Opruimen oude template directory..."
8+ Remove-Item - Recurse - Force $TEMP_DIR
9+ }
610
711Write-Host " Clonen van NL-ReSpec-template..."
812git clone $TEMPLATE_REPO $TEMP_DIR
913
1014if (-not (Test-Path $TEMP_DIR )) {
11- Write-Error " Het clonen van NL-ReSpec-template is mislukt."
12- exit 1
15+ throw " Het clonen van NL-ReSpec-template is mislukt."
1316}
1417
1518Write-Host " Ophalen van remote branches..."
16- git fetch -- all
17- # Haal alle remote branches op behalve HEAD/merge/etc.
18- $BRANCHES = git branch - r | Where-Object {$_ -notmatch " ->" } | ForEach-Object { $_.Trim () -replace " ^origin/" , " " } | Sort-Object - Unique
19+ git fetch -- all | Out-Null
20+ $branches = git branch - r | Where-Object { $_ -notmatch " ->" } | ForEach-Object { ($_ -replace " ^origin/" , " " ).Trim() } | Sort-Object - Unique
21+
22+ foreach ($branch in $branches ) {
23+ Write-Host " "
24+ Write-Host " Verwerken van branch: $branch "
25+ if (-not (git branch -- list $branch )) {
26+ git checkout - b $branch origin/ $branch
27+ } else {
28+ git checkout $branch
29+ git pull origin $branch | Out-Null
30+ }
1931
20- $README_NOTICE = @"
32+ Write-Host " Vervangen van .github/workflows..."
33+ Remove-Item - Recurse - Force " .github/workflows" - ErrorAction SilentlyContinue
34+ if (-not (Test-Path " .github" )) { New-Item " .github" - ItemType Directory | Out-Null }
35+ Copy-Item - Recurse " $TEMP_DIR /.github/workflows" " .github/"
36+
37+ $readmePath = " README.md"
38+ $noticeText = @"
2139Deze repository is automatisch bijgewerkt naar de nieuwste workflow.
2240Voor vragen, neem contact op met [Linda van den Brink](mailto:l.vandenbrink@geonovum.nl) of [Wilko Quak](mailto:w.quak@geonovum.nl).
2341
2442Als je een nieuwe publicatie wilt starten, lees dan eerst de instructies in de README van de NL-ReSpec-template:
2543[https://github.com/Geonovum/NL-ReSpec-template](https://github.com/Geonovum/NL-ReSpec-template).
2644"@
2745
28- foreach ($BRANCH in $BRANCHES ) {
29- Write-Host " 🔁 Verwerken van branch: $BRANCH "
30- git checkout $BRANCH
31- git pull origin $BRANCH
32-
33- Write-Host " Vervangen van .github/workflows..."
34- Remove-Item - Recurse - Force " .github/workflows" - ErrorAction SilentlyContinue
35- if (-not (Test-Path " .github" )) { New-Item " .github" - ItemType Directory | Out-Null }
36- Copy-Item - Recurse " $TEMP_DIR /.github/workflows" " .github/"
37-
38- $readmeFile = " README.md"
39- $noticeRegex = " automatisch bijgewerkt naar de nieuwste workflow"
46+ $readmeNeedsUpdate = $true
47+ if (Test-Path $readmePath ) {
48+ $content = Get-Content $readmePath - Raw
49+ if ($content -match " automatisch bijgewerkt naar de nieuwste workflow" ) {
50+ $readmeNeedsUpdate = $false
51+ Write-Host " README.md bevat al de melding."
52+ }
53+ }
4054
41- if (Test-Path $readmeFile ) {
42- $readmeContent = Get-Content $readmeFile - Raw
43- if ($readmeContent -notmatch $noticeRegex ) {
44- $newContent = " $README_NOTICE `r`n`r`n $readmeContent "
45- Set-Content $readmeFile $newContent
46- Write-Host " README.md aangepast."
55+ if ($readmeNeedsUpdate ) {
56+ if (-not (Test-Path $readmePath )) {
57+ Write-Host " README.md aangemaakt."
58+ Set-Content $readmePath $noticeText
4759 } else {
48- Write-Host " README.md bevat al de melding."
60+ Write-Host " README.md aangepast."
61+ $existing = Get-Content $readmePath - Raw
62+ Set-Content $readmePath " $noticeText `r`n`r`n $existing "
4963 }
50- } else {
51- Set-Content $readmeFile $README_NOTICE
52- Write-Host " README.md aangemaakt."
5364 }
54-
55- $status = git status -- porcelain
56- if ($status ) {
65+
66+ $changes = git status -- porcelain
67+ if ($changes ) {
5768 git add .github/ workflows README.md
5869 git commit - m " Update workflows en README vanuit NL-ReSpec-template"
59- git push origin $BRANCH
60- Write-Host " Branch '$BRANCH ' bijgewerkt en gepusht."
70+ git push origin $branch
71+ Write-Host " Branch '$branch ' bijgewerkt en gepusht."
6172 } else {
62- Write-Host " Geen wijzigingen in branch '$BRANCH '."
73+ Write-Host " ⏭️ Geen wijzigingen in branch '$branch '."
6374 }
6475}
6576
77+ Write-Host " Opruimen tijdelijke map..."
6678Remove-Item - Recurse - Force $TEMP_DIR
67- git checkout main
6879
80+ git checkout main | Out-Null
81+ Write-Host " "
6982Write-Host " Alle branches zijn verwerkt en bijgewerkt."
0 commit comments