-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-manual.ps1
More file actions
228 lines (195 loc) · 7.03 KB
/
publish-manual.ps1
File metadata and controls
228 lines (195 loc) · 7.03 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
#Requires -Version 7.0
<#
.SYNOPSIS
Manual NuGet publish script for SchemaMagic
.DESCRIPTION
Builds, packs, and publishes SchemaMagic to NuGet.org
.PARAMETER DryRun
Test build without publishing
.PARAMETER SkipTests
Skip running tests before publishing
.PARAMETER ApiKeyFile
Path to file containing NuGet API key (default: .secrets/nuget-api-key.txt)
.EXAMPLE
.\publish-manual.ps1
Full build, test, and publish
.EXAMPLE
.\publish-manual.ps1 -DryRun
Test build without publishing
.EXAMPLE
.\publish-manual.ps1 -SkipTests
Skip tests and publish
#>
param(
[switch]$DryRun,
[switch]$SkipTests,
[string]$ApiKeyFile = ".secrets/nuget-api-key.txt"
)
$ErrorActionPreference = "Stop"
# Set console encoding to UTF-8 to display emojis correctly
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host ""
Write-Host "?? SchemaMagic Manual Publish Script" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
# Check if nbgv is installed
try {
$null = nbgv --version
} catch {
Write-Host "? Nerdbank.GitVersioning (nbgv) not installed" -ForegroundColor Red
Write-Host "?? Installing nbgv..." -ForegroundColor Yellow
dotnet tool install -g nbgv
}
# Check API key file exists
if (-not (Test-Path $ApiKeyFile)) {
Write-Host "? API key file not found: $ApiKeyFile" -ForegroundColor Red
Write-Host ""
Write-Host "?? Create the file and add your NuGet API key:" -ForegroundColor Yellow
Write-Host " 1. Get key from: https://www.nuget.org/account/apikeys" -ForegroundColor White
Write-Host " 2. Save it to: $ApiKeyFile" -ForegroundColor White
Write-Host ""
exit 1
}
# Load API key
$API_KEY = (Get-Content $ApiKeyFile -Raw).Trim()
if ([string]::IsNullOrWhiteSpace($API_KEY)) {
Write-Host "? API key file is empty: $ApiKeyFile" -ForegroundColor Red
exit 1
}
Write-Host "? API key loaded from $ApiKeyFile" -ForegroundColor Green
# Get version
Write-Host ""
Write-Host "?? Getting version..." -ForegroundColor Yellow
$VERSION = nbgv get-version -v SemVer2
$SIMPLE_VERSION = nbgv get-version -v SimpleVersion
Write-Host "? Version: $VERSION" -ForegroundColor Green
Write-Host " Simple: $SIMPLE_VERSION" -ForegroundColor Cyan
# Check git status
$gitStatus = git status --porcelain
if ($gitStatus) {
Write-Host ""
Write-Host "?? Warning: You have uncommitted changes" -ForegroundColor Yellow
Write-Host "$gitStatus" -ForegroundColor Gray
$continue = Read-Host "Continue anyway? (y/N)"
if ($continue -ne "y") {
Write-Host "? Cancelled" -ForegroundColor Red
exit 1
}
}
# Clean
Write-Host ""
Write-Host "?? Cleaning previous builds..." -ForegroundColor Yellow
dotnet clean --verbosity quiet
Remove-Item -Recurse -Force ./nupkg -ErrorAction SilentlyContinue
Write-Host "? Clean complete" -ForegroundColor Green
# Restore
Write-Host ""
Write-Host "?? Restoring dependencies..." -ForegroundColor Yellow
dotnet restore --verbosity quiet
Write-Host "? Dependencies restored" -ForegroundColor Green
# Run tests
if (-not $SkipTests) {
Write-Host ""
Write-Host "?? Running tests..." -ForegroundColor Yellow
dotnet test --configuration Release --verbosity quiet --nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "? Tests failed" -ForegroundColor Red
exit 1
}
Write-Host "? All tests passed" -ForegroundColor Green
} else {
Write-Host ""
Write-Host "?? Skipping tests" -ForegroundColor Yellow
}
# Build
Write-Host ""
Write-Host "?? Building Release configuration..." -ForegroundColor Yellow
dotnet build --configuration Release --no-restore --verbosity quiet --nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "? Build failed" -ForegroundColor Red
exit 1
}
Write-Host "? Build successful" -ForegroundColor Green
# Pack
Write-Host ""
Write-Host "?? Creating NuGet package..." -ForegroundColor Yellow
dotnet pack SchemaMagic/SchemaMagic.csproj `
--configuration Release `
--output ./nupkg `
--no-build `
--verbosity quiet `
--nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "? Pack failed" -ForegroundColor Red
exit 1
}
# List generated packages
Write-Host "? Package created" -ForegroundColor Green
Write-Host ""
Write-Host "?? Generated packages:" -ForegroundColor Cyan
Get-ChildItem ./nupkg/*.nupkg | ForEach-Object {
$size = [math]::Round($_.Length / 1KB, 2)
Write-Host " $($_.Name) ($size KB)" -ForegroundColor White
}
if ($DryRun) {
Write-Host ""
Write-Host "?? DRY RUN - Skipping publish" -ForegroundColor Yellow
Write-Host ""
Write-Host "? Build successful! Package ready at ./nupkg/" -ForegroundColor Green
Write-Host ""
Write-Host "?? To publish for real, run without -DryRun:" -ForegroundColor Yellow
Write-Host " .\publish-manual.ps1" -ForegroundColor White
Write-Host ""
exit 0
}
# Confirm publish
Write-Host ""
Write-Host "?? About to publish version $VERSION to NuGet.org" -ForegroundColor Yellow
$confirm = Read-Host "Continue? (y/N)"
if ($confirm -ne "y") {
Write-Host "? Cancelled" -ForegroundColor Red
exit 1
}
# Publish
Write-Host ""
Write-Host "🚀 Publishing to NuGet.org..." -ForegroundColor Yellow
# Get the actual nupkg file path
$nupkgFiles = Get-ChildItem ./nupkg/*.nupkg -ErrorAction Stop
if ($nupkgFiles.Count -eq 0) {
Write-Host "❌ No .nupkg files found in ./nupkg/" -ForegroundColor Red
exit 1
}
Write-Host "📦 Found $($nupkgFiles.Count) package(s) to publish" -ForegroundColor Cyan
foreach ($pkg in $nupkgFiles) {
Write-Host " Publishing: $($pkg.Name)" -ForegroundColor White
dotnet nuget push $pkg.FullName `
--api-key $API_KEY `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "❌ Publish failed for $($pkg.Name) with exit code $LASTEXITCODE" -ForegroundColor Red
Write-Host ""
Write-Host "Common issues:" -ForegroundColor Yellow
Write-Host " • API key expired or invalid" -ForegroundColor White
Write-Host " • Version already published (NuGet doesn't allow overwrites)" -ForegroundColor White
Write-Host " • Network connectivity issues" -ForegroundColor White
Write-Host ""
exit 1
}
}
Write-Host ""
Write-Host "? Published successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "?? Package URL: https://www.nuget.org/packages/SchemaMagic/$SIMPLE_VERSION" -ForegroundColor Cyan
Write-Host ""
Write-Host "?? Next steps:" -ForegroundColor Yellow
Write-Host " 1. Wait 5-10 minutes for NuGet indexing" -ForegroundColor White
Write-Host " 2. Create git tag:" -ForegroundColor White
Write-Host " git tag -a v$VERSION -m 'Release v$VERSION'" -ForegroundColor Cyan
Write-Host " 3. Push tag to GitHub:" -ForegroundColor White
Write-Host " git push origin v$VERSION" -ForegroundColor Cyan
Write-Host " 4. Test installation:" -ForegroundColor White
Write-Host " dotnet tool update -g SchemaMagic" -ForegroundColor Cyan
Write-Host ""