Skip to content

Commit 3a0e536

Browse files
authored
Merge pull request #760 from jonsequitur/fix-ymls-8
add more yml templates
2 parents 8a0fc23 + 0ab12e7 commit 3a0e536

8 files changed

+724
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
param(
2+
[string] $token
3+
)
4+
5+
. $PSScriptRoot\pipeline-logging-functions.ps1
6+
7+
Write-PipelineSetVariable -Name 'VSS_NUGET_ACCESSTOKEN' -Value $token
8+
Write-PipelineSetVariable -Name 'VSS_NUGET_URI_PREFIXES' -Value 'https://dnceng.pkgs.visualstudio.com/;https://pkgs.dev.azure.com/dnceng/;https://devdiv.pkgs.visualstudio.com/;https://pkgs.dev.azure.com/devdiv/'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
param(
2+
[Parameter(Mandatory=$true)][int] $BarBuildId, # ID of the build which assets should be downloaded
3+
[Parameter(Mandatory=$true)][string] $DropLocation, # Where the assets should be downloaded to
4+
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken, # Token used to access Maestro API
5+
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com', # Maestro API URL
6+
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16' # Version of Maestro API to use
7+
)
8+
9+
try {
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
Write-Host 'Installing DARC ...'
13+
14+
. $PSScriptRoot\..\darc-init.ps1
15+
$exitCode = $LASTEXITCODE
16+
17+
if ($exitCode -ne 0) {
18+
Write-PipelineTelemetryError -Category "Darc" -Message "Something failed while running 'darc-init.ps1'. Check for errors above. Exiting now..."
19+
ExitWithExitCode $exitCode
20+
}
21+
22+
# For now, only use a dry run.
23+
# Ideally we would change darc to enable a quick request that
24+
# would check whether the file exists that you can download it,
25+
# and that it won't conflict with other files.
26+
# https://github.com/dotnet/arcade/issues/3674
27+
# Right now we can't remove continue-on-error because we ocassionally will have
28+
# dependencies that have no associated builds (e.g. an old dependency).
29+
# We need to add an option to baseline specific dependencies away, or add them manually
30+
# to the BAR.
31+
darc gather-drop --non-shipping `
32+
--dry-run `
33+
--continue-on-error `
34+
--id $BarBuildId `
35+
--output-dir $DropLocation `
36+
--bar-uri $MaestroApiEndpoint `
37+
--password $MaestroApiAccessToken `
38+
--latest-location
39+
}
40+
catch {
41+
Write-Host $_.ScriptStackTrace
42+
Write-PipelineTelemetryError -Category "Darc" -Message $_
43+
ExitWithExitCode 1
44+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This script validates NuGet package metadata information using this
2+
# tool: https://github.com/NuGet/NuGetGallery/tree/jver-verify/src/VerifyMicrosoftPackage
3+
4+
param(
5+
[Parameter(Mandatory=$true)][string] $PackagesPath, # Path to where the packages to be validated are
6+
[Parameter(Mandatory=$true)][string] $ToolDestinationPath # Where the validation tool should be downloaded to
7+
)
8+
9+
try {
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
$url = 'https://raw.githubusercontent.com/NuGet/NuGetGallery/jver-verify/src/VerifyMicrosoftPackage/verify.ps1'
13+
14+
New-Item -ItemType 'directory' -Path ${ToolDestinationPath} -Force
15+
16+
Invoke-WebRequest $url -OutFile ${ToolDestinationPath}\verify.ps1
17+
18+
& ${ToolDestinationPath}\verify.ps1 ${PackagesPath}\*.nupkg
19+
}
20+
catch {
21+
Write-Host $_.ScriptStackTrace
22+
Write-PipelineTelemetryError -Category 'NuGetValidation' -Message $_
23+
ExitWithExitCode 1
24+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Most of the functions in this file require the variables `MaestroApiEndPoint`,
2+
# `MaestroApiVersion` and `MaestroApiAccessToken` to be globally available.
3+
4+
$ErrorActionPreference = 'Stop'
5+
Set-StrictMode -Version 2.0
6+
7+
# `tools.ps1` checks $ci to perform some actions. Since the post-build
8+
# scripts don't necessarily execute in the same agent that run the
9+
# build.ps1/sh script this variable isn't automatically set.
10+
$ci = $true
11+
$disableConfigureToolsetImport = $true
12+
. $PSScriptRoot\..\tools.ps1
13+
14+
function Create-MaestroApiRequestHeaders([string]$ContentType = 'application/json') {
15+
Validate-MaestroVars
16+
17+
$headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
18+
$headers.Add('Accept', $ContentType)
19+
$headers.Add('Authorization',"Bearer $MaestroApiAccessToken")
20+
return $headers
21+
}
22+
23+
function Get-MaestroChannel([int]$ChannelId) {
24+
Validate-MaestroVars
25+
26+
$apiHeaders = Create-MaestroApiRequestHeaders
27+
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}?api-version=$MaestroApiVersion"
28+
29+
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
30+
return $result
31+
}
32+
33+
function Get-MaestroBuild([int]$BuildId) {
34+
Validate-MaestroVars
35+
36+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
37+
$apiEndpoint = "$MaestroApiEndPoint/api/builds/${BuildId}?api-version=$MaestroApiVersion"
38+
39+
$result = try { return Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
40+
return $result
41+
}
42+
43+
function Get-MaestroSubscriptions([string]$SourceRepository, [int]$ChannelId) {
44+
Validate-MaestroVars
45+
46+
$SourceRepository = [System.Web.HttpUtility]::UrlEncode($SourceRepository)
47+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
48+
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions?sourceRepository=$SourceRepository&channelId=$ChannelId&api-version=$MaestroApiVersion"
49+
50+
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" }
51+
return $result
52+
}
53+
54+
function Assign-BuildToChannel([int]$BuildId, [int]$ChannelId) {
55+
Validate-MaestroVars
56+
57+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
58+
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}/builds/${BuildId}?api-version=$MaestroApiVersion"
59+
Invoke-WebRequest -Method Post -Uri $apiEndpoint -Headers $apiHeaders | Out-Null
60+
}
61+
62+
function Trigger-Subscription([string]$SubscriptionId) {
63+
Validate-MaestroVars
64+
65+
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken
66+
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions/$SubscriptionId/trigger?api-version=$MaestroApiVersion"
67+
Invoke-WebRequest -Uri $apiEndpoint -Headers $apiHeaders -Method Post | Out-Null
68+
}
69+
70+
function Validate-MaestroVars {
71+
try {
72+
Get-Variable MaestroApiEndPoint -Scope Global | Out-Null
73+
Get-Variable MaestroApiVersion -Scope Global | Out-Null
74+
Get-Variable MaestroApiAccessToken -Scope Global | Out-Null
75+
76+
if (!($MaestroApiEndPoint -Match '^http[s]?://maestro-(int|prod).westus2.cloudapp.azure.com$')) {
77+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiEndPoint is not a valid Maestro URL. '$MaestroApiEndPoint'"
78+
ExitWithExitCode 1
79+
}
80+
81+
if (!($MaestroApiVersion -Match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$')) {
82+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiVersion does not match a version string in the format yyyy-MM-DD. '$MaestroApiVersion'"
83+
ExitWithExitCode 1
84+
}
85+
}
86+
catch {
87+
Write-PipelineTelemetryError -Category 'MaestroVars' -Message 'Error: Variables `MaestroApiEndPoint`, `MaestroApiVersion` and `MaestroApiAccessToken` are required while using this script.'
88+
Write-Host $_
89+
ExitWithExitCode 1
90+
}
91+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
param(
2+
[Parameter(Mandatory=$true)][int] $BuildId,
3+
[Parameter(Mandatory=$true)][int] $ChannelId,
4+
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken,
5+
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com',
6+
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16'
7+
)
8+
9+
try {
10+
. $PSScriptRoot\post-build-utils.ps1
11+
12+
# Check that the channel we are going to promote the build to exist
13+
$channelInfo = Get-MaestroChannel -ChannelId $ChannelId
14+
15+
if (!$channelInfo) {
16+
Write-PipelineTelemetryCategory -Category 'PromoteBuild' -Message "Channel with BAR ID $ChannelId was not found in BAR!"
17+
ExitWithExitCode 1
18+
}
19+
20+
# Get info about which channels the build has already been promoted to
21+
$buildInfo = Get-MaestroBuild -BuildId $BuildId
22+
23+
if (!$buildInfo) {
24+
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "Build with BAR ID $BuildId was not found in BAR!"
25+
ExitWithExitCode 1
26+
}
27+
28+
# Find whether the build is already assigned to the channel or not
29+
if ($buildInfo.channels) {
30+
foreach ($channel in $buildInfo.channels) {
31+
if ($channel.Id -eq $ChannelId) {
32+
Write-Host "The build with BAR ID $BuildId is already on channel $ChannelId!"
33+
ExitWithExitCode 0
34+
}
35+
}
36+
}
37+
38+
Write-Host "Promoting build '$BuildId' to channel '$ChannelId'."
39+
40+
Assign-BuildToChannel -BuildId $BuildId -ChannelId $ChannelId
41+
42+
Write-Host 'done.'
43+
}
44+
catch {
45+
Write-Host $_
46+
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to promote build '$BuildId' to channel '$ChannelId'"
47+
ExitWithExitCode 1
48+
}

0 commit comments

Comments
 (0)