-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-Release.ps1
More file actions
163 lines (143 loc) Β· 5.93 KB
/
New-Release.ps1
File metadata and controls
163 lines (143 loc) Β· 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Release Helper Script for WordleSharp
# This script helps prepare and validate a manual release
# NOTE: Automatic releases happen when you merge to main - this is for manual releases only
param(
[Parameter(Mandatory)]
[string]$Version,
[string]$ReleaseNotes = "",
[switch]$DryRun
)
Write-Host "π WordleSharp Release Helper" -ForegroundColor Cyan
Write-Host "=============================" -ForegroundColor Cyan
# Validate version format
if ($Version -notmatch '^\d+\.\d+\.\d+$') {
Write-Error "Version must be in format X.Y.Z (e.g., 1.0.0)"
exit 1
}
$tagName = "v$Version"
function Write-Step {
param([string]$Message)
Write-Host "βΆοΈ $Message" -ForegroundColor Green
}
function Write-Success {
param([string]$Message)
Write-Host "β
$Message" -ForegroundColor Green
}
try {
# Check if we're in a git repository
if (-not (Test-Path ".git")) {
throw "This must be run from a git repository"
}
# Check if working directory is clean
Write-Step "Checking git status..."
$gitStatus = git status --porcelain
if ($gitStatus -and -not $DryRun) {
Write-Warning "Working directory has uncommitted changes:"
$gitStatus | ForEach-Object { Write-Host " $_" -ForegroundColor Yellow }
$response = Read-Host "Continue anyway? (y/N)"
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Host "Release cancelled by user"
exit 0
}
}
# Check if tag already exists
Write-Step "Checking if tag $tagName already exists..."
$existingTag = git tag -l $tagName
if ($existingTag) {
throw "Tag $tagName already exists"
}
Write-Success "Tag $tagName is available"
# Validate current module version
Write-Step "Reading current module manifest..."
$manifestPath = "WordleSharp.psd1"
if (-not (Test-Path $manifestPath)) {
throw "Module manifest not found: $manifestPath"
}
$manifestContent = Get-Content $manifestPath -Raw
if ($manifestContent -match "ModuleVersion\s*=\s*'([^']*)'") {
$currentVersion = $matches[1]
Write-Host "Current module version: $currentVersion" -ForegroundColor Cyan
if ($currentVersion -eq $Version) {
Write-Warning "Module is already at version $Version"
} else {
Write-Host "Module will be updated from $currentVersion to $Version" -ForegroundColor Cyan
}
} else {
throw "Could not parse ModuleVersion from manifest"
}
# Run local build to ensure everything works
Write-Step "Running local build to validate..."
if (Test-Path "Build-Local.ps1") {
& ./Build-Local.ps1 -Configuration Release
if ($LASTEXITCODE -ne 0) {
throw "Local build failed"
}
} else {
# Fallback to basic build
dotnet build WordleSharp.sln --configuration Release
if ($LASTEXITCODE -ne 0) {
throw "Build failed"
}
}
Write-Success "Local build passed"
# Show what will happen
Write-Host ""
Write-Host "π― Release Summary:" -ForegroundColor Cyan
Write-Host " Version: $Version" -ForegroundColor White
Write-Host " Tag: $tagName" -ForegroundColor White
Write-Host " Current branch: $(git branch --show-current)" -ForegroundColor White
if ($ReleaseNotes) {
Write-Host " Release notes: $ReleaseNotes" -ForegroundColor White
} else {
Write-Host " Release notes: (will be prompted)" -ForegroundColor Yellow
}
if ($DryRun) {
Write-Warning "DRY RUN - No actual release will be created"
Write-Host ""
Write-Host "What would happen:" -ForegroundColor Cyan
Write-Host "1. Create git tag: $tagName" -ForegroundColor White
Write-Host "2. Push tag to origin" -ForegroundColor White
Write-Host "3. GitHub Actions will:" -ForegroundColor White
Write-Host " β’ Update module version to $Version" -ForegroundColor White
Write-Host " β’ Build and test the solution" -ForegroundColor White
Write-Host " β’ Publish to PowerShell Gallery" -ForegroundColor White
exit 0
}
# Confirm release
Write-Host ""
$response = Read-Host "Create release $tagName? (y/N)"
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Host "Release cancelled by user"
exit 0
}
# Create and push tag
Write-Step "Creating git tag..."
git tag -a $tagName -m "Release version $Version"
if ($LASTEXITCODE -ne 0) {
throw "Failed to create git tag"
}
Write-Step "Pushing tag to origin..."
git push origin $tagName
if ($LASTEXITCODE -ne 0) {
throw "Failed to push tag"
} Write-Success "π Manual release $tagName created successfully!"
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "1. Go to GitHub and create a release from the tag" -ForegroundColor White
Write-Host "2. GitHub Actions will automatically:" -ForegroundColor White
Write-Host " β’ Build and test the module" -ForegroundColor White
Write-Host " β’ Update the module version" -ForegroundColor White
Write-Host " β’ Publish to PowerShell Gallery" -ForegroundColor White
Write-Host ""
Write-Host "π‘ For future releases, consider using automatic releases:" -ForegroundColor Cyan
Write-Host " Just merge to main with proper commit messages!" -ForegroundColor White
Write-Host " β’ 'Add feature' β minor bump (default)" -ForegroundColor White
Write-Host " β’ 'Fix bug [patch]' β patch bump" -ForegroundColor White
Write-Host " β’ 'Breaking change [major]' β major bump" -ForegroundColor White
Write-Host ""
Write-Host "Monitor the build at: https://github.com/$(git config --get remote.origin.url | sed 's/.*github.com[:/]\([^.]*\).*/\1/')/actions" -ForegroundColor Cyan
} catch {
Write-Host ""
Write-Host "β Release failed: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}