-
Notifications
You must be signed in to change notification settings - Fork 7
/
Publish.ps1
165 lines (127 loc) · 3.9 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
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
Param (
[Parameter(Mandatory = $true)]
[Version] $Version,
[ValidateSet('Archive', 'Publish')]
[string] $Mode = 'Publish'
)
Enum PublishMode {
Archive = 0
Publish = 1
}
$_Mode = [PublishMode]$Mode
Set-Location $(Get-Item "$PSScriptRoot").FullName
if (Get-Module Common) {
Remove-Module Common -Force
}
if (Get-Module Antlr) {
Remove-Module Antlr -Force
}
Import-Module ".\Build\Common.ps1"
if ($_Mode -eq [PublishMode]::Publish) {
$NugetApiKey = $Env:QSI_NUGET_API_KEY
if ($NugetApiKey.Length -eq 0) {
throw "QSI_NUGET_API_KEY environment variable not found."
}
}
Class Task {
[string] $Project
[bool] $Antlr
Task ([string] $Project, [bool] $Antlr) {
$this.Project = $Project
$this.Antlr = $Antlr
}
}
$PublishDirectory = $(Resolve-Path-Safe ".\Publish")
$Tasks =
[Task]::new("Qsi", $false),
[Task]::new("Qsi.MySql", $true),
[Task]::new("Qsi.PostgreSql", $false),
[Task]::new("Qsi.Oracle", $true),
[Task]::new("Qsi.SqlServer", $false),
[Task]::new("Qsi.PhoenixSql", $false),
[Task]::new("Qsi.Cql", $true),
[Task]::new("Qsi.PrimarSql", $false),
[Task]::new("Qsi.Hana", $true),
[Task]::new("Qsi.Impala", $true),
[Task]::new("Qsi.Trino", $true),
[Task]::new("Qsi.Athena", $true),
[Task]::new("Qsi.Redshift", $false),
[Task]::new("Qsi.SingleStore", $true)
Function DotNet-Pack {
Param (
[Parameter(Mandatory = $true)][string] $ProjectName
)
Write-Host "[.NET] $($ProjectName) Pack" -ForegroundColor Cyan
Remove-Directory-Safe "$ProjectName/bin"
Remove-Directory-Safe "$ProjectName/obj"
dotnet pack $ProjectName `
--nologo `
-v=q `
-c Release `
-o $PublishDirectory `
-p:Version=$Version `
-p:PackageVersion=$Version `
-p:Packaging=true
}
Function NuGet-Push {
Param (
[Parameter(Mandatory = $true)]
[System.IO.FileInfo] $PackageFile,
[Parameter(Mandatory = $true)]
[string] $Source,
[Parameter(Mandatory = $true)]
[string] $ApiKey
)
Write-Host "[NuGet] '$($PackageFile.Name)' Push to '$Source'" -ForegroundColor Cyan
dotnet nuget push $PackageFile --source $Source --api-key $ApiKey
}
Function Check-Nuget-Package-Index {
Param (
[Parameter(Mandatory = $true)][string] $PackageName,
[Parameter(Mandatory = $true)][version] $Version
)
$IndexedVersions = (Invoke-WebRequest https://api.nuget.org/v3-flatcontainer/$PackageName/index.json | ConvertFrom-Json).versions
return $IndexedVersions -contains $Version
}
# Clean publish
Remove-Directory-Safe $PublishDirectory
$Tasks | ForEach-Object {
if ($PSItem.Antlr) {
& "$PSScriptRoot\Setup.ps1" $PSItem.Project
}
DotNet-Pack $PSItem.Project
}
Write-Host "Done pack." -ForegroundColor Green
if ($_Mode -eq [PublishMode]::Publish) {
# Publish
Get-ChildItem -Path $PublishDirectory/*.nupkg | ForEach-Object {
NuGet-Push $PSItem "https://api.nuget.org/v3/index.json" $NugetApiKey
}
# Tag
if ($_Mode -eq [PublishMode]::Publish) {
$GitTag = "v$Version"
git tag $GitTag
git push origin $GitTag
}
# Waiting for NuGet Indexing
$Packages = @()
$Tasks | ForEach { $Packages += $_.Project }
Write-Host "Waiting for indexing NuGet packages"
while ($Packages.Length -gt 0) {
$PackageName = $Packages[0]
if (Check-Nuget-Package-Index $PackageName $Version) {
Write-Host "NuGet package $PackageName $Version has been indexed"
if ($Packages.Length -eq 1) {
break
}
$Packages = $Packages[1..($Packages.Length - 1)]
continue
}
else {
Write-Host "Waiting NuGet package $PackageName $Version indexing"
}
sleep 15
}
Write-Host "All NuGet packages has been indexed"
Write-Host "Done $Version publish." -ForegroundColor Green
}