Skip to content

Commit a085b0d

Browse files
committed
20230313B
1 parent f2dd83d commit a085b0d

File tree

10 files changed

+159
-91
lines changed

10 files changed

+159
-91
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +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.3.2-beta.4"
21+
- "v1.3.2"
2222
- "v1.3.1"
2323
- "v1.3.0"
2424
- "v1.2.3"

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

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

252252
# Prerelease string of this module
253-
Prerelease = 'beta4'
253+
# Prerelease = ''
254254

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

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ Function Export-Artifact {
5656
}
5757
}
5858
}
59-
[Hashtable]$InputObject = @{
59+
[Hashtable]$Argument = @{
6060
Name = $Name
6161
Path = $PathsProceed
6262
BaseRoot = $BaseRoot
6363
ContinueOnIssue = $ContinueOnIssue.IsPresent
6464
}
6565
If ($RetentionTime -igt 0) {
66-
$InputObject.RetentionTIme = $RetentionTime
66+
$Argument.RetentionTIme = $RetentionTime
6767
}
68-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/upload' -InputObject $InputObject |
68+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/upload' -Argument $Argument |
6969
Write-Output
7070
}
7171
}
@@ -100,13 +100,13 @@ Function Import-Artifact {
100100
Process {
101101
Switch ($PSCmdlet.ParameterSetName) {
102102
'All' {
103-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -InputObject @{
103+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -Argument @{
104104
Destination = $Destination
105105
} |
106106
Write-Output
107107
}
108108
'Single' {
109-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -InputObject @{
109+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -Argument @{
110110
Name = $Name
111111
Destination = $Destination
112112
CreateSubfolder = $CreateSubfolder.IsPresent

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Function Restore-Cache {
4545
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$LookUp
4646
)
4747
Process {
48-
[Hashtable]$InputObject = @{
48+
[Hashtable]$Argument = @{
4949
PrimaryKey = $Key[0]
5050
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
5151
$LiteralPath |
@@ -57,18 +57,18 @@ Function Restore-Cache {
5757
[String[]]$RestoreKey = $Key |
5858
Select-Object -SkipIndex 0
5959
If ($RestoreKey.Count -igt 0) {
60-
$InputObject.RestoreKey = $RestoreKey
60+
$Argument.RestoreKey = $RestoreKey
6161
}
6262
If ($DownloadConcurrency -igt 0) {
63-
$InputObject.DownloadConcurrency = $DownloadConcurrency
63+
$Argument.DownloadConcurrency = $DownloadConcurrency
6464
}
6565
If ($SegmentTimeout -igt 0) {
66-
$InputObject.SegmentTimeout = $SegmentTimeout * 1000
66+
$Argument.SegmentTimeout = $SegmentTimeout * 1000
6767
}
6868
If ($Timeout -igt 0) {
69-
$InputObject.Timeout = $Timeout * 1000
69+
$Argument.Timeout = $Timeout * 1000
7070
}
71-
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/restore' -InputObject $InputObject)?.CacheKey |
71+
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/restore' -Argument $Argument)?.CacheKey |
7272
Write-Output
7373
}
7474
}
@@ -102,20 +102,20 @@ Function Save-Cache {
102102
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Alias('Concurrency')][Byte]$UploadConcurrency
103103
)
104104
Process {
105-
[Hashtable]$InputObject = @{
105+
[Hashtable]$Argument = @{
106106
Key = $Key
107107
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
108108
$LiteralPath |
109109
ForEach-Object -Process { [WildcardPattern]::Escape($_) }
110110
) : $Path
111111
}
112112
If ($UploadChunkSizes -igt 0) {
113-
$InputObject.UploadChunkSizes = $UploadChunkSizes * 1KB
113+
$Argument.UploadChunkSizes = $UploadChunkSizes * 1KB
114114
}
115115
If ($UploadConcurrency -igt 0) {
116-
$InputObject.UploadConcurrency = $UploadConcurrency
116+
$Argument.UploadConcurrency = $UploadConcurrency
117117
}
118-
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/save' -InputObject $InputObject)?.CacheId |
118+
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/save' -Argument $Argument)?.CacheId |
119119
Write-Output
120120
}
121121
}

hugoalh.GitHubActionsToolkit/module/internal/new-random-token.psm1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
#Requires -PSEdition Core
22
#Requires -Version 7.2
3-
[Char[]]$PoolLowerCase = [Char[]]@(97..122)
4-
[Char[]]$PoolNumber = [String[]]@(0..9)
5-
[Char[]]$PoolUpperCase = [Char[]]@(65..90)
3+
[Char[]]$PoolMain = [String[]]@(0..9) + [Char[]]@(65..90) + [Char[]]@(97..122)
64
<#
75
.SYNOPSIS
86
GitHub Actions - Internal - New Random Token
97
.DESCRIPTION
108
Generate a new random token.
119
.PARAMETER Length
1210
Length of the random token.
13-
.PARAMETER WithUpperCase
14-
Whether to contain upper case letters in the random token.
1511
.OUTPUTS
1612
[String] A new random token.
1713
#>
1814
Function New-RandomToken {
1915
[CmdletBinding()]
2016
[OutputType([String])]
2117
Param (
22-
[Parameter(Position = 0)][ValidateRange(1, [UInt32]::MaxValue)][UInt32]$Length = 16,
23-
[Alias('UpperCase')][Switch]$WithUpperCase
18+
[Parameter(Position = 0)][ValidateRange(1, [UInt32]::MaxValue)][UInt32]$Length = 16
2419
)
25-
[Char[]]$Pool = $PoolLowerCase + $PoolNumber + ($WithUpperCase.IsPresent ? $PoolUpperCase : @()) |
20+
[Char[]]$PoolCurrent = $PoolMain |
2621
Get-Random -Shuffle
2722
@(1..$Length) |
2823
ForEach-Object -Process {
29-
$Pool |
24+
$PoolCurrent |
3025
Get-Random -Count 1
3126
} |
3227
Join-String -Separator '' |

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper.psm1

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,60 @@ Import-Module -Name (
88
) -Prefix 'GitHubActions' -Scope 'Local'
99
[Boolean]$IsTested = $False
1010
[Boolean]$ResultDependencies = $False
11-
[Boolean]$ResultTest = $False
11+
[Boolean]$ResultEnvironment = $False
1212
[SemVer]$NodeJsMinimumVersion = [SemVer]::Parse('14.15.0')
1313
[SemVer]$NpmMinimumVersion = [SemVer]::Parse('6.14.8')
14+
[SemVer]$PnpmMinimumVersion = [SemVer]::Parse('7.28.0')
1415
[RegEx]$SemVerRegEx = 'v?\d+\.\d+\.\d+'
1516
[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+
}
1757
<#
1858
.SYNOPSIS
1959
GitHub Actions - Invoke NodeJS Wrapper
2060
.DESCRIPTION
2161
Invoke NodeJS wrapper.
2262
.PARAMETER Name
2363
Name of the NodeJS wrapper.
24-
.PARAMETER InputObject
64+
.PARAMETER Argument
2565
Arguments of the NodeJS wrapper.
2666
.OUTPUTS
2767
[PSCustomObject] Result of the NodeJS wrapper.
@@ -32,30 +72,38 @@ Function Invoke-NodeJsWrapper {
3272
[OutputType(([PSCustomObject], [PSCustomObject[]]))]
3373
Param (
3474
[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
3677
)
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+
}
4491
}
4592
[String]$ResultSeparator = "=====$(New-GitHubActionsRandomToken -Length 32)====="
4693
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)"
5199
[UInt32[]]$ResultSkipIndexes = @()
52100
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
56104
$ResultSkipIndexes += $ResultIndex
57105
}
58-
If ($Item -ieq $ResultSeparator) {
106+
If ($ResultLine -ieq $ResultSeparator) {
59107
$ResultSkipIndexes += @($ResultIndex..($Result.Count - 1))
60108
Break
61109
}
@@ -67,7 +115,8 @@ Function Invoke-NodeJsWrapper {
67115
Join-String -Separator "`n"
68116
)"
69117
}
70-
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Result[$Result.IndexOf($ResultSeparator) + 1])) |
118+
$Result[$Result.Count - 1] |
119+
Convert-FromBase64StringToUtf8String |
71120
ConvertFrom-Json -Depth 100 |
72121
Write-Output
73122
}
@@ -96,17 +145,17 @@ Function Test-NodeJsEnvironment {
96145
)
97146
If ($IsTested -and !$Retest.IsPresent -and !$ReinstallDependencies.IsPresent) {
98147
Write-Verbose -Message 'Previously tested NodeJS environment; Return previous result.'
99-
Write-Output -InputObject ($ResultDependencies -and $ResultTest)
148+
Write-Output -InputObject ($ResultDependencies -and $ResultEnvironment)
100149
Return
101150
}
102151
$Script:IsTested = $False
103152
If ($ReinstallDependencies.IsPresent) {
104153
$Script:ResultDependencies = $False
105154
}
106155
If ($Retest.IsPresent) {
107-
$Script:ResultTest = $False
156+
$Script:ResultEnvironment = $False
108157
}
109-
If (!$ResultTest) {
158+
If (!$ResultEnvironment) {
110159
Try {
111160
Try {
112161
$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 {
150199
Catch {
151200
Write-Verbose -Message $_
152201
$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)
155204
Return
156205
}
157206
}
158-
$Script:ResultTest = $True
207+
$Script:ResultEnvironment = $True
159208
If (!$ResultDependencies) {
160209
Try {
161210
Try {
162211
$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+
}
163220
}
164221
Catch {
165222
Try {
166-
$Null = npm install --global pnpm
223+
$Null = npm install --global pnpm@latest
167224
}
168225
Catch {
169226
Throw 'Unable to install PNPM!'
@@ -190,13 +247,13 @@ Function Test-NodeJsEnvironment {
190247
Write-Verbose -Message $_
191248
$Script:IsTested = $True
192249
$Script:ResultDependencies = $False
193-
Write-Output -InputObject ($ResultDependencies -and $ResultTest)
250+
Write-Output -InputObject ($ResultDependencies -and $ResultEnvironment)
194251
Return
195252
}
196253
}
197254
$Script:IsTested = $True
198255
$Script:ResultDependencies = $True
199-
Write-Output -InputObject ($ResultDependencies -and $ResultTest)
256+
Write-Output -InputObject ($ResultDependencies -and $ResultEnvironment)
200257
}
201258
Export-ModuleMember -Function @(
202259
'Invoke-NodeJsWrapper',

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/lib/main.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
import { cacheDir as ghactionsToolCacheCacheDirectory, cacheFile as ghactionsToolCacheCacheFile, downloadTool as ghactionToolCacheDownloadTool, extract7z as ghactionToolCacheExtract7z, extractTar as ghactionToolCacheExtractTar, extractXar as ghactionToolCacheExtractXar, extractZip as ghactionToolCacheExtractZip, find as ghactionsToolCacheFind, findAllVersions as ghactionsToolCacheFindAllVersions } from "@actions/tool-cache";
22
import { create as ghactionsArtifact } from "@actions/artifact";
3-
import { getIDToken as ghactionsGetOpenIDConnectToken } from "@actions/core";
3+
import { debug as ghactionsDebug, getIDToken as ghactionsGetOpenIDConnectToken } from "@actions/core";
44
import { restoreCache as ghactionsCacheRestoreCache, saveCache as ghactionsCacheSaveCache } from "@actions/cache";
5+
function base64FromUTF8(item) {
6+
return Buffer.from(item, "utf8").toString("base64");
7+
}
8+
function base64ToUTF8(item) {
9+
return Buffer.from(item, "base64").toString("utf8");
10+
}
511
function errorHandle(reason) {
612
console.error(reason?.message ?? reason);
713
return process.exit(1);
814
}
915
function resultHandle(result) {
10-
return Buffer.from(JSON.stringify(result), "utf8").toString("base64");
16+
return base64FromUTF8(JSON.stringify(result));
1117
}
12-
const [wrapperName, inputsRaw, delimiter] = process.argv.slice(2);
13-
const inputs = JSON.parse(Buffer.from(inputsRaw, "base64").toString("utf8"));
18+
let [wrapperName, inputsRaw, delimiter] = process.argv.slice(2);
19+
[wrapperName, inputsRaw, delimiter] = [wrapperName, inputsRaw, delimiter].map((value) => {
20+
return base64ToUTF8(value);
21+
});
22+
const inputs = JSON.parse(inputsRaw);
1423
switch (wrapperName) {
24+
case "__debug":
25+
{
26+
ghactionsDebug(inputs.Message);
27+
console.log(delimiter);
28+
console.log(resultHandle({
29+
Message: "Hello, world!",
30+
Message2: "Good day, world!"
31+
}));
32+
}
33+
break;
1534
case "artifact/download":
1635
{
1736
const result = await ghactionsArtifact().downloadArtifact(inputs.Name, inputs.Destination, { createArtifactFolder: inputs.CreateSubfolder }).catch(errorHandle);

0 commit comments

Comments
 (0)