|
1 |
| -function Test-SupportsDevOpsLogging() |
2 |
| -{ |
3 |
| - return ($null -ne $env:SYSTEM_TEAMPROJECTID) |
| 1 | +function Test-SupportsDevOpsLogging() { |
| 2 | + return ($null -ne $env:SYSTEM_TEAMPROJECTID) |
4 | 3 | }
|
5 | 4 |
|
6 |
| -function LogWarning |
7 |
| -{ |
8 |
| - if (Test-SupportsDevOpsLogging) |
9 |
| - { |
10 |
| - Write-Host "##vso[task.LogIssue type=warning;]$args" |
11 |
| - } |
12 |
| - else |
13 |
| - { |
14 |
| - Write-Warning "$args" |
15 |
| - } |
| 5 | +function Test-SupportsGitHubLogging() { |
| 6 | + return ($null -ne $env:GITHUB_ACTIONS) |
16 | 7 | }
|
17 | 8 |
|
18 |
| -function LogError |
19 |
| -{ |
20 |
| - if (Test-SupportsDevOpsLogging) |
21 |
| - { |
22 |
| - Write-Host "##vso[task.LogIssue type=error;]$args" |
23 |
| - } |
24 |
| - else |
25 |
| - { |
26 |
| - Write-Error "$args" |
27 |
| - } |
| 9 | +function LogInfo { |
| 10 | + Write-Host "$args" |
| 11 | +} |
| 12 | + |
| 13 | +function LogWarning { |
| 14 | + if (Test-SupportsDevOpsLogging) { |
| 15 | + Write-Host ("##vso[task.LogIssue type=warning;]$args" -replace "`n", "%0D%0A") |
| 16 | + } |
| 17 | + elseif (Test-SupportsGitHubLogging) { |
| 18 | + Write-Warning ("::warning::$args" -replace "`n", "%0D%0A") |
| 19 | + } |
| 20 | + else { |
| 21 | + Write-Warning "$args" |
| 22 | + } |
28 | 23 | }
|
29 | 24 |
|
30 |
| -function LogDebug |
| 25 | +function LogSuccess { |
| 26 | + $esc = [char]27 |
| 27 | + $green = "${esc}[32m" |
| 28 | + $reset = "${esc}[0m" |
| 29 | + |
| 30 | + Write-Host "${green}$args${reset}" |
| 31 | +} |
| 32 | + |
| 33 | +function LogErrorForFile($file, $errorString) |
31 | 34 | {
|
32 |
| - if (Test-SupportsDevOpsLogging) |
33 |
| - { |
34 |
| - Write-Host "[debug]$args" |
35 |
| - } |
36 |
| - else |
37 |
| - { |
38 |
| - Write-Debug "$args" |
39 |
| - } |
| 35 | + if (Test-SupportsDevOpsLogging) { |
| 36 | + Write-Host ("##vso[task.logissue type=error;sourcepath=$file;linenumber=1;columnnumber=1;]$errorString" -replace "`n", "%0D%0A") |
| 37 | + } |
| 38 | + elseif (Test-SupportsGitHubLogging) { |
| 39 | + Write-Error ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A") |
| 40 | + } |
| 41 | + else { |
| 42 | + Write-Error "[Error in file $file]$errorString" |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function LogError { |
| 47 | + if (Test-SupportsDevOpsLogging) { |
| 48 | + Write-Host ("##vso[task.LogIssue type=error;]$args" -replace "`n", "%0D%0A") |
| 49 | + } |
| 50 | + elseif (Test-SupportsGitHubLogging) { |
| 51 | + Write-Error ("::error::$args" -replace "`n", "%0D%0A") |
| 52 | + } |
| 53 | + else { |
| 54 | + Write-Error "$args" |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +function LogDebug { |
| 59 | + if (Test-SupportsDevOpsLogging) { |
| 60 | + Write-Host "[debug]$args" |
| 61 | + } |
| 62 | + elseif (Test-SupportsGitHubLogging) { |
| 63 | + Write-Debug "::debug::$args" |
| 64 | + } |
| 65 | + else { |
| 66 | + Write-Debug "$args" |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function LogGroupStart() { |
| 71 | + if (Test-SupportsDevOpsLogging) { |
| 72 | + Write-Host "##[group]$args" |
| 73 | + } |
| 74 | + elseif (Test-SupportsGitHubLogging) { |
| 75 | + Write-Host "::group::$args" |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +function LogGroupEnd() { |
| 80 | + if (Test-SupportsDevOpsLogging) { |
| 81 | + Write-Host "##[endgroup]" |
| 82 | + } |
| 83 | + elseif (Test-SupportsGitHubLogging) { |
| 84 | + Write-Host "::endgroup::" |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +function LogJobFailure() { |
| 89 | + if (Test-SupportsDevOpsLogging) { |
| 90 | + Write-Host "##vso[task.complete result=Failed;]" |
| 91 | + } |
| 92 | + # No equivalent for GitHub Actions. Failure is only determined by nonzero exit code. |
40 | 93 | }
|
0 commit comments