Skip to content

Commit fb68d7e

Browse files
committed
add realease script
1 parent 2dda3ff commit fb68d7e

2 files changed

Lines changed: 193 additions & 1 deletion

File tree

EtabSharp.sln

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 18
4-
VisualStudioVersion = 18.1.11304.174 d18.0
4+
VisualStudioVersion = 18.1.11304.174
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
7+
ProjectSection(SolutionItems) = preProject
8+
release-package.ps1 = release-package.ps1
9+
EndProjectSection
710
EndProject
811
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
912
ProjectSection(SolutionItems) = preProject
@@ -16,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1619
PUBLISH_GUIDE.md = PUBLISH_GUIDE.md
1720
PUBLISH_QUICK_START.md = PUBLISH_QUICK_START.md
1821
README.md = README.md
22+
release-package.ps1 = release-package.ps1
1923
EndProjectSection
2024
EndProject
2125
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E1550E01-A197-42F6-BD5D-86F838187C93}"

release-package.ps1

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# release-package.ps1
2+
# Script to build and package EtabSharp for NuGet release
3+
4+
param(
5+
[Parameter(Mandatory=$false)]
6+
[string]$Version = "",
7+
8+
[Parameter(Mandatory=$false)]
9+
[switch]$SkipTests = $false,
10+
11+
[Parameter(Mandatory=$false)]
12+
[switch]$Push = $false,
13+
14+
[Parameter(Mandatory=$false)]
15+
[string]$ApiKey = ""
16+
)
17+
18+
$ErrorActionPreference = "Stop"
19+
20+
Write-Host ""
21+
Write-Host "================================================" -ForegroundColor Cyan
22+
Write-Host "EtabSharp NuGet Package Release Script" -ForegroundColor Cyan
23+
Write-Host "================================================" -ForegroundColor Cyan
24+
Write-Host ""
25+
26+
# Navigate to solution root
27+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
28+
Set-Location $scriptPath
29+
30+
# Check if we're in the right directory
31+
if (-not (Test-Path "EtabSharp.sln")) {
32+
Write-Host "Error: EtabSharp.sln not found. Please run this script from the solution root." -ForegroundColor Red
33+
exit 1
34+
}
35+
36+
# Get current version from .csproj if not specified
37+
if ([string]::IsNullOrEmpty($Version)) {
38+
$csprojPath = "src\EtabSharp\EtabSharp.csproj"
39+
$csprojContent = Get-Content $csprojPath -Raw
40+
if ($csprojContent -match '<Version>(.*?)</Version>') {
41+
$Version = $matches[1]
42+
Write-Host "Using version from .csproj: $Version" -ForegroundColor Yellow
43+
} else {
44+
Write-Host "Error: Could not find version in .csproj and no version specified" -ForegroundColor Red
45+
exit 1
46+
}
47+
}
48+
49+
Write-Host "Building EtabSharp v$Version..." -ForegroundColor Green
50+
Write-Host ""
51+
52+
# Step 1: Clean
53+
Write-Host "Step 1: Cleaning previous builds..." -ForegroundColor Yellow
54+
dotnet clean --configuration Release
55+
if ($LASTEXITCODE -ne 0) {
56+
Write-Host "Clean failed!" -ForegroundColor Red
57+
exit 1
58+
}
59+
Write-Host "✓ Clean completed" -ForegroundColor Green
60+
Write-Host ""
61+
62+
# Step 2: Restore
63+
Write-Host "Step 2: Restoring NuGet packages..." -ForegroundColor Yellow
64+
dotnet restore
65+
if ($LASTEXITCODE -ne 0) {
66+
Write-Host "Restore failed!" -ForegroundColor Red
67+
exit 1
68+
}
69+
Write-Host "✓ Restore completed" -ForegroundColor Green
70+
Write-Host ""
71+
72+
# Step 3: Run tests (optional)
73+
if (-not $SkipTests) {
74+
Write-Host "Step 3: Running tests..." -ForegroundColor Yellow
75+
dotnet test --configuration Release --no-restore
76+
if ($LASTEXITCODE -ne 0) {
77+
Write-Host "Tests failed! Use -SkipTests to skip testing." -ForegroundColor Red
78+
exit 1
79+
}
80+
Write-Host "✓ All tests passed" -ForegroundColor Green
81+
Write-Host ""
82+
} else {
83+
Write-Host "Step 3: Skipping tests (as requested)" -ForegroundColor Yellow
84+
Write-Host ""
85+
}
86+
87+
# Step 4: Build
88+
Write-Host "Step 4: Building in Release mode..." -ForegroundColor Yellow
89+
dotnet build src\EtabSharp\EtabSharp.csproj --configuration Release --no-restore
90+
if ($LASTEXITCODE -ne 0) {
91+
Write-Host "Build failed!" -ForegroundColor Red
92+
exit 1
93+
}
94+
Write-Host "✓ Build completed" -ForegroundColor Green
95+
Write-Host ""
96+
97+
# Step 5: Pack
98+
Write-Host "Step 5: Creating NuGet package..." -ForegroundColor Yellow
99+
$outputDir = ".\artifacts"
100+
if (-not (Test-Path $outputDir)) {
101+
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
102+
}
103+
104+
dotnet pack src\EtabSharp\EtabSharp.csproj `
105+
--configuration Release `
106+
--no-build `
107+
--output $outputDir `
108+
/p:PackageVersion=$Version
109+
110+
if ($LASTEXITCODE -ne 0) {
111+
Write-Host "Pack failed!" -ForegroundColor Red
112+
exit 1
113+
}
114+
Write-Host "✓ Package created" -ForegroundColor Green
115+
Write-Host ""
116+
117+
# Find the created package
118+
$packageFile = Get-ChildItem "$outputDir\EtabSharp.$Version.nupkg" -ErrorAction SilentlyContinue
119+
if (-not $packageFile) {
120+
Write-Host "Error: Package file not found at $outputDir\EtabSharp.$Version.nupkg" -ForegroundColor Red
121+
exit 1
122+
}
123+
124+
$packageSize = [math]::Round($packageFile.Length / 1MB, 2)
125+
126+
Write-Host ""
127+
Write-Host "================================================" -ForegroundColor Green
128+
Write-Host "✓ Package Created Successfully!" -ForegroundColor Green
129+
Write-Host "================================================" -ForegroundColor Green
130+
Write-Host ""
131+
Write-Host "Package Details:" -ForegroundColor Cyan
132+
Write-Host " Version: $Version" -ForegroundColor White
133+
Write-Host " Location: $($packageFile.FullName)" -ForegroundColor White
134+
Write-Host " Size: $packageSize MB" -ForegroundColor White
135+
Write-Host ""
136+
137+
# Step 6: Verify package contents
138+
Write-Host "Step 6: Verifying package contents..." -ForegroundColor Yellow
139+
dotnet nuget verify $packageFile.FullName
140+
Write-Host ""
141+
142+
# Step 7: Push to NuGet (optional)
143+
if ($Push) {
144+
if ([string]::IsNullOrEmpty($ApiKey)) {
145+
Write-Host "Error: -Push specified but no -ApiKey provided" -ForegroundColor Red
146+
Write-Host "Usage: .\release-package.ps1 -Push -ApiKey YOUR_API_KEY" -ForegroundColor Yellow
147+
exit 1
148+
}
149+
150+
Write-Host "Step 7: Publishing to NuGet.org..." -ForegroundColor Yellow
151+
Write-Host "Package: $($packageFile.Name)" -ForegroundColor White
152+
153+
$confirm = Read-Host "Are you sure you want to publish to NuGet.org? (yes/no)"
154+
if ($confirm -eq "yes") {
155+
dotnet nuget push $packageFile.FullName --api-key $ApiKey --source https://api.nuget.org/v3/index.json
156+
157+
if ($LASTEXITCODE -eq 0) {
158+
Write-Host ""
159+
Write-Host "✓ Package published successfully!" -ForegroundColor Green
160+
Write-Host "It may take a few minutes to appear on NuGet.org" -ForegroundColor Yellow
161+
} else {
162+
Write-Host ""
163+
Write-Host "✗ Publish failed!" -ForegroundColor Red
164+
exit 1
165+
}
166+
} else {
167+
Write-Host "Publish cancelled by user" -ForegroundColor Yellow
168+
}
169+
} else {
170+
Write-Host "================================================" -ForegroundColor Yellow
171+
Write-Host "Next Steps:" -ForegroundColor Yellow
172+
Write-Host "================================================" -ForegroundColor Yellow
173+
Write-Host "1. Verify package contents:" -ForegroundColor White
174+
Write-Host " dotnet nuget verify `"$($packageFile.FullName)`"" -ForegroundColor Cyan
175+
Write-Host ""
176+
Write-Host "2. Test package locally:" -ForegroundColor White
177+
Write-Host " dotnet nuget add source $outputDir --name LocalPackages" -ForegroundColor Cyan
178+
Write-Host ""
179+
Write-Host "3. Publish to NuGet.org:" -ForegroundColor White
180+
Write-Host " .\release-package.ps1 -Version $Version -Push -ApiKey YOUR_API_KEY" -ForegroundColor Cyan
181+
Write-Host ""
182+
Write-Host "Or manually:" -ForegroundColor White
183+
Write-Host " dotnet nuget push `"$($packageFile.FullName)`" --api-key YOUR_KEY --source https://api.nuget.org/v3/index.json" -ForegroundColor Cyan
184+
Write-Host ""
185+
}
186+
187+
Write-Host "================================================" -ForegroundColor Cyan
188+
Write-Host ""

0 commit comments

Comments
 (0)