Skip to content

Commit 713373e

Browse files
🩹 [Patch]: Add workflow command Add-Mask (#114)
## Description - Added function for `Add-Mask` ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 4783ba1 commit 713373e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/public/Commands/Add-Mask.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
filter Add-Mask {
2+
<#
3+
.SYNOPSIS
4+
Mask a value in GitHub Actions
5+
6+
.DESCRIPTION
7+
Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is
8+
replaced with the * character. You can use an environment variable or string for the mask's value. When you mask a value,
9+
it is treated as a secret and will be redacted on the runner. For example, after you mask a value, you won't be able to
10+
set that value as an output.
11+
12+
.EXAMPLE
13+
Add-Mask $SecretValue
14+
15+
Masks the value of $SecretValue so that its printed like ***.
16+
17+
.EXAMPLE
18+
$SecretValue1, $SecretValue2 | Mask
19+
20+
Masks the value of $SecretValue1 and $SecretValue2 so that its printed like ***, using the pipeline
21+
22+
.NOTES
23+
[Masking a value in a log | GitHub Docs](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#masking-a-value-in-a-log)
24+
#>
25+
[Alias('Mask')]
26+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
27+
'PSAvoidLongLines', '', Scope = 'Function',
28+
Justification = 'Long documentation URL'
29+
)]
30+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
31+
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
32+
Justification = 'Does not change state'
33+
)]
34+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
35+
'PSAvoidUsingWriteHost', '', Scope = 'Function',
36+
Justification = 'Intended for logging in Github Runners which does support Write-Host'
37+
)]
38+
[CmdletBinding()]
39+
param(
40+
# The value to mask
41+
[Parameter(
42+
Mandatory,
43+
ValueFromPipeline
44+
)]
45+
[AllowNull()]
46+
[string[]] $Value
47+
)
48+
49+
foreach ($item in $Value) {
50+
Write-Host "::add-mask::$item"
51+
}
52+
}

0 commit comments

Comments
 (0)