Skip to content

Commit 455afa3

Browse files
committed
Improve wrapper
1 parent 63ac733 commit 455afa3

File tree

7 files changed

+207
-214
lines changed

7 files changed

+207
-214
lines changed

SECURITY.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
1313
| **Versions** | **Status** | **🔵 Date** | **🟢 Date** | **🔴 Date** | **Target - GitHub Actions Runner** | **Target - PowerShell** | **Target - NodeJS (Wrapper API)** |
1414
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
15-
| v2.0.X | 🟤 | *Pending 2023-12-01* | *N/A* | *N/A* | >= v2.310.0 | >= v7.2.0 | >= v16.13.0 |
16-
| v1.7.X | 🟢 | 2023-07-24 | 2023-07-24 | *Pending 2024-01-01* | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 |
15+
| v2.0.X | 🟤 | *Pending <br />2023-12-01* | *N/A* | *N/A* | >= v2.310.0 | >= v7.2.0 | >= v16.13.0 |
16+
| v1.7.X | 🟢 | 2023-07-24 | 2023-07-24 | *Pending <br />2024-01-01* | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 |
1717
| v1.6.X | 🔴 | 2023-07-09 | 2023-07-09 | 2023-07-31 | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 |
1818
| v1.5.X | 🔴 | 2023-04-28 | 2023-04-28 | 2023-07-14 | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 |
1919
| v1.4.X | 🔴 | 2023-03-24 | 2023-03-24 | 2023-05-01 | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 |
2020

2121
> **ℹ️ Notice:**
2222
>
2323
> - The date format is according to ISO 8601 standard.
24+
> - Values in italic format are subject to change.
2425
> - Versions which not in the list are also end of life.
2526
2627
## Report Vulnerability

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
ReleaseNotes = '(Please visit https://github.com/hugoalh-studio/ghactions-toolkit-powershell/releases.)'
219219

220220
# Prerelease string of this module
221-
Prerelease = 'beta2'
221+
Prerelease = 'beta3'
222222

223223
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
224224
RequireLicenseAcceptance = $False

hugoalh.GitHubActionsToolkit/module/internal/nodejs-wrapper.psm1

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,82 +26,74 @@ Function Invoke-NodeJsWrapper {
2626
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
2727
[Parameter(Mandatory = $True, Position = 1)][Alias('Arguments')][Hashtable]$Argument
2828
)
29-
Begin {
30-
[Boolean]$ShouldProceed = $True
29+
Try {
30+
$CommandMeta = Get-Command -Name 'node' -CommandType 'Application' -ErrorAction 'SilentlyContinue'
31+
If ($Null -ieq $CommandMeta) {
32+
Throw 'NodeJS is not exist, or not accessible and usable!'
33+
}
3134
Try {
32-
$CommandMeta = Get-Command -Name 'node' -CommandType 'Application' -ErrorAction 'SilentlyContinue'
33-
If ($Null -ieq $CommandMeta) {
34-
Throw 'NodeJS is not exist, or not accessible and usable!'
35-
}
36-
Try {
37-
[PSCustomObject]$VersionsTable = node --no-deprecation --no-warnings '--eval=console.log(JSON.stringify(process.versions));' *>&1 |
38-
Join-String -Separator "`n" |
39-
ConvertFrom-Json -Depth 100
40-
[SemVer]$CurrentVersion = [SemVer]::Parse($VersionsTable.node)
41-
}
42-
Catch {
43-
Throw 'NodeJS versions table is not parsable!'
44-
}
45-
If ($RequireVersionMinimum -gt $CurrentVersion) {
46-
Throw 'NodeJS is not fulfill the requirement!'
47-
}
48-
ForEach ($FilePath In @($WrapperPackageMetaFilePath, $WrapperScriptFilePath)) {
49-
If (!(Test-Path -LiteralPath $FilePath -PathType 'Leaf')) {
50-
Throw "wrapper resource `"$FilePath`" is missing!"
51-
}
52-
}
53-
If ([String]::IsNullOrEmpty($Env:RUNNER_TEMP)) {
54-
Throw 'environment variable `RUNNER_TEMP` is not defined!'
55-
}
56-
If (![System.IO.Path]::IsPathFullyQualified($Env:RUNNER_TEMP)) {
57-
Throw "``$Env:RUNNER_TEMP`` (environment variable ``RUNNER_TEMP``) is not a valid absolute path!"
58-
}
59-
If (!(Test-Path -LiteralPath $Env:RUNNER_TEMP -PathType 'Container')) {
60-
Throw "path ``$Env:RUNNER_TEMP`` is not initialized!"
61-
}
35+
[PSCustomObject]$VersionsTable = node --no-deprecation --no-warnings '--eval=console.log(JSON.stringify(process.versions));' *>&1 |
36+
Join-String -Separator "`n" |
37+
ConvertFrom-Json -Depth 100
38+
[SemVer]$CurrentVersion = [SemVer]::Parse($VersionsTable.node)
6239
}
6340
Catch {
64-
$ShouldProceed = $False
65-
Write-Error -Message "This function depends and requires to invoke with the compatible NodeJS environment, but $_" -Category 'ResourceUnavailable'
66-
}
67-
}
68-
Process {
69-
If (!$ShouldProceed) {
70-
Return
41+
Throw 'NodeJS versions table is not parsable!'
7142
}
72-
Do {
73-
[String]$ExchangeFilePath = Join-Path -Path $Env:RUNNER_TEMP -ChildPath ([System.IO.Path]::GetRandomFileName())
43+
If ($RequireVersionMinimum -gt $CurrentVersion) {
44+
Throw 'NodeJS is not fulfill the requirement!'
7445
}
75-
While (Test-Path -LiteralPath $ExchangeFilePath -PathType 'Leaf')
76-
Try {
77-
@{ '$name' = $Name } + $Argument |
78-
ConvertTo-Json -Depth 100 -Compress |
79-
Set-Content -LiteralPath $ExchangeFilePath -Confirm:$False -Encoding 'UTF8NoBOM'
80-
[String]$StdOut = node --no-deprecation --no-warnings $WrapperScriptFilePath $ExchangeFilePath *>&1 |
81-
Where-Object -FilterScript {
82-
If ($_ -imatch '^::.+?::.*$') {
83-
Write-Host -Object $_
84-
Return $False
85-
}
86-
Return $True
87-
} |
88-
Join-String -Separator "`n"
89-
If ($LASTEXITCODE -ne 0) {
90-
Throw "[Exit Code $LASTEXITCODE] $StdOut"
91-
}
92-
[PSCustomObject]$Result = Get-Content -LiteralPath $ExchangeFilePath -Raw -Encoding 'UTF8NoBOM' |
93-
ConvertFrom-Json -Depth 100
94-
If (!$Result.IsSuccess) {
95-
Throw $Result.Reason
46+
ForEach ($FilePath In @($WrapperPackageMetaFilePath, $WrapperScriptFilePath)) {
47+
If (!(Test-Path -LiteralPath $FilePath -PathType 'Leaf')) {
48+
Throw "wrapper resource `"$FilePath`" is missing!"
9649
}
97-
$Result.Result |
98-
Write-Output
9950
}
100-
Catch {
101-
Write-Error -Message "Unable to successfully invoke the NodeJS wrapper ``$Name``: $_" -Category 'InvalidData'
51+
If ([String]::IsNullOrEmpty($Env:RUNNER_TEMP)) {
52+
Throw 'environment variable `RUNNER_TEMP` is not defined!'
10253
}
54+
If (![System.IO.Path]::IsPathFullyQualified($Env:RUNNER_TEMP)) {
55+
Throw "``$Env:RUNNER_TEMP`` (environment variable ``RUNNER_TEMP``) is not a valid absolute path!"
56+
}
57+
If (!(Test-Path -LiteralPath $Env:RUNNER_TEMP -PathType 'Container')) {
58+
Throw "path ``$Env:RUNNER_TEMP`` is not initialized!"
59+
}
60+
}
61+
Catch {
62+
Write-Error -Message "This function depends and requires to invoke with the compatible NodeJS environment, but $_" -Category 'ResourceUnavailable'
63+
Return
64+
}
65+
Do {
66+
[String]$ExchangeFilePath = Join-Path -Path $Env:RUNNER_TEMP -ChildPath ([System.IO.Path]::GetRandomFileName())
67+
}
68+
While (Test-Path -LiteralPath $ExchangeFilePath -PathType 'Leaf')
69+
Try {
70+
@{ '$name' = $Name } + $Argument |
71+
ConvertTo-Json -Depth 100 -Compress |
72+
Set-Content -LiteralPath $ExchangeFilePath -Confirm:$False -Encoding 'UTF8NoBOM'
73+
[String]$StdOut = node --no-deprecation --no-warnings $WrapperScriptFilePath $ExchangeFilePath *>&1 |
74+
Where-Object -FilterScript {
75+
If ($_ -imatch '^::.+?::.*$') {
76+
Write-Host -Object $_
77+
Return $False
78+
}
79+
Return $True
80+
} |
81+
Join-String -Separator "`n"
82+
If ($LASTEXITCODE -ne 0) {
83+
Throw "[Exit Code $LASTEXITCODE] $StdOut"
84+
}
85+
[PSCustomObject]$Result = Get-Content -LiteralPath $ExchangeFilePath -Raw -Encoding 'UTF8NoBOM' |
86+
ConvertFrom-Json -Depth 100
87+
If (!$Result.IsSuccess) {
88+
Throw $Result.Reason
89+
}
90+
$Result.Result |
91+
Write-Output
92+
}
93+
Catch {
94+
Write-Error -Message "Unable to successfully invoke the NodeJS wrapper ``$Name``: $_" -Category 'InvalidData'
10395
}
104-
End {
96+
Finally {
10597
If (Test-Path -LiteralPath $ExchangeFilePath -PathType 'Leaf') {
10698
Remove-Item -LiteralPath $ExchangeFilePath -Force -Confirm:$False -ErrorAction 'Continue'
10799
}

hugoalh.GitHubActionsToolkit/nodejs-wrapper/main.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hugoalh.GitHubActionsToolkit/nodejs-wrapper/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hugoalh/ghactions-toolkit-powershell-nodejs-wrapper",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
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",

0 commit comments

Comments
 (0)