-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish-to-nuget.ps1
49 lines (38 loc) · 1.41 KB
/
publish-to-nuget.ps1
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
# Get NuGet API Key from environment variable
$apiKey = $env:NUGET_API_KEY
# Error handling function
function Write-ErrorAndExit {
param(
$message
)
Write-Host $message -ForegroundColor Red
exit 1
}
# Check for NuGet API Key in environment variable
if (-not $apiKey) {
Write-ErrorAndExit "NuGet API Key not found in environment variable 'NUGET_API_KEY'. Please set the environment variable and try again."
}
# Check if current branch is main
$currentBranch = git rev-parse --abbrev-ref HEAD
if ($currentBranch -ne "main") {
Write-ErrorAndExit "Publishing is only allowed from the 'main' branch. Current branch: $currentBranch"
}
# Build and pack Flowbite.Blazor
Write-Host "Packing..."
# Delete the .\artifacts directory before running pack
if (Test-Path ".\artifacts") {
rm -r -force .\artifacts
}
dotnet pack
if ($LASTEXITCODE -ne 0) {
Write-ErrorAndExit "Error occurred while packing Flowbite templates"
}
Write-Host "NuGet package created in .\artifacts directory" -ForegroundColor Green
# Publish to NuGet.org
Write-Host "Publishing Flowbite Templates to NuGet.org..."
# Publish Flowbite.Blazor
dotnet nuget push .\artifacts\Flowbite.*.nupkg -s https://api.nuget.org/v3/index.json -k $apiKey --skip-duplicate
if ($LASTEXITCODE -ne 0) {
Write-ErrorAndExit "An error occurred while publishing Flowbite templates"
}
Write-Host "Flowbite templates published successfully to NuGet.org!" -ForegroundColor Green