-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.ps1
executable file
·162 lines (129 loc) · 5.04 KB
/
build.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
#!/usr/bin/env pwsh
# Copyright 2021 WGBH Educational Foundation
# Licensed under the Apache License, Version 2.0
param (
[Parameter(Mandatory = $true)]
[string]$WwsVersion,
[Parameter(Mandatory = $true)]
[int]$PackagePatch,
[string]$PreRelease,
[string[]]$Endpoints,
[int]$WarningLevel = 4,
[string]$PushTo,
[switch]$SkipComponentIfAlreadyPushed,
[string]$ApiKey,
[switch]$LocalDryRun
)
$ProgressPreference = 'SilentlyContinue'
if ($WwsVersion -notmatch '^\d+.\d+$') {
Write-Error '-WwsVersion is not of the correct format!'
exit 1
}
if ($PackagePatch -lt 0 -or $PackagePatch -gt 100) {
Write-Error '-PackagePatch is out of range!'
exit 1
}
# match blank or groupings of letter/numbers/hyphen separated by periods
if ($PreRelease -notmatch '^(?:[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$') {
Write-Error '-PreRelease contains invalid characters!'
exit 1
}
if ($LocalDryRun -and $PushTo) {
Write-Warning '-LocalDryRun specified; ignoring -PushTo'
}
Set-Location $PSScriptRoot/Endpoints
$allEndpoints = Get-Content endpoints.json | ConvertFrom-Json
if($null -eq $endpoints) {
$endpoints = $allEndpoints
} elseif($endpoints.Length -eq 0) {
Write-Warning ('An empty array was specified for -Endpoints. ' `
+ 'Remove the switch to generate all endpoints.')
exit
}
$packageVersion = "$WwsVersion.$PackagePatch" + (($PreRelease)? "-$PreRelease" : "")
$root = 'WorkSharp.Wws'
$template = @"
<?xml version="1.0" encoding="utf-8"?>
<Configuration xmlns="http://www.microsoft.com/xml/schema/linq">
<NullableReferences>true</NullableReferences>
<Namespaces>
<Namespace Schema="urn:com.workday/bsvc" Clr="$root.{0}" />
</Namespaces>
</Configuration>
"@
if(!$LocalDryRun -and $PushTo -and $SkipComponentIfAlreadyPushed) {
$dotnetNugetOutputLines = dotnet nuget list source
$indexInOuput = 1 + $dotnetNugetOutputLines.IndexOf(
$dotnetNugetOutputLines.Where({ $_ -like "* $PushTo *" }))
$serviceIndexUri = $dotnetNugetOutputLines[$indexInOuput].Trim()
$packageBaseUri = (Invoke-RestMethod $serviceIndexUri).resources.Where(
{$_.'@type' -eq 'PackageBaseAddress/3.0.0'} ).'@id'
if(!$?) { exit 1 }
}
dotnet tool restore
if(Test-Path build) {
Remove-Item -Force -Recurse build/*
} else {
New-Item -ItemType Directory build > $null
}
foreach($endpoint in $endpoints) {
if($endpoint -notin $allEndpoints) {
Write-Warning "$endpoint is not a valid endpoint name. Skipping..."
continue
}
$packageName = "$root.Endpoints.$endpoint"
if(!$LocalDryRun -and $PushTo -and $SkipComponentIfAlreadyPushed) {
$packageLower = $packageName.ToLower()
$packageUri = "$packageBaseUri$packageLower/$packageVersion/$packageLower.nuspec"
Invoke-RestMethod -Method HEAD $packageUri `
-SkipHttpErrorCheck -StatusCodeVariable packageLookupStatus > $null
if(!$?) { exit 1 }
if ($packageLookupStatus -eq 200) {
"Skipping $endpoint version $WwsVersion..."
continue
}
}
$baseEndpointInfoUri = 'https://community.workday.com/sites/default/files/file-hosting/productionapi/' `
+ "$endpoint/v$WwsVersion/$endpoint"
Invoke-RestMethod -Method HEAD "$baseEndpointInfoUri.xsd" `
-SkipHttpErrorCheck -StatusCodeVariable xsdLookupStatus > $null
if ($xsdLookupStatus -eq 404) {
Write-Warning "Endpoint $endpoint does not exist for WWS version $WwsVersion."
continue
}
"Generating package for $endpoint version $WwsVersion..."
Set-Location $PSScriptRoot/Endpoints/build
New-Item -ItemType Directory $endpoint > $null
Set-Location $endpoint
Copy-Item $PSScriptRoot/Endpoints/template.csproj "$packageName.csproj"
$template -f $endpoint > "$endpoint.xsd.config"
Invoke-WebRequest "$baseEndpointInfoUri.xsd" -OutFile "$endpoint.xsd"
if(!$?) { exit 1 }
dotnet LinqToXsd gen "$endpoint.xsd" --Config "$endpoint.xsd.config"
if(!$?) { exit 1 }
Invoke-WebRequest "$baseEndpointInfoUri.wsdl" -OutFile "$endpoint.wsdl"
if(!$?) { exit 1 }
dotnet run -c Release --project $PSScriptRoot/ClientBuilder -- "$endpoint.wsdl"
if(!$?) { exit 1 }
dotnet pack -c Release -p:Version="$packageVersion" -p:Endpoint=$endpoint `
-p:LocalDryRun=$LocalDryRun -p:WarningLevel=$WarningLevel -o $PSScriptRoot/out
if(!$?) { exit 1 }
if (!$LocalDryRun -and $PushTo ) {
$package = "$PSScriptRoot/out/$packageName.$packageVersion.nupkg"
if ($ApiKey -ne '') {
$pushOutput = dotnet nuget push $package `
--source $PushTo --api-key $ApiKey --skip-duplicate | Join-String -Separator "`n"
} else {
$pushOutput = dotnet nuget push $package `
--source $PushTo --skip-duplicate | Join-String -Separator "`n"
}
$pushResult = $?
if($pushOutput -like "*$package*already exists*" ) {
Write-Warning $pushOutput
} else {
$pushOutput
}
if (!$pushResult) { exit 1 }
}
}
Set-Location $PSScriptRoot