forked from nanoframework/nf-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-dependents.yml
82 lines (69 loc) · 2.93 KB
/
update-dependents.yml
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
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
parameters:
- name: repositoriesToUpdate
type: string
default: ''
- name: waitBeforeUpdate
type: boolean
default: false
steps:
- task: PowerShell@2
displayName: Update dependent class libs
condition: >-
and(
succeeded(),
ne(variables['StartReleaseCandidate'], 'true'),
or(
startsWith(variables['Build.SourceBranch'], 'refs/heads/main'),
contains(variables['GetCommitDetails.COMMIT_MESSAGE'], '***UPDATE_DEPENDENTS***'),
eq(variables['UPDATE_DEPENDENTS'], 'true')
)
)
env:
REPOS_TO_UPDATE: ${{ parameters.repositoriesToUpdate }}
GITHUB_TOKEN: $(GitHubToken)
WAIT_BEFORE_UPDATE: ${{ parameters.waitBeforeUpdate }}
inputs:
targetType: 'inline'
script: |
if ($env:WAIT_BEFORE_UPDATE -eq "true")
{
# wait 15 minutes to allow nuget package to go through validation and indexing
'Waiting 15 minutes to allow package indexing...' | Write-Host -ForegroundColor Yellow
Start-Sleep -Seconds (15 * 60)
}
$librariesToUpdate = $env:REPOS_TO_UPDATE.Split([environment]::NewLine)
ForEach($library in $librariesToUpdate)
{
# remove quotes, if any
$library = $library -replace "'", ""
"" | Write-Host
"*******************************" | Write-Host
"Updating '$library'" | Write-Host
$requestContent = @{event_type="update-dependencies"} | ConvertTo-Json
$requestUrl = "https://api.github.com/repos/nanoframework/$library/dispatches"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# compute authorization header in format "AUTHORIZATION: Bearer <YOUR-TOKEN>"
$auth = "Bearer $(GitHubToken)"
$headers = @{}
$headers.Add("Authorization","$auth")
$headers.Add("Accept","application/vnd.github.v3+json")
try
{
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $requestUrl -Header $headers -ContentType "application/json" -Body $requestContent
'Triggering GitHub Action to update dependencies...' | Write-Host -NoNewline
'OK' | Write-Host -ForegroundColor Green
# give some slack for the next action to start the decrease the likelihood of hitting the GitHub API rate limit
Start-Sleep -Seconds (63)
}
catch
{
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
throw "Error firing GitHub action: $responseBody"
}
}