-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithub-builder.psm1
More file actions
166 lines (136 loc) · 4.34 KB
/
github-builder.psm1
File metadata and controls
166 lines (136 loc) · 4.34 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
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
166
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
#requires -version 7
$ErrorActionPreference = "Stop"
<#
.DESCRIPTION
Builds a pre-release version number based on the last tag in the commit history
and the number of commits since then.
#>
function Get-VersionNumber {
$prefix = "v"
# Install the MinVer CLI tool
&dotnet tool install --global minver-cli
$version = $(&minver -t $prefix)
"appcommon-v=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"appcommon-semver=$($version -Replace $prefix)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
}
<#
.DESCRIPTION
Builds the EdFi.DataManagementService NuGet package.
#>
function Invoke-DotnetPack {
[CmdletBinding()]
param (
# Package version number
[string]
[Parameter(Mandatory = $true)]
$Version
)
&dotnet pack -p:PackageVersion=$Version -o ./
}
<#
.DESCRIPTION
PUblishes any local NuGet packages to the given feed.
#>
function Invoke-NuGetPush {
[CmdletBinding()]
param (
# NuGet package feed / source
[string]
[Parameter(Mandatory = $true)]
$NuGetFeed,
# API key for authentication
[string]
[Parameter(Mandatory = $true)]
$NuGetApiKey
)
(Get-ChildItem -Path $_ -Name -Include *.nupkg) | ForEach-Object {
&dotnet nuget push $_ --api-key $NuGetApiKey --source $NuGetFeed
}
}
<#
.DESCRIPTION
Retrieves a list package versions previously published to Azure Artifacts.
#>
function Get-PackagesFromAzure {
param(
# Array of packages to look up
[Parameter(Mandatory=$true)]
[String[]]
$Packages
)
$uri = "$FeedsURL/packages?api-version=6.0-preview.1"
$result = @{ }
foreach ($packageName in $Packages) {
$packageQueryUrl = "$uri&packageNameQuery=$packageName"
$packagesResponse = (Invoke-WebRequest -Uri $packageQueryUrl -UseBasicParsing).Content | ConvertFrom-Json
$latestPackageVersion = ($packagesResponse.value.versions | Where-Object { $_.isLatest -eq $True } | Select-Object -ExpandProperty version)
Write-Host "Package Name: $packageName"
Write-Host "Package Version: $latestPackageVersion"
$result.add(
$packageName.ToLower().Trim(),
$latestPackageVersion
)
}
return $result
}
<#
.DESCRIPTION
Promotes a package in Azure Artifacts to a view, e.g. pre-release or release.
#>
function Invoke-Promote {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'False positive')]
param(
# NuGet package feed / source
[Parameter(Mandatory = $true)]
[String]
$FeedsURL,
# NuGet Packages API URL
[Parameter(Mandatory = $true)]
[String]
$PackagesURL,
# Azure Artifacts user name
[Parameter(Mandatory = $true)]
[String]
$Username,
# Azure Artifacts password
[Parameter(Mandatory = $true)]
[SecureString]
$Password,
# View to promote into
[Parameter(Mandatory = $true)]
[String]
$View
)
$body = @{
data = @{
viewId = $View
}
operation = 0
packages = @()
}
$latestPackages = Get-PackagesFromAzure -Packages "EdFi.Installer.AppCommon"
foreach ($key in $latestPackages.Keys) {
$body.packages += @{
id = $key
version = $latestPackages[$key]
protocolType = "NuGet"
}
}
$parameters = @{
Method = "POST"
ContentType = "application/json"
Credential = New-Object -TypeName PSCredential -ArgumentList $Username, $Password
URI = "$PackagesURL/nuget/packagesBatch?api-version=5.0-preview.1"
Body = ConvertTo-Json $Body -Depth 10
}
$parameters | Out-Host
$parameters.URI | Out-Host
$parameters.Body | Out-Host
$response = Invoke-WebRequest @parameters -UseBasicParsing
$response | ConvertTo-Json -Depth 10 | Out-Host
}
Export-ModuleMember -Function Get-VersionNumber, Invoke-DotnetPack, Invoke-NuGetPush, Invoke-Promote