-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.ps1
More file actions
201 lines (170 loc) · 6 KB
/
release.ps1
File metadata and controls
201 lines (170 loc) · 6 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# ModelingEvolution.Drawing Release Script for Windows
# Usage: .\release.ps1 [-Patch] [-Minor] [-Major] [-Version X.X.X.X]
param(
[switch]$Patch = $false,
[switch]$Minor = $false,
[switch]$Major = $false,
[string]$Version = ""
)
# Colors for output
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor Green }
function Write-Warn { Write-Host "[WARN] $args" -ForegroundColor Yellow }
function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor Red }
# Function to get the latest version from git tags
function Get-CurrentVersion {
$latestTag = git tag -l "ModelingEvolution.Drawing/*" | Sort-Object -Version | Select-Object -Last 1
if ($latestTag) {
# Extract version from tag (format: ModelingEvolution.Drawing/1.0.57.35)
return $latestTag -replace "ModelingEvolution.Drawing/", ""
}
else {
# Fallback to csproj if no tags exist
$csprojPath = "Sources\ModelingEvolution.Drawing\ModelingEvolution.Drawing.csproj"
if (Test-Path $csprojPath) {
$csproj = Get-Content $csprojPath -Raw
if ($csproj -match '<AssemblyVersion>([^<]+)</AssemblyVersion>') {
return $matches[1]
}
}
return "1.0.57.35" # Default based on known last version
}
}
# Function to calculate next version
function Get-NextVersion {
param(
[string]$CurrentVersion,
[string]$BumpType
)
$parts = $CurrentVersion.Split('.')
$major = [int]$parts[0]
$minor = if ($parts.Length -gt 1) { [int]$parts[1] } else { 0 }
$patch = if ($parts.Length -gt 2) { [int]$parts[2] } else { 0 }
$build = if ($parts.Length -gt 3) { [int]$parts[3] } else { 0 }
switch ($BumpType) {
"major" {
$major++
$minor = 0
$patch = 0
$build = 0
}
"minor" {
$minor++
$patch = 0
$build++
}
"patch" {
$patch++
$build++
}
default {
Write-Error "Unknown bump type: $BumpType"
exit 1
}
}
return "$major.$minor.$patch.$build"
}
# Function to update version in csproj
function Update-CsprojVersion {
param([string]$Version)
$csprojPath = "Sources\ModelingEvolution.Drawing\ModelingEvolution.Drawing.csproj"
if (-not (Test-Path $csprojPath)) {
Write-Error "Could not find $csprojPath"
return $false
}
Write-Info "Updating version in $csprojPath to $Version"
$content = Get-Content $csprojPath -Raw
# Update AssemblyVersion
$content = $content -replace '<AssemblyVersion>[^<]+</AssemblyVersion>', "<AssemblyVersion>$Version</AssemblyVersion>"
# Update FileVersion
$content = $content -replace '<FileVersion>[^<]+</FileVersion>', "<FileVersion>$Version</FileVersion>"
# Update or add Version tag
if ($content -match '<Version>') {
$content = $content -replace '<Version>[^<]+</Version>', "<Version>$Version</Version>"
}
else {
# Add Version after AssemblyVersion
$content = $content -replace '(<AssemblyVersion>[^<]+</AssemblyVersion>)', "`$1`n <Version>$Version</Version>"
}
Set-Content -Path $csprojPath -Value $content -NoNewline
return $true
}
# Main script
function Main {
# Determine bump type
$bumpType = "patch" # Default
$customVersion = ""
if ($Major) { $bumpType = "major" }
elseif ($Minor) { $bumpType = "minor" }
elseif ($Patch) { $bumpType = "patch" }
elseif ($Version) { $customVersion = $Version }
# Ensure we're in a git repository
try {
git rev-parse --git-dir | Out-Null
}
catch {
Write-Error "Not in a git repository"
exit 1
}
# Check for uncommitted changes
$gitStatus = git status --porcelain
if ($gitStatus) {
Write-Warn "You have uncommitted changes. Continue anyway? (y/N)"
$response = Read-Host
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Info "Aborted"
exit 0
}
}
# Get current version
$currentVersion = Get-CurrentVersion
Write-Info "Current version: $currentVersion"
# Calculate next version
if ($customVersion) {
$nextVersion = $customVersion
Write-Info "Using custom version: $nextVersion"
}
else {
$nextVersion = Get-NextVersion -CurrentVersion $currentVersion -BumpType $bumpType
Write-Info "Next version ($bumpType bump): $nextVersion"
}
# Confirm with user
Write-Host ""
Write-Warn "This will:"
Write-Host " 1. Update version in .csproj to $nextVersion"
Write-Host " 2. Commit the changes"
Write-Host " 3. Create tag: ModelingEvolution.Drawing/$nextVersion"
Write-Host " 4. Push changes and tag to origin"
Write-Host ""
Write-Warn "Continue? (y/N)"
$response = Read-Host
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Info "Aborted"
exit 0
}
# Update csproj
if (-not (Update-CsprojVersion -Version $nextVersion)) {
exit 1
}
# Commit changes
Write-Info "Committing version update..."
git add Sources/ModelingEvolution.Drawing/ModelingEvolution.Drawing.csproj
git commit -m "Bump version to $nextVersion"
# Create tag
$tagName = "ModelingEvolution.Drawing/$nextVersion"
Write-Info "Creating tag: $tagName"
git tag -a $tagName -m "Release ModelingEvolution.Drawing v$nextVersion"
# Push changes and tag
Write-Info "Pushing to origin..."
git push origin HEAD
git push origin $tagName
Write-Info "✅ Successfully created release $nextVersion"
Write-Host ""
Write-Host "Tag: $tagName"
Write-Host "This will trigger the GitHub Actions workflow to:"
Write-Host " - Create a GitHub release"
Write-Host " - Publish to NuGet"
Write-Host ""
Write-Host "Monitor progress at: https://github.com/modelingevolution/drawing/actions"
}
# Run main function
Main