Skip to content

Commit

Permalink
🩹 [Patch]: Add workflow command Add-Mask (#114)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
MariusStorhaug authored Aug 8, 2024
1 parent 4783ba1 commit 713373e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/public/Commands/Add-Mask.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
filter Add-Mask {
<#
.SYNOPSIS
Mask a value in GitHub Actions
.DESCRIPTION
Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is
replaced with the * character. You can use an environment variable or string for the mask's value. When you mask a value,
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
set that value as an output.
.EXAMPLE
Add-Mask $SecretValue
Masks the value of $SecretValue so that its printed like ***.
.EXAMPLE
$SecretValue1, $SecretValue2 | Mask
Masks the value of $SecretValue1 and $SecretValue2 so that its printed like ***, using the pipeline
.NOTES
[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)
#>
[Alias('Mask')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidLongLines', '', Scope = 'Function',
Justification = 'Long documentation URL'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
Justification = 'Does not change state'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '', Scope = 'Function',
Justification = 'Intended for logging in Github Runners which does support Write-Host'
)]
[CmdletBinding()]
param(
# The value to mask
[Parameter(
Mandatory,
ValueFromPipeline
)]
[AllowNull()]
[string[]] $Value
)

foreach ($item in $Value) {
Write-Host "::add-mask::$item"
}
}

0 comments on commit 713373e

Please sign in to comment.