-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildAndUploadApiClient.ps1
More file actions
95 lines (69 loc) · 2.97 KB
/
BuildAndUploadApiClient.ps1
File metadata and controls
95 lines (69 loc) · 2.97 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
$lastVersion = "";
$nuspecContent = Get-Content -Path ".\QueueService.Api.Client\QueueService.Api.Client.nuspec" -raw
$versionMatch = [regex]::Match($nuspecContent,'<version>(.*)</version>')
if(!$versionMatch.Success)
{
throw 'Previous version not found in nuspec file. Make sure it looks like this <version>x.x.x</version>'
}
$lastVersionString = $versionMatch.Groups[1].Value
try{
$lastVersion = [version]($lastVersionString)
}
catch {
Write-Host $_ -BackgroundColor Black -ForegroundColor Red
Write-Host "Incorrect format of version in nuspec file"
Read-Host -Prompt "Enter to exit"
exit
}
$automaticVersionToUse = "1.0.0"
if(![string]::IsNullOrEmpty($lastVersion))
{
$automaticVersionToUse = "{0}.{1}.{2}" -f $lastVersion.Major, $lastVersion.Minor, ($lastVersion.Build + 1)
}
$manualVersion = Read-Host -Prompt "OPTIONAL: Manual version number (Press enter for automatic - $automaticVersionToUse)"
$newVersion = $automaticVersionToUse;
if(![string]::IsNullOrEmpty($manualVersion))
{
try{
$splitManual = [System.Version]::Parse($manualVersion)
}
catch {
Write-Host $_ -BackgroundColor Black -ForegroundColor Red
Write-Host "Incorrect format of given version - Should have format Major.Minor.Build so for instance 1.0.2"
Read-Host -Prompt "Enter to exit"
exit
}
$newVersion = $manualVersion;
}
$releaseNotes = Read-Host -Prompt "Release notes"
$releaseNotesMatch = [regex]::Match($nuspecContent,'<releaseNotes>.*</releaseNotes>')
if(!$releaseNotesMatch.Success)
{
throw 'release notes not found in nuspec file. Make sure it looks like this <releaseNotes>xxxxxxxx</releaseNotes>'
}
$lastReleaseNotesString = $releaseNotesMatch.Value
Set-Content -Path ".\QueueService.Api.Client\QueueService.Api.Client.nuspec" -Value $($nuspecContent -replace $("<version>$($lastVersionString)</version>"),$("<version>$($newVersion)</version>") -replace $lastReleaseNotesString,"<releaseNotes>$($releaseNotes)</releaseNotes>")
dotnet build ".\QueueService.Api.Model\QueueService.Api.Model.csproj" --configuration Release
dotnet build ".\QueueService.Api.Client\QueueService.Api.Client.csproj" --configuration Release
..\nuget.exe pack .\QueueService.Api.Client\QueueService.Api.Client.csproj -Properties Configuration=Release
Write-Host "Press enter to push to nuget server (or close to not push)" -BackgroundColor Black -ForegroundColor Cyan
Read-Host
$nugetApiKey = ""
if([System.IO.File]::Exists(".\NugetKey.txt"))
{
$nugetApiKey = Get-Content -Path .\NugetKey.txt -First 1
}
else
{
Write-Host $_ -BackgroundColor Black -ForegroundColor Red
Write-Host "There must be a NugetKey.txt in the same directory as this build script that contains only the api key to the nuget server"
Read-Host -Prompt "Enter to exit"
exit
}
$packages = gci ".\*.nupkg"
foreach ($package in $packages){
$packageLocation = ".\" + $package.Name
..\nuget.exe push $packageLocation $nugetApiKey -Source https://api.nuget.org/v3/index.json
Remove-Item –path $packageLocation
}
Read-Host -Prompt "Enter to exit"