-
Notifications
You must be signed in to change notification settings - Fork 0
/
Publish-GitPub.ps.ps1
77 lines (70 loc) · 2.67 KB
/
Publish-GitPub.ps.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
function Publish-GitPub
{
<#
.SYNOPSIS
Publishes content with GitPub
.DESCRIPTION
Collects content from all valid sources and publishes it with all valid publishers.
.LINK
Get-GitPub
.EXAMPLE
Publish-GitPub
#>
param(
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Parameters')]
$Parameter
)
process {
$gitPub = Get-GitPub
if ($env:GITHUB_WORKSPACE) {
"::group::Publish-GitPub Parameters" | Out-Host
$Parameter | Format-Custom | Out-Host
"::endgroup::" | Out-Host
}
$gitPubSourceInfo =
foreach ($source in $gitPub.Sources) {
if (-not $Parameter.($source.Name)) { continue }
$sourceParamSets = @($Parameter.($source.Name))
foreach ($sourceParam in $sourceParamSets) {
if ($sourceParam -isnot [Collections.IDictionary]) {
$sourceParamDict = [Ordered]@{}
foreach ($prop in $sourceParam.psobject.properties) {
$sourceParamDict[$prop.Name] = $prop.Value
}
$sourceParam = $sourceParamDict
}
try {
& $source @sourceParam
} catch {
$err = $_
Write-Error "Could not run source '$source': $($err.Message)"
}
}
}
$wasPublished = $false
foreach ($publisher in $gitPub.Publishers) {
if (-not ($Parameter.$($publisher.Name))) { continue }
$publishParamSets = @($Parameter.($publisher.Name))
foreach ($publishParam in $publishParamSets) {
if ($publishParam -isnot [Collections.IDictionary]) {
$publishParamDict = [Ordered]@{}
foreach ($prop in $publishParam.psobject.properties) {
$publishParamDict[$prop.Name] = $prop.Value
}
$publishParam = $publishParamDict
}
$wasPublished = $true
try {
$gitPubSourceInfo | & $publisher @publishParam
} catch {
$err = $_
Write-Error "Could not run publisher '$publisher': $($err.Message) @ $($err.ScriptStackTrace)"
}
}
}
if (-not $wasPublished) {
Write-Error "No parameters were provided to publishers"
}
}
}