forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrite-GitHubWarning.ps1
66 lines (61 loc) · 2.04 KB
/
Write-GitHubWarning.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
function Write-GitHubWarning
{
<#
.Synopsis
Writes an GitHub Warning
.Description
Writes an GitHub Workflow Warning
.Example
Write-GitHubWarning "Stuff hit the fan"
.Link
Write-GitHubError
.Link
https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
#>
[OutputType([string])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "",
Justification="Directly outputs in certain scenarios")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Test-ForUnusableFunction", "",
Justification="Directly outputs in certain scenarios")]
param(
# The Warning message.
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[string]
$Message,
# An optional source path.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Source','SourcePath','FullName')]
[string]
$File,
# An optional line number.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('LineNumber')]
[uint32]
$Line,
# An optional column number.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Column','ColumnNumber')]
[uint32]
$Col
)
begin {
$cmdMd = [Management.Automation.CommandMetaData]$MyInvocation.MyCommand
}
process {
#region Collect Additional Properties
$properties = # Collect the optional properties
@(foreach ($kv in $PSBoundParameters.GetEnumerator()) {
if ('Message' -contains $kv.Key) { continue } # (anything but Message).
if (-not $cmdMd.Parameters.ContainsKey($kv.Key)) { continue }
"$($kv.Key.ToLower())=$($kv.Value)"
}) -join ','
#endregion Collect Additional Properties
# Then output the Warning with it's message.
$out = "::warning$(if ($properties){" $properties"})::$Message"
if ($env:GITHUB_WORKFLOW -and $DebugPreference -eq 'SilentlyContinue') {
Write-Host $out
} else {
$out
}
}
}