@@ -8,20 +8,60 @@ Import-Module -Name (
8
8
) - Prefix ' GitHubActions' - Scope ' Local'
9
9
[Boolean ]$IsTested = $False
10
10
[Boolean ]$ResultDependencies = $False
11
- [Boolean ]$ResultTest = $False
11
+ [Boolean ]$ResultEnvironment = $False
12
12
[SemVer ]$NodeJsMinimumVersion = [SemVer ]::Parse(' 14.15.0' )
13
13
[SemVer ]$NpmMinimumVersion = [SemVer ]::Parse(' 6.14.8' )
14
+ [SemVer ]$PnpmMinimumVersion = [SemVer ]::Parse(' 7.28.0' )
14
15
[RegEx ]$SemVerRegEx = ' v?\d+\.\d+\.\d+'
15
16
[String ]$WrapperRoot = Join-Path - Path $PSScriptRoot - ChildPath ' nodejs-wrapper'
16
- [String ]$WrapperPath = Join-Path - Path $WrapperRoot - ChildPath ' lib' - AdditionalChildPath @ (' main.js' )
17
+ [String ]$WrapperMetaPath = Join-Path - Path $WrapperRoot - ChildPath ' package.json'
18
+ [String ]$WrapperScriptPath = Join-Path - Path $WrapperRoot - ChildPath ' lib' - AdditionalChildPath @ (' main.js' )
19
+ <#
20
+ . SYNOPSIS
21
+ GitHub Actions - Internal - Convert From Base64 String To Utf8 String
22
+ . PARAMETER InputObject
23
+ String that need decode from base64.
24
+ . OUTPUTS
25
+ [String] An decoded string.
26
+ #>
27
+ Function Convert-FromBase64StringToUtf8String {
28
+ [CmdletBinding ()]
29
+ [OutputType ([String ])]
30
+ Param (
31
+ [Parameter (Mandatory = $True , Position = 0 , ValueFromPipeline = $True )][Alias (' Input' , ' Object' )][String ]$InputObject
32
+ )
33
+ Process {
34
+ [System.Text.Encoding ]::UTF8.GetString([System.Convert ]::FromBase64String($InputObject )) |
35
+ Write-Output
36
+ }
37
+ }
38
+ <#
39
+ . SYNOPSIS
40
+ GitHub Actions - Internal - Convert From Utf8 String To Base64 String
41
+ . PARAMETER InputObject
42
+ String that need encode to base64.
43
+ . OUTPUTS
44
+ [String] An encoded string.
45
+ #>
46
+ Function Convert-FromUtf8StringToBase64String {
47
+ [CmdletBinding ()]
48
+ [OutputType ([String ])]
49
+ Param (
50
+ [Parameter (Mandatory = $True , Position = 0 , ValueFromPipeline = $True )][Alias (' Input' , ' Object' )][String ]$InputObject
51
+ )
52
+ Process {
53
+ [System.Convert ]::ToBase64String([System.Text.Encoding ]::UTF8.GetBytes($InputObject )) |
54
+ Write-Output
55
+ }
56
+ }
17
57
<#
18
58
. SYNOPSIS
19
59
GitHub Actions - Invoke NodeJS Wrapper
20
60
. DESCRIPTION
21
61
Invoke NodeJS wrapper.
22
62
. PARAMETER Name
23
63
Name of the NodeJS wrapper.
24
- . PARAMETER InputObject
64
+ . PARAMETER Argument
25
65
Arguments of the NodeJS wrapper.
26
66
. OUTPUTS
27
67
[PSCustomObject] Result of the NodeJS wrapper.
@@ -32,30 +72,38 @@ Function Invoke-NodeJsWrapper {
32
72
[OutputType (([PSCustomObject ], [PSCustomObject []]))]
33
73
Param (
34
74
[Parameter (Mandatory = $True , Position = 0 )][String ]$Name ,
35
- [Parameter (Mandatory = $True , Position = 1 )][Alias (' Argument' , ' Arguments' , ' Input' , ' Object' , ' Parameter' , ' Parameters' )][Hashtable ]$InputObject
75
+ [Parameter (Mandatory = $True , Position = 1 )][Alias (' Arguments' )][Hashtable ]$Argument ,
76
+ [Alias (' Debug' )][Switch ]$LocalDebug
36
77
)
37
- If (! (Test-NodeJsEnvironment )) {
38
- Write-Error - Message ' This function requires to invoke with the compatible NodeJS environment!' - Category ' ResourceUnavailable'
39
- Return
40
- }
41
- If (! (Test-Path - LiteralPath $WrapperPath - PathType ' Leaf' )) {
42
- Write-Error - Message ' Wrapper is missing!' - Category ' ResourceUnavailable'
43
- Return
78
+ If (! $LocalDebug.IsPresent ) {
79
+ If (! (Test-NodeJsEnvironment )) {
80
+ Write-Error - Message ' This function depends and requires to invoke with the compatible NodeJS environment!' - Category ' ResourceUnavailable'
81
+ Return
82
+ }
83
+ If (! (Test-Path - LiteralPath $WrapperMetaPath - PathType ' Leaf' )) {
84
+ Write-Error - Message ' Wrapper meta is missing!' - Category ' ResourceUnavailable'
85
+ Return
86
+ }
87
+ If (! (Test-Path - LiteralPath $WrapperScriptPath - PathType ' Leaf' )) {
88
+ Write-Error - Message ' Wrapper script is missing!' - Category ' ResourceUnavailable'
89
+ Return
90
+ }
44
91
}
45
92
[String ]$ResultSeparator = " =====$ ( New-GitHubActionsRandomToken - Length 32 ) ====="
46
93
Try {
47
- [String []]$Result = Invoke-Expression - Command " node --no-deprecation --no-warnings `" $WrapperPath `" `" $Name `" `" $ ( [System.Convert ]::ToBase64String([System.Text.Encoding ]::UTF8.GetBytes((
48
- $InputObject |
49
- ConvertTo-Json - Depth 100 - Compress
50
- )))) `" `" $ResultSeparator `" "
94
+ [String []]$Result = Invoke-Expression - Command " node --no-deprecation --no-warnings `" $WrapperScriptPath `" $ ( Convert-FromUtf8StringToBase64String - InputObject $Name ) $ (
95
+ $Argument |
96
+ ConvertTo-Json - Depth 100 - Compress |
97
+ Convert-FromUtf8StringToBase64String
98
+ ) $ ( Convert-FromUtf8StringToBase64String - InputObject $ResultSeparator ) "
51
99
[UInt32 []]$ResultSkipIndexes = @ ()
52
100
For ([UInt32 ]$ResultIndex = 0 ; $ResultIndex -ilt $Result.Count ; $ResultIndex ++ ) {
53
- [String ]$Item = $Result [$ResultIndex ]
54
- If ($Item -imatch ' ^::.+?::.*$' ) {
55
- Write-Host - Object $Item
101
+ [String ]$ResultLine = $Result [$ResultIndex ]
102
+ If ($ResultLine -imatch ' ^::.+?::.*$' ) {
103
+ Write-Host - Object $ResultLine
56
104
$ResultSkipIndexes += $ResultIndex
57
105
}
58
- If ($Item -ieq $ResultSeparator ) {
106
+ If ($ResultLine -ieq $ResultSeparator ) {
59
107
$ResultSkipIndexes += @ ($ResultIndex .. ($Result.Count - 1 ))
60
108
Break
61
109
}
@@ -67,7 +115,8 @@ Function Invoke-NodeJsWrapper {
67
115
Join-String - Separator " `n "
68
116
) "
69
117
}
70
- [System.Text.Encoding ]::UTF8.GetString([System.Convert ]::FromBase64String($Result [$Result.IndexOf ($ResultSeparator ) + 1 ])) |
118
+ $Result [$Result.Count - 1 ] |
119
+ Convert-FromBase64StringToUtf8String |
71
120
ConvertFrom-Json - Depth 100 |
72
121
Write-Output
73
122
}
@@ -96,17 +145,17 @@ Function Test-NodeJsEnvironment {
96
145
)
97
146
If ($IsTested -and ! $Retest.IsPresent -and ! $ReinstallDependencies.IsPresent ) {
98
147
Write-Verbose - Message ' Previously tested NodeJS environment; Return previous result.'
99
- Write-Output - InputObject ($ResultDependencies -and $ResultTest )
148
+ Write-Output - InputObject ($ResultDependencies -and $ResultEnvironment )
100
149
Return
101
150
}
102
151
$Script :IsTested = $False
103
152
If ($ReinstallDependencies.IsPresent ) {
104
153
$Script :ResultDependencies = $False
105
154
}
106
155
If ($Retest.IsPresent ) {
107
- $Script :ResultTest = $False
156
+ $Script :ResultEnvironment = $False
108
157
}
109
- If (! $ResultTest ) {
158
+ If (! $ResultEnvironment ) {
110
159
Try {
111
160
Try {
112
161
$Null = Get-Command - Name ' node' - CommandType ' Application' - ErrorAction ' Stop' # `Get-Command` will throw error when nothing is found.
@@ -150,20 +199,28 @@ Function Test-NodeJsEnvironment {
150
199
Catch {
151
200
Write-Verbose - Message $_
152
201
$Script :IsTested = $True
153
- $Script :ResultTest = $False
154
- Write-Output - InputObject ($ResultDependencies -and $ResultTest )
202
+ $Script :ResultEnvironment = $False
203
+ Write-Output - InputObject ($ResultDependencies -and $ResultEnvironment )
155
204
Return
156
205
}
157
206
}
158
- $Script :ResultTest = $True
207
+ $Script :ResultEnvironment = $True
159
208
If (! $ResultDependencies ) {
160
209
Try {
161
210
Try {
162
211
$Null = Get-Command - Name ' pnpm' - CommandType ' Application' - ErrorAction ' Stop' # `Get-Command` will throw error when nothing is found.
212
+ [String ]$PnpmVersionStdOut = pnpm -- version |
213
+ Join-String - Separator " `n "
214
+ If (
215
+ $PnpmVersionStdOut -inotmatch $SemVerRegEx -or
216
+ $PnpmMinimumVersion -igt [SemVer ]::Parse(($Matches [0 ] -ireplace ' ^v' , ' ' ))
217
+ ) {
218
+ Throw
219
+ }
163
220
}
164
221
Catch {
165
222
Try {
166
- $Null = npm install -- global pnpm
223
+ $Null = npm install -- global pnpm@latest
167
224
}
168
225
Catch {
169
226
Throw ' Unable to install PNPM!'
@@ -190,13 +247,13 @@ Function Test-NodeJsEnvironment {
190
247
Write-Verbose - Message $_
191
248
$Script :IsTested = $True
192
249
$Script :ResultDependencies = $False
193
- Write-Output - InputObject ($ResultDependencies -and $ResultTest )
250
+ Write-Output - InputObject ($ResultDependencies -and $ResultEnvironment )
194
251
Return
195
252
}
196
253
}
197
254
$Script :IsTested = $True
198
255
$Script :ResultDependencies = $True
199
- Write-Output - InputObject ($ResultDependencies -and $ResultTest )
256
+ Write-Output - InputObject ($ResultDependencies -and $ResultEnvironment )
200
257
}
201
258
Export-ModuleMember - Function @ (
202
259
' Invoke-NodeJsWrapper' ,
0 commit comments