|
| 1 | +# release.ps1 - Automated release script for doctest plugin |
| 2 | +# Creates and pushes version tags in format vYYYY.MM.DD[a-z] |
| 3 | + |
| 4 | +param( |
| 5 | + [switch]$DryRun, |
| 6 | + [switch]$Force |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +# Get today's date in version format |
| 12 | +$dateVersion = Get-Date -Format "yyyy.MM.dd" |
| 13 | +$baseTag = "v$dateVersion" |
| 14 | + |
| 15 | +# Get existing tags for today |
| 16 | +$existingTags = git tag -l "$baseTag*" 2>$null | Sort-Object |
| 17 | + |
| 18 | +if ($existingTags) { |
| 19 | + Write-Host "Existing tags for today:" -ForegroundColor Yellow |
| 20 | + $existingTags | ForEach-Object { Write-Host " $_" -ForegroundColor Gray } |
| 21 | + |
| 22 | + # Find the next suffix |
| 23 | + $lastTag = $existingTags | Select-Object -Last 1 |
| 24 | + |
| 25 | + if ($lastTag -eq $baseTag) { |
| 26 | + # First release was without suffix, next is 'a' |
| 27 | + $newTag = "${baseTag}a" |
| 28 | + } elseif ($lastTag -match "^v\d{4}\.\d{2}\.\d{2}([a-z])$") { |
| 29 | + # Increment the suffix letter |
| 30 | + $lastSuffix = $matches[1] |
| 31 | + $nextSuffix = [char]([int][char]$lastSuffix + 1) |
| 32 | + if ($nextSuffix -gt 'z') { |
| 33 | + Write-Error "Too many releases today! (exceeded 'z' suffix)" |
| 34 | + exit 1 |
| 35 | + } |
| 36 | + $newTag = "$baseTag$nextSuffix" |
| 37 | + } else { |
| 38 | + Write-Error "Unexpected tag format: $lastTag" |
| 39 | + exit 1 |
| 40 | + } |
| 41 | +} else { |
| 42 | + # No releases today yet - use base tag without suffix |
| 43 | + $newTag = $baseTag |
| 44 | +} |
| 45 | + |
| 46 | +Write-Host "" |
| 47 | +Write-Host "New release tag: " -NoNewline |
| 48 | +Write-Host $newTag -ForegroundColor Green |
| 49 | +Write-Host "" |
| 50 | + |
| 51 | +# Check for uncommitted changes |
| 52 | +$status = git status --porcelain |
| 53 | +if ($status) { |
| 54 | + Write-Host "Warning: You have uncommitted changes:" -ForegroundColor Yellow |
| 55 | + $status | ForEach-Object { Write-Host " $_" -ForegroundColor Gray } |
| 56 | + Write-Host "" |
| 57 | + |
| 58 | + if (-not $Force) { |
| 59 | + $response = Read-Host "Continue anyway? (y/N)" |
| 60 | + if ($response -ne 'y' -and $response -ne 'Y') { |
| 61 | + Write-Host "Aborted." -ForegroundColor Red |
| 62 | + exit 1 |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +# Check if we're on main branch |
| 68 | +$currentBranch = git branch --show-current |
| 69 | +if ($currentBranch -ne 'main') { |
| 70 | + Write-Host "Warning: You're on branch '$currentBranch', not 'main'" -ForegroundColor Yellow |
| 71 | + |
| 72 | + if (-not $Force) { |
| 73 | + $response = Read-Host "Continue anyway? (y/N)" |
| 74 | + if ($response -ne 'y' -and $response -ne 'Y') { |
| 75 | + Write-Host "Aborted." -ForegroundColor Red |
| 76 | + exit 1 |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +# Ensure we're up to date with remote |
| 82 | +Write-Host "Fetching latest from origin..." -ForegroundColor Cyan |
| 83 | +git fetch origin --tags |
| 84 | + |
| 85 | +# Check if local is behind remote |
| 86 | +$behind = git rev-list --count "HEAD..origin/$currentBranch" 2>$null |
| 87 | +if ($behind -gt 0) { |
| 88 | + Write-Host "Warning: Local branch is $behind commit(s) behind origin/$currentBranch" -ForegroundColor Yellow |
| 89 | + |
| 90 | + if (-not $Force) { |
| 91 | + $response = Read-Host "Pull changes first? (Y/n)" |
| 92 | + if ($response -ne 'n' -and $response -ne 'N') { |
| 93 | + git pull origin $currentBranch |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +if ($DryRun) { |
| 99 | + Write-Host "" |
| 100 | + Write-Host "[DRY RUN] Would execute:" -ForegroundColor Magenta |
| 101 | + Write-Host " git tag $newTag" -ForegroundColor Gray |
| 102 | + Write-Host " git push origin $newTag" -ForegroundColor Gray |
| 103 | + Write-Host "" |
| 104 | + Write-Host "Run without -DryRun to create the release." -ForegroundColor Cyan |
| 105 | + exit 0 |
| 106 | +} |
| 107 | + |
| 108 | +# Confirm release |
| 109 | +Write-Host "" |
| 110 | +$response = Read-Host "Create and push tag '$newTag'? (y/N)" |
| 111 | +if ($response -ne 'y' -and $response -ne 'Y') { |
| 112 | + Write-Host "Aborted." -ForegroundColor Red |
| 113 | + exit 1 |
| 114 | +} |
| 115 | + |
| 116 | +# Create and push the tag |
| 117 | +Write-Host "" |
| 118 | +Write-Host "Creating tag $newTag..." -ForegroundColor Cyan |
| 119 | +git tag $newTag |
| 120 | + |
| 121 | +Write-Host "Pushing tag to origin..." -ForegroundColor Cyan |
| 122 | +git push origin $newTag |
| 123 | + |
| 124 | +Write-Host "" |
| 125 | +Write-Host "Release $newTag created successfully!" -ForegroundColor Green |
| 126 | +Write-Host "" |
| 127 | +Write-Host "GitHub Actions will now:" -ForegroundColor Cyan |
| 128 | +Write-Host " 1. Build the TXZ package" -ForegroundColor Gray |
| 129 | +Write-Host " 2. Generate the PLG file" -ForegroundColor Gray |
| 130 | +Write-Host " 3. Create a GitHub Release" -ForegroundColor Gray |
| 131 | +Write-Host "" |
| 132 | +Write-Host "Monitor progress at:" -ForegroundColor Cyan |
| 133 | +Write-Host " https://github.com/mstrhakr/unraid-plugin-docs/actions" -ForegroundColor Blue |
| 134 | +Write-Host "" |
| 135 | +Write-Host "Release will be available at:" -ForegroundColor Cyan |
| 136 | +Write-Host " https://github.com/mstrhakr/unraid-plugin-docs/releases/tag/$newTag" -ForegroundColor Blue |
0 commit comments