-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ps1
51 lines (36 loc) · 1.78 KB
/
publish.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
50
51
param (
[Parameter(Mandatory=$true)]
[String] $ApiKey
)
function PublishProject {
param (
[Parameter(Mandatory=$true)]
[String] $projectPath
)
[xml]$proj = Get-Content $projectPath;
$versionNode = Select-Xml -Xml $proj -XPath "//Version" | Select-Object @{l="Version";e={$_.node.InnerXML}}
$packageNameNode = Select-Xml -Xml $proj -XPath "//PackageId" | Select-Object @{l="PackageId";e={$_.node.InnerXML}}
$version = $versionNode.Version
$packageId = $packageNameNode.PackageId
Write-Host "Looking for $version $packageId"
try {
$response = Invoke-WebRequest "https://api.nuget.org/v3-flatcontainer/$packageId/index.json"
} catch {
$code = $_.Exception.Response.StatusCode.value__
Write-Host "No remote infomration, could be first time package - got $code"
dotnet pack $projectPath -c Release -o ./packs/$packageId
dotnet nuget push "./packs/$packageId/$packageId.$version.nupkg" --source https://api.nuget.org/v3/index.json --api-key $ApiKey;
return;
}
$versionList = $response.Content | ConvertFrom-Json
$serverPackageVersion = $versionList.versions[$versionList.versions.Length - 1]
Write-Host "$serverPackageVersion $version"
# if the versions are equal, then no need to push packages
if ($version -eq $serverPackageVersion) { return; }
Write-Host "Creating and publishing $packageId.$version"
dotnet pack $projectPath -c Release -o ./packs/$packageId
dotnet nuget push "./packs/$packageId/$packageId.$version.nupkg" --source https://api.nuget.org/v3/index.json --api-key $ApiKey;
}
Get-ChildItem -Path ./src/**/*.fsproj -Recurse
| Select-Object @{l="Name";e={$_.FullName}}
| ForEach-Object -Process { PublishProject -projectPath $_.Name }