-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-release.ps1
More file actions
236 lines (186 loc) · 6.93 KB
/
create-release.ps1
File metadata and controls
236 lines (186 loc) · 6.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#Requires -Version 7.0
<#
.SYNOPSIS
Merges develop to main to trigger a release.
.DESCRIPTION
This script automates the release process:
1. Ensures you're on the develop branch with no uncommitted changes
2. Runs tests (optional)
3. Merges develop to main
4. Pushes main to trigger the Azure DevOps release pipeline
The Azure DevOps pipeline handles version calculation and tagging automatically.
Releases are published to the GitHub mirror at: https://github.com/DevPossible/lcd-possible
.PARAMETER SkipTests
Skip running tests before release.
.PARAMETER DryRun
Show what would be done without making changes.
.EXAMPLE
./create-release.ps1
# Merges develop to main and triggers release
.EXAMPLE
./create-release.ps1 -SkipTests
# Skip tests and proceed with release
.EXAMPLE
./create-release.ps1 -DryRun
# Shows what would happen without making changes
#>
param(
[switch]$SkipTests,
[switch]$DryRun
)
$ErrorActionPreference = 'Stop'
# ============================================================================
# Helper Functions
# ============================================================================
function Write-Step {
param([string]$Message)
Write-Host "`n=== $Message ===" -ForegroundColor Cyan
}
function Write-Info {
param([string]$Message)
Write-Host " $Message" -ForegroundColor Gray
}
function Write-Success {
param([string]$Message)
Write-Host " [OK] $Message" -ForegroundColor Green
}
function Write-Skipped {
param([string]$Message)
Write-Host " [SKIP] $Message" -ForegroundColor DarkGray
}
function Write-Warning {
param([string]$Message)
Write-Host " [WARN] $Message" -ForegroundColor Yellow
}
function Invoke-Git {
param(
[Parameter(Mandatory)]
[string]$Command,
[switch]$AllowFailure,
[switch]$Quiet
)
if ($DryRun) {
Write-Host " [DRY-RUN] git $Command" -ForegroundColor Magenta
return ""
}
$result = Invoke-Expression "git $Command 2>&1"
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0 -and -not $AllowFailure) {
throw "Git command failed (exit $exitCode): git $Command`n$result"
}
if (-not $Quiet -and $result) {
$result | ForEach-Object { Write-Info $_ }
}
return $result
}
function Get-CurrentBranch {
return (git branch --show-current 2>$null)?.Trim()
}
function Test-WorkingTreeClean {
$status = git status --porcelain 2>$null
return -not $status
}
# ============================================================================
# Pre-flight Checks
# ============================================================================
Write-Step "Pre-flight Checks"
# Check we're in a git repository
if (-not (Test-Path ".git")) {
throw "Not in a git repository root. Run from the project root directory."
}
Write-Success "In git repository"
# Check we're on develop branch
$currentBranch = Get-CurrentBranch
if ($currentBranch -ne "develop") {
throw "Must be on develop branch to create a release. Currently on: $currentBranch"
}
Write-Success "On develop branch"
# Check working tree is clean
if (-not (Test-WorkingTreeClean)) {
Write-Host "`nUncommitted changes detected:" -ForegroundColor Red
git status --porcelain | ForEach-Object { Write-Host " $_" -ForegroundColor Yellow }
throw "Please commit or stash changes before creating a release."
}
Write-Success "Working tree clean"
# ============================================================================
# Run Tests
# ============================================================================
if (-not $SkipTests) {
Write-Step "Running Tests"
if ($DryRun) {
Write-Host " [DRY-RUN] ./test-smoke.ps1" -ForegroundColor Magenta
} else {
& "$PSScriptRoot/test-smoke.ps1"
if ($LASTEXITCODE -ne 0) {
throw "Tests failed. Fix tests before releasing."
}
Write-Success "All tests passed"
}
} else {
Write-Skipped "Tests (--SkipTests)"
}
# ============================================================================
# Show What Will Be Released
# ============================================================================
Write-Step "Release Preview"
# Get last tag and commit info
$lastTag = git describe --tags --abbrev=0 2>$null
if ($lastTag) {
Write-Info "Last release: $lastTag"
$commitCount = git rev-list "$lastTag..HEAD" --count 2>$null
Write-Info "Commits since last release: $commitCount"
Write-Host "`n Recent commits:" -ForegroundColor White
git log "$lastTag..HEAD" --pretty=format:" - %s" --reverse 2>$null | Select-Object -First 10 | ForEach-Object { Write-Host $_ -ForegroundColor Gray }
} else {
Write-Info "No previous releases"
}
# Confirm
if (-not $DryRun) {
Write-Host "`nProceed with release? (Y/n): " -NoNewline -ForegroundColor Yellow
$response = Read-Host
if ($response -and $response -notmatch '^[Yy]$') {
Write-Host "Release cancelled." -ForegroundColor Yellow
exit 0
}
}
# ============================================================================
# Merge to Main
# ============================================================================
Write-Step "Merging to Main"
# Fetch latest
Invoke-Git "fetch origin" -Quiet
Write-Info "Fetched latest from origin"
# Checkout main
Invoke-Git "checkout main" -Quiet
Write-Info "Switched to main branch"
# Pull latest main to avoid conflicts
$pullResult = Invoke-Git "pull origin main --ff-only" -AllowFailure -Quiet
if ($LASTEXITCODE -ne 0) {
Write-Warning "Could not fast-forward main. Attempting merge anyway..."
}
# Merge develop
Invoke-Git "merge develop --no-edit" -Quiet
Write-Success "Merged develop into main"
# ============================================================================
# Push to Remote
# ============================================================================
Write-Step "Pushing to Remote"
Invoke-Git "push origin main" -Quiet
Write-Success "Pushed main branch"
# Switch back to develop
Invoke-Git "checkout develop" -Quiet
Write-Info "Switched back to develop branch"
# ============================================================================
# Summary
# ============================================================================
Write-Host "`n" + ("=" * 60) -ForegroundColor Green
Write-Host " RELEASE TRIGGERED!" -ForegroundColor Green
Write-Host ("=" * 60) -ForegroundColor Green
Write-Host "`nThe Azure DevOps pipeline will now:"
Write-Host " 1. Calculate the version from conventional commits" -ForegroundColor White
Write-Host " 2. Build artifacts for all platforms" -ForegroundColor White
Write-Host " 3. Create a GitHub release on the public mirror" -ForegroundColor White
Write-Host "`nMonitor the release pipeline:" -ForegroundColor White
Write-Host " Azure DevOps: Check your organization's pipelines" -ForegroundColor Blue
Write-Host " GitHub Releases: https://github.com/DevPossible/lcd-possible/releases" -ForegroundColor Blue
Write-Host ""