-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ps1
More file actions
41 lines (35 loc) · 1.79 KB
/
main.ps1
File metadata and controls
41 lines (35 loc) · 1.79 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
[CmdletBinding(DefaultParameterSetName = 'WorkflowID')]
param(
# The ID of the workflow to get the run for.
[Parameter()]
[string] $WorkflowID = $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowID,
# The ID of the workflow run to verify.
[Parameter()]
[string] $WorkflowRunID = $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_WorkflowRunID
)
if ($WorkflowRunID) {
Write-Output '::group::Verify Workflow Run'
gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' "/repos/$env:GITHUB_REPOSITORY/actions/runs/$WorkflowRunID"
Write-Output '::endgroup::'
} else {
Write-Output '::group::Get PR'
$PR = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
"/repos/$env:GITHUB_REPOSITORY/commits/$env:GITHUB_SHA/pulls" | ConvertFrom-Json
$PR | ConvertTo-Json -Depth 100
if ($PR.Count -ne 1) {
throw "Expected 1 PR, but found [$($PR.Count)]."
}
Write-Output '::endgroup::'
Write-Output '::group::Get WorkflowRun'
$WorkflowRuns = gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' `
"/repos/$env:GITHUB_REPOSITORY/actions/workflows/$WorkflowID/runs?head_sha=$($PR.head.sha)" |
ConvertFrom-Json | Select-Object -ExpandProperty workflow_runs
$WorkflowRuns | ConvertTo-Json -Depth 100
$WorkflowRunID = $WorkflowRuns.id
Write-Output '::endgroup::'
}
Write-Output "Workflow Run ID: [$WorkflowRunID]"
"RunID=$WorkflowRunID" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
$path = [string]::IsNullOrEmpty($env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_Path) ? '.' : $env:PSMODULE_DOWNLOAD_CIARTIFACT_INPUT_Path
$path = Resolve-Path -Path $path | Select-Object -ExpandProperty Path
"Path=$path" | Out-File -FilePath $env:GITHUB_OUTPUT -Append