-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🩹 [Patch]: Adding GitHub action loader and output + var commands (#119)
## Description - Add detection for module running on GitHub Runners, if so run an initializer. - run loader if `$env:GITHUB_ACTIONS == true`. - Adding commands for creating a step output and setting a GitHub env var, mean to be used while on a GitHub runner. - `Set-GitHubEnvironmentVariable` - `Set-GitHubOutput` ## 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
1 parent
1556473
commit a62bac0
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function Initialize-RunnerEnvironment { | ||
<# | ||
.SYNOPSIS | ||
Initialize the runner environment for the GitHub module | ||
.DESCRIPTION | ||
Initialize the runner environment for the GitHub module | ||
.EXAMPLE | ||
Initialize-RunnerEnvironment | ||
Initializes the runner environment for the GitHub module | ||
#> | ||
[CmdletBinding()] | ||
param () | ||
|
||
Write-Warning 'Detected running on a GitHub Actions runner, preparing environment...' | ||
$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' | ||
Set-GitHubEnv -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function Set-GitHubEnvironmentVariable { | ||
<# | ||
.SYNOPSIS | ||
Set a GitHub environment variable | ||
.DESCRIPTION | ||
Set a GitHub environment variable | ||
.EXAMPLE | ||
Set-GitHubEnv -Name 'MyVariable' -Value 'MyValue' | ||
#> | ||
[OutputType([void])] | ||
[Alias('Set-GitHubEnv')] | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( | ||
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', | ||
Justification = 'Does not change system state significantly' | ||
)] | ||
[CmdletBinding()] | ||
param ( | ||
# Name of the variable | ||
[Parameter(Mandatory)] | ||
[string] $Name, | ||
|
||
# Value of the variable | ||
[Parameter(Mandatory)] | ||
[AllowNull()] | ||
[string] $Value | ||
) | ||
Write-Verbose (@{ $Name = $Value } | Format-Table -Wrap -AutoSize | Out-String) | ||
"$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function Set-GitHubOutput { | ||
<# | ||
.SYNOPSIS | ||
Set a output variable in GitHub Actions | ||
.DESCRIPTION | ||
Set a output variable in GitHub Actions. If the variable is a SecureString, it will be converted to plain text and masked. | ||
.EXAMPLE | ||
Set-GitHubOutput -Name 'MyOutput' -Value 'Hello, World!' | ||
Creates a new output variable named 'MyOutput' with the value 'Hello, World!'. | ||
#> | ||
[OutputType([void])] | ||
[Alias('Output')] | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( | ||
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', | ||
Justification = 'Does not change system state significantly' | ||
)] | ||
[CmdletBinding()] | ||
param ( | ||
# Name of the variable | ||
[Parameter(Mandatory)] | ||
[string] $Name, | ||
|
||
# Value of the variable | ||
[Parameter(Mandatory)] | ||
[AllowNull()] | ||
[object] $Value | ||
) | ||
if ($Value -Is [securestring]) { | ||
$Value = $Value | ConvertFrom-SecureString -AsPlainText -Force | ||
Add-Mask -Value $Value | ||
} | ||
Write-Verbose (@{ $Name = $Value } | Format-Table -Wrap -AutoSize | Out-String) | ||
"$Name=$Value" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | ||
if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { | ||
Write-Warning "Cannot create output as the step has no ID." | ||
} else { | ||
Write-Verbose "Output: [$Name] avaiable as `${{ steps.$env:GITHUB_ACTION.outputs.$Name }}'" | ||
} | ||
} |