Skip to content

Commit 3750876

Browse files
committed
20230322A
1 parent e2a52af commit 3750876

File tree

17 files changed

+87
-923
lines changed

17 files changed

+87
-923
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ body:
1818
description: "What versions are affected? Versions must be listed as supported in the Security Policy (file: `SECURITY.md`)."
1919
multiple: true
2020
options:
21+
- "v1.4.0"
2122
- "v1.3.2"
2223
- "v1.3.1"
2324
- "v1.3.0"

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ For the full documentation, please visit the [GitHub Repository Wiki](https://gi
2727

2828
#### Install
2929

30-
- PowerShell >= v7.2.0
31-
- NodeJS >= v14.15.0 (only for NodeJS wrapper API)
32-
- NPM >= v6.14.8 (only for NodeJS wrapper API)
30+
- GitHub Actions Runner >= v2.303.0
31+
- PowerShell >= v7.2.0
32+
- NodeJS >= v14.15.0 (only for NodeJS wrapper API)
33+
- NPM >= v6.14.8 (only for NodeJS wrapper API) **\***
34+
35+
**\*:** Only apply to some of the versions, please visit "Supported Versions" in the Security Policy (file: `SECURITY.md`).
3336

3437
```ps1
3538
Install-Module -Name 'hugoalh.GitHubActionsToolkit' -AcceptLicense

SECURITY.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
> | ❌{🐛} | **No (Issue):** Not supported due to confirmed contains bugs and/or issues. |
1212
> | ❌{🧓} | **No (Old):** Not supported due to too old. |
1313
14-
| **Versions** | **Status** | **Target - PowerShell** | **Target - NodeJS (Wrapper API)** | **Target - NPM (Wrapper API)** |
15-
|:-:|:-:|:-:|:-:|:-:|
16-
| v1.3.X | L | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
17-
| v1.3.0 \~ v1.3.1 | 👎{🐛} | >= v7.2.0 | >= v14.15.0 | *N/A* |
18-
| v1.2.X | 👎{🐛} | >= v7.2.0 | >= v14.15.0 | *N/A* |
19-
| v1.1.X | 👎{🐛} | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
20-
| v1.1.0 | ❌{🐛} | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
21-
| v1.0.X | ❌{🐛🧓} | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
22-
| v1.0.0 | ❌{🐛🧓} | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
23-
| v0.X.X | ❌{🐛🧓} | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
14+
| **Versions** | **Status** | **Target - GitHub Actions Runner** | **Target - PowerShell** | **Target - NodeJS (Wrapper API)** | **Target - NPM (Wrapper API)** |
15+
|:-:|:-:|:-:|:-:|:-:|:-:|
16+
| v1.4.X | L | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 | *N/A* |
17+
| v1.3.X | 👎{🐛🧓} | *N/A* | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
18+
| v1.3.0 \~ v1.3.1 | 👎{🐛🧓} | *N/A* | >= v7.2.0 | >= v14.15.0 | *N/A* |
19+
| v1.2.X | 👎{🐛🧓} | *N/A* | >= v7.2.0 | >= v14.15.0 | *N/A* |
20+
| v1.1.X | 👎{🐛🧓} | *N/A* | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
21+
| <= v1.1.0 | ❌{🐛🧓} | *N/A* | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |
2422

2523
## Report Vulnerability
2624

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'hugoalh.GitHubActionsToolkit.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.3.2'
6+
ModuleVersion = '1.4.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = @()
@@ -70,7 +70,6 @@
7070
'Add-StepSummaryLink',
7171
'Add-StepSummarySubscriptText',
7272
'Add-StepSummarySuperscriptText',
73-
'Clear-FileCommand',
7473
'Disable-EchoingCommands',
7574
'Disable-ProcessingCommands',
7675
'Enable-EchoingCommands',

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ Import-Module -Name (
77
) -Prefix 'GitHubActions' -Scope 'Local'
88
<#
99
.SYNOPSIS
10-
GitHub Actions - Clear File Command
11-
.DESCRIPTION
12-
Clear the file commands.
13-
.OUTPUTS
14-
[Void]
15-
#>
16-
Function Clear-FileCommand {# Deprecated, keep as legacy.
17-
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_cleargithubactionsfilecommand')]
18-
[OutputType([Void])]
19-
Param (
20-
[Parameter(Position = 0)][Alias('Types')]$Type
21-
)
22-
}
23-
<#
24-
.SYNOPSIS
2510
GitHub Actions - Format Command Parameter Value
2611
.DESCRIPTION
2712
Format the command parameter value characters that can cause issues.
@@ -127,7 +112,7 @@ Function Write-FileCommand {
127112
Do {
128113
[String]$Token = New-GitHubActionsRandomToken
129114
}
130-
While ( $ItemRaw -imatch [RegEx]::Escape($Token) )
115+
While ($ItemRaw -imatch [RegEx]::Escape($Token))
131116
@(
132117
"$Name<<$Token",
133118
($Value -ireplace '\r?\n', "`n"),
@@ -138,7 +123,6 @@ Function Write-FileCommand {
138123
}
139124
}
140125
Export-ModuleMember -Function @(
141-
'Clear-FileCommand',
142126
'Write-Command',
143127
'Write-FileCommand'
144128
)

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Function Add-PATH {
3232
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('NoValidate', 'SkipValidate', 'SkipValidator')][Switch]$NoValidator,
3333
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Scopes')][GitHubActionsEnvironmentVariableScopes]$Scope = [GitHubActionsEnvironmentVariableScopes]3
3434
)
35-
Begin {
36-
[Boolean]$UseLegacyMethod = [String]::IsNullOrWhiteSpace($Env:GITHUB_PATH)
37-
}
3835
Process {
3936
ForEach ($Item In (
4037
$Path |
@@ -48,12 +45,7 @@ Function Add-PATH {
4845
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$Item" -Confirm:$False -NoNewLine
4946
}
5047
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
51-
If ($UseLegacyMethod) {
52-
Write-GitHubActionsCommand -Command 'add-path' -Value $Item
53-
}
54-
Else {
55-
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
56-
}
48+
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
5749
}
5850
}
5951
}
@@ -86,9 +78,6 @@ Function Set-EnvironmentVariable {
8678
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('NoToUpperCase')][Switch]$NoToUpper,
8779
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Scopes')][GitHubActionsEnvironmentVariableScopes]$Scope = [GitHubActionsEnvironmentVariableScopes]3
8880
)
89-
Begin {
90-
[Boolean]$UseLegacyMethod = [String]::IsNullOrWhiteSpace($Env:GITHUB_ENV)
91-
}
9281
Process {
9382
If ($PSCmdlet.ParameterSetName -ieq 'Multiple') {
9483
If (
@@ -107,12 +96,7 @@ Function Set-EnvironmentVariable {
10796
$Null = [System.Environment]::SetEnvironmentVariable($Name, $Value)
10897
}
10998
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
110-
If ($UseLegacyMethod) {
111-
Write-GitHubActionsCommand -Command 'set-env' -Parameter @{ 'name' = $Name } -Value $Value
112-
}
113-
Else {
114-
Write-GitHubActionsFileCommand -LiteralPath $Env:GITHUB_ENV -Name $Name -Value $Value
115-
}
99+
Write-GitHubActionsFileCommand -LiteralPath $Env:GITHUB_ENV -Name $Name -Value $Value
116100
}
117101
}
118102
}

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper.psm1

Lines changed: 15 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ Import-Module -Name (
66
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
77
) -Prefix 'GitHubActions' -Scope 'Local'
88
[SemVer]$NodeJsMinimumVersion = [SemVer]::Parse('14.15.0')
9-
[SemVer]$NpmMinimumVersion = [SemVer]::Parse('6.14.8')
10-
[SemVer]$PnpmMinimumVersion = [SemVer]::Parse('7.28.0')
119
[RegEx]$SemVerRegEx = 'v?\d+\.\d+\.\d+'
1210
[String]$WrapperRoot = Join-Path -Path $PSScriptRoot -ChildPath 'nodejs-wrapper'
1311
[String]$WrapperPackageFilePath = Join-Path -Path $WrapperRoot -ChildPath 'package.json'
14-
[String]$WrapperPackageLockFilePath = Join-Path -Path $WrapperRoot -ChildPath 'pnpm-lock.yaml'
15-
[String]$WrapperBundledFilePath = Join-Path -Path $WrapperRoot -ChildPath 'bundled.js'
16-
[String]$WrapperUnbundledFilePath = Join-Path -Path $WrapperRoot -ChildPath 'unbundled.js'
12+
[String]$WrapperScriptFilePath = Join-Path -Path $WrapperRoot -ChildPath 'main.js'
1713
[Boolean]$EnvironmentTested = $False
1814
[Boolean]$EnvironmentResult = $False
19-
[Boolean]$DependenciesTested = $False
20-
[Boolean]$DependenciesResult = $False
2115
<#
2216
.SYNOPSIS
2317
GitHub Actions - Internal - Convert From Base64 String To Utf8 String
@@ -58,89 +52,6 @@ Function Convert-FromUtf8StringToBase64String {
5852
}
5953
<#
6054
.SYNOPSIS
61-
GitHub Actions - Internal - Install NodeJS Dependencies
62-
.DESCRIPTION
63-
Use to install NodeJS wrapper API dependencies when bundled wrapper failed and retry with unbundled wrapper.
64-
.OUTPUTS
65-
[Boolean] Test result.
66-
#>
67-
Function Install-NodeJsDependencies {
68-
[CmdletBinding()]
69-
[OutputType([Boolean])]
70-
Param ()
71-
If ($DependenciesTested) {
72-
Write-Output -InputObject $DependenciesResult
73-
Return
74-
}
75-
Try {
76-
Try {
77-
$Null = Get-Command -Name 'npm' -CommandType 'Application' -ErrorAction 'Stop'# `Get-Command` will throw error when nothing is found.
78-
}
79-
Catch {
80-
Throw 'Unable to find NPM!'
81-
}
82-
Try {
83-
[String]$NpmVersionStdOut = npm --version |
84-
Join-String -Separator "`n"
85-
If (
86-
$NpmVersionStdOut -inotmatch $SemVerRegEx -or
87-
$NpmMinimumVersion -igt [SemVer]::Parse(($Matches[0] -ireplace '^v', ''))
88-
) {
89-
Throw
90-
}
91-
}
92-
Catch {
93-
Throw 'NPM is not match the requirement!'
94-
}
95-
Try {
96-
$Null = Get-Command -Name 'pnpm' -CommandType 'Application' -ErrorAction 'Stop'# `Get-Command` will throw error when nothing is found.
97-
[String]$PnpmVersionStdOut = pnpm --version |
98-
Join-String -Separator "`n"
99-
If (
100-
$PnpmVersionStdOut -inotmatch $SemVerRegEx -or
101-
$PnpmMinimumVersion -igt [SemVer]::Parse(($Matches[0] -ireplace '^v', ''))
102-
) {
103-
Throw
104-
}
105-
}
106-
Catch {
107-
Try {
108-
$Null = npm install --global pnpm@latest
109-
}
110-
Catch {
111-
Throw 'Unable to install PNPM!'
112-
}
113-
}
114-
Try {
115-
$CurrentWorkingRoot = Get-Location
116-
$Null = Set-Location -LiteralPath $WrapperRoot
117-
Try {
118-
$Null = pnpm install
119-
}
120-
Catch {
121-
Throw 'Unable to install NodeJS wrapper API dependencies!'
122-
}
123-
Finally {
124-
Set-Location -LiteralPath $CurrentWorkingRoot.Path
125-
}
126-
}
127-
Catch {
128-
Throw $_
129-
}
130-
}
131-
Catch {
132-
Write-Verbose -Message $_
133-
$Script:DependenciesTested = $True
134-
$Script:DependenciesResult = $False
135-
Write-Output -InputObject $DependenciesResult
136-
Return
137-
}
138-
$Script:DependenciesTested = $True
139-
$Script:DependenciesResult = $True
140-
Write-Output -InputObject $DependenciesResult
141-
}
142-
<#
143-
.SYNOPSIS
14455
GitHub Actions - Invoke NodeJS Wrapper
14556
.DESCRIPTION
14657
Invoke NodeJS wrapper.
@@ -157,29 +68,26 @@ Function Invoke-NodeJsWrapper {
15768
[OutputType(([PSCustomObject], [PSCustomObject[]]))]
15869
Param (
15970
[Parameter(Mandatory = $True, Position = 0)][String]$Name,
160-
[Parameter(Mandatory = $True, Position = 1)][Alias('Arguments')][Hashtable]$Argument,
161-
[Alias('Debug')][Switch]$LocalDebug
71+
[Parameter(Mandatory = $True, Position = 1)][Alias('Arguments')][Hashtable]$Argument
16272
)
163-
If (!$LocalDebug.IsPresent) {
164-
If (!(Test-NodeJsEnvironment)) {
165-
Write-Error -Message 'This function depends and requires to invoke with the compatible NodeJS environment!' -Category 'ResourceUnavailable'
166-
Return
167-
}
73+
If (!(Test-NodeJsEnvironment)) {
74+
Write-Error -Message 'This function depends and requires to invoke with the compatible NodeJS environment!' -Category 'ResourceUnavailable'
75+
Return
16876
}
169-
ForEach ($Item In @($WrapperPackageFilePath, $WrapperPackageLockFilePath, $WrapperBundledFilePath, $WrapperUnbundledFilePath)) {
77+
ForEach ($Item In @($WrapperPackageFilePath, $WrapperScriptFilePath)) {
17078
If (!(Test-Path -LiteralPath $Item -PathType 'Leaf')) {
171-
Write-Error -Message "Wrapper resource `"$Item`" is missing!" -Category 'ResourceUnavailable'
79+
Write-Error -Message "Unable to invoke NodeJS wrapper: Wrapper resource `"$Item`" is missing!" -Category 'ResourceUnavailable'
17280
Return
17381
}
17482
}
175-
[String]$ResultSeparator = "=====$(New-GitHubActionsRandomToken)====="
176-
[String]$Base64Name = Convert-FromUtf8StringToBase64String -InputObject $Name
177-
[String]$Base64Argument = $Argument |
178-
ConvertTo-Json -Depth 100 -Compress |
179-
Convert-FromUtf8StringToBase64String
180-
[String]$Base64ResultSeparator = Convert-FromUtf8StringToBase64String -InputObject $ResultSeparator
18183
Try {
182-
[String[]]$Result = Invoke-Expression -Command "node --no-deprecation --no-warnings `"$WrapperBundledFilePath`" $Base64Name $Base64Argument $Base64ResultSeparator"
84+
[String]$ResultSeparator = "=====$(New-GitHubActionsRandomToken)====="
85+
[String]$Base64Name = Convert-FromUtf8StringToBase64String -InputObject $Name
86+
[String]$Base64Argument = $Argument |
87+
ConvertTo-Json -Depth 100 -Compress |
88+
Convert-FromUtf8StringToBase64String
89+
[String]$Base64ResultSeparator = Convert-FromUtf8StringToBase64String -InputObject $ResultSeparator
90+
[String[]]$Result = Invoke-Expression -Command "node --no-deprecation --no-warnings `"$WrapperScriptFilePath`" $Base64Name $Base64Argument $Base64ResultSeparator"
18391
[UInt32[]]$ResultSkipIndexes = @()
18492
For ([UInt32]$ResultIndex = 0; $ResultIndex -ilt $Result.Count; $ResultIndex++) {
18593
[String]$ResultLine = $Result[$ResultIndex]
@@ -204,44 +112,9 @@ Function Invoke-NodeJsWrapper {
204112
Convert-FromBase64StringToUtf8String |
205113
ConvertFrom-Json -Depth 100 |
206114
Write-Output
207-
Return
208-
}
209-
Catch {
210-
Write-Warning -Message "Unable to successfully invoke NodeJS bundled wrapper (``$Name``): $_"
211-
}
212-
Try {
213-
If (!(Install-NodeJsDependencies)) {
214-
Throw 'Unable to install NodeJS wrapper API dependencies!'
215-
}
216-
[String[]]$Result = Invoke-Expression -Command "node --no-deprecation --no-warnings `"$WrapperUnbundledFilePath`" $Base64Name $Base64Argument $Base64ResultSeparator"
217-
[UInt32[]]$ResultSkipIndexes = @()
218-
For ([UInt32]$ResultIndex = 0; $ResultIndex -ilt $Result.Count; $ResultIndex++) {
219-
[String]$ResultLine = $Result[$ResultIndex]
220-
If ($ResultLine -imatch '^::.+?::.*$') {
221-
Write-Host -Object $ResultLine
222-
$ResultSkipIndexes += $ResultIndex
223-
Continue
224-
}
225-
If ($ResultLine -ieq $ResultSeparator) {
226-
$ResultSkipIndexes += @($ResultIndex..($Result.Count - 1))
227-
Break
228-
}
229-
}
230-
If ($LASTEXITCODE -ine 0) {
231-
Throw "Unexpected exit code ``$LASTEXITCODE``! $(
232-
$Result |
233-
Select-Object -SkipIndex $ResultSkipIndexes |
234-
Join-String -Separator "`n"
235-
)"
236-
}
237-
$Result[$Result.Count - 1] |
238-
Convert-FromBase64StringToUtf8String |
239-
ConvertFrom-Json -Depth 100 |
240-
Write-Output
241-
Return
242115
}
243116
Catch {
244-
Write-Error -Message "Unable to successfully invoke NodeJS unbundled wrapper (``$Name``): $_" -Category 'InvalidData'
117+
Write-Error -Message "Unable to successfully invoke NodeJS wrapper (``$Name``): $_" -Category 'InvalidData'
245118
}
246119
}
247120
<#

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hugoalh/ghactions-toolkit-powershell-nodejs-wrapper-distribution",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"description": "A PowerShell module to provide a better and easier way for GitHub Actions to communicate with the runner machine, and the toolkit for developing GitHub Actions in PowerShell.",
55
"keywords": [
66
"gh-actions",
@@ -24,12 +24,6 @@
2424
"type": "git",
2525
"url": "git+https://github.com/hugoalh-studio/ghactions-toolkit-powershell.git"
2626
},
27-
"dependencies": {
28-
"@actions/artifact": "^1.1.1",
29-
"@actions/cache": "^3.2.1",
30-
"@actions/core": "^1.10.0",
31-
"@actions/tool-cache": "^2.0.1"
32-
},
3327
"engines": {
3428
"node": ">=14.15.0"
3529
},

0 commit comments

Comments
 (0)