Skip to content

Commit 22369bd

Browse files
committed
Merge branch 'enhancement/wrapper-bundle'
1 parent cfdf2ab commit 22369bd

31 files changed

+70632
-1553
lines changed

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 2 additions & 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.1.1'
6+
ModuleVersion = '1.2.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = @()
@@ -249,7 +249,7 @@
249249
ReleaseNotes = '(Please visit https://github.com/hugoalh-studio/ghactions-toolkit-powershell/releases.)'
250250

251251
# Prerelease string of this module
252-
# Prerelease = ''
252+
Prerelease = 'beta1'
253253

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

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Function Export-Artifact {
7474
If ($RetentionTime -igt 0) {
7575
$InputObject.RetentionTIme = $RetentionTime
7676
}
77-
Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\upload.js' -InputObject ([PSCustomObject]$InputObject) |
77+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/upload' -InputObject ([PSCustomObject]$InputObject) |
7878
Write-Output
7979
}
8080
}
@@ -118,13 +118,13 @@ Function Import-Artifact {
118118
}
119119
Switch ($PSCmdlet.ParameterSetName) {
120120
'All' {
121-
Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\download-all.js' -InputObject ([PSCustomObject]@{
121+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -InputObject ([PSCustomObject]@{
122122
Destination = $Destination
123123
}) |
124124
Write-Output
125125
}
126126
'Single' {
127-
Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\download.js' -InputObject ([PSCustomObject]@{
127+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -InputObject ([PSCustomObject]@{
128128
Name = $Name
129129
Destination = $Destination
130130
CreateSubfolder = $CreateSubfolder.IsPresent

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Function Restore-Cache {
7474
}
7575
[System.Environment]::SetEnvironmentVariable('SEGMENT_DOWNLOAD_TIMEOUT_MINS', $SegmentTimeout) |
7676
Out-Null
77-
(Invoke-GitHubActionsNodeJsWrapper -Path 'cache\restore.js' -InputObject ([PSCustomObject]$InputObject))?.CacheKey |
77+
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/restore' -InputObject ([PSCustomObject]$InputObject))?.CacheKey |
7878
Write-Output
7979
}
8080
}
@@ -130,7 +130,7 @@ Function Save-Cache {
130130
If ($UploadConcurrency -igt 0) {
131131
$InputObject.UploadConcurrency = $UploadConcurrency
132132
}
133-
(Invoke-GitHubActionsNodeJsWrapper -Path 'cache\save.js' -InputObject ([PSCustomObject]$InputObject))?.CacheId |
133+
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/save' -InputObject ([PSCustomObject]$InputObject))?.CacheId |
134134
Write-Output
135135
}
136136
}

hugoalh.GitHubActionsToolkit/module/nodejs-invoke.psm1

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Import-Module -Name (
77
) |
88
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath $_ }
99
) -Prefix 'GitHubActions' -Scope 'Local'
10-
[String]$WrapperRoot = Join-Path -Path $PSScriptRoot -ChildPath 'nodejs-wrapper'
10+
[String]$Wrapper = (Join-Path -Path $PSScriptRoot -ChildPath 'nodejs-wrapper' -AdditionalChildPath @('dist', 'main.js')) -ireplace '\\', '/'
1111
<#
1212
.SYNOPSIS
1313
GitHub Actions (Private) - Invoke NodeJS Wrapper
1414
.DESCRIPTION
1515
Invoke NodeJS wrapper.
16-
.PARAMETER Path
17-
Relative literal path of the NodeJS wrapper.
16+
.PARAMETER Name
17+
Name of the NodeJS wrapper.
1818
.PARAMETER InputObject
1919
Arguments of the NodeJS wrapper.
2020
.OUTPUTS
@@ -25,28 +25,27 @@ Function Invoke-NodeJsWrapper {
2525
[CmdletBinding()]
2626
[OutputType(([PSCustomObject], [PSCustomObject[]]))]
2727
Param (
28-
[Parameter(Mandatory = $True, Position = 0)][String]$Path,
28+
[Parameter(Mandatory = $True, Position = 0)][String]$Name,
2929
[Parameter(Mandatory = $True, Position = 1)][Alias('Argument', 'Arguments', 'Input', 'Object', 'Parameter', 'Parameters')][PSCustomObject]$InputObject
3030
)
3131
If (!(Test-GitHubActionsNodeJsEnvironment)) {
32-
Write-Error -Message 'This function requires to invoke with the compatible NodeJS and NPM environment!' -Category 'ResourceUnavailable'
32+
Write-Error -Message 'This function requires to invoke with the compatible NodeJS environment!' -Category 'ResourceUnavailable'
3333
Return
3434
}
35-
[String]$WrapperFullName = Join-Path -Path $WrapperRoot -ChildPath $Path
36-
If (!(Test-Path -LiteralPath $WrapperFullName -PathType 'Leaf')) {
37-
Write-Error -Message "``$Path`` is not an exist and valid NodeJS wrapper path! Most likely some of the files are missing." -Category 'ResourceUnavailable'
35+
If (!(Test-Path -LiteralPath $Wrapper -PathType 'Leaf')) {
36+
Write-Error -Message 'Wrapper is missing!' -Category 'ResourceUnavailable'
3837
Return
3938
}
4039
[String]$ResultSeparator = "=====$(New-GitHubActionsRandomToken -Length 32)====="
4140
Try {
42-
[String[]]$Result = node --no-deprecation --no-warnings "$($WrapperFullName -ireplace '\\', '/')" "$(
41+
[String[]]$Result = node --no-deprecation --no-warnings "$Wrapper" "$Name" "$(
4342
$InputObject |
4443
ConvertTo-Json -Depth 100 -Compress
4544
)" "$ResultSeparator"
4645
[UInt32]$ResultSkipIndex = @()
4746
For ([UInt32]$ResultIndex = 0; $ResultIndex -ilt $Result.Count; $ResultIndex++) {
4847
[String]$Item = $Result[$ResultIndex]
49-
If ($Item -imatch '^::.+$') {
48+
If ($Item -imatch '^::.+?::.*$') {
5049
Write-Host -Object $Item
5150
$ResultSkipIndex += $ResultIndex
5251
}
@@ -64,7 +63,7 @@ Function Invoke-NodeJsWrapper {
6463
Write-Output
6564
}
6665
Catch {
67-
Write-Error -Message "Unable to successfully invoke NodeJS wrapper ``$Path``! $_" -Category 'InvalidData'
66+
Write-Error -Message "Unable to successfully invoke NodeJS wrapper ``$Name``! $_" -Category 'InvalidData'
6867
}
6968
}
7069
Export-ModuleMember -Function @(

hugoalh.GitHubActionsToolkit/module/nodejs-test.psm1

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,32 @@
33
[Boolean]$EnvironmentResult = $False
44
[Boolean]$EnvironmentTested = $False
55
[SemVer]$NodeJsMinimumVersion = [SemVer]::Parse('14.15.0')
6-
[SemVer]$NpmMinimumVersion = [SemVer]::Parse('6.14.8')
76
[RegEx]$SemVerRegEx = '^v?\d+\.\d+\.\d+$'
8-
[String]$WrapperRoot = Join-Path -Path $PSScriptRoot -ChildPath 'nodejs-wrapper'
97
<#
108
.SYNOPSIS
119
GitHub Actions - Test NodeJS Environment
1210
.DESCRIPTION
13-
Test the current machine whether has compatible NodeJS and NPM environment, and has dependencies ready; Test result always cache for reuse.
14-
.PARAMETER ReinstallDependencies
15-
Whether to force reinstall dependencies even though available.
11+
Test the current machine whether has compatible NodeJS environment; Test result always cache for reuse.
1612
.PARAMETER Retest
17-
Whether to redo this test, ignore the cached test result.
13+
Whether to redo this test by ignore the cached test result.
1814
.OUTPUTS
1915
[Boolean] Test result.
2016
#>
2117
Function Test-NodeJsEnvironment {
2218
[CmdletBinding()]
2319
[OutputType([Boolean])]
2420
Param (
25-
[Alias('Reinstall', 'ReinstallDependency', 'ReinstallPackage', 'ReinstallPackages')][Switch]$ReinstallDependencies,
21+
[Alias('Reinstall', 'ReinstallDependency', 'ReinstallPackage', 'ReinstallPackages')][Switch]$ReinstallDependencies,# Deprecated, keep as legacy.
2622
[Alias('Redo')][Switch]$Retest
2723
)
28-
If ($EnvironmentTested -and !$ReinstallDependencies.IsPresent -and !$Retest.IsPresent) {
24+
If ($EnvironmentTested -and !$Retest.IsPresent) {
2925
Write-Verbose -Message 'Previously tested NodeJS environment; Return previous result.'
3026
Write-Output -InputObject $EnvironmentResult
3127
Return
3228
}
29+
$Script:EnvironmentResult = $False
3330
$Script:EnvironmentTested = $False
3431
Try {
35-
Write-Verbose -Message 'Test NodeJS.'
3632
Get-Command -Name 'node' -CommandType 'Application' -ErrorAction 'Stop' |# `Get-Command` will throw error when nothing is found.
3733
Out-Null# No need the result.
3834
[String]$ExpressionNodeJsVersionResult = node --no-deprecation --no-warnings --version |
@@ -43,53 +39,15 @@ Function Test-NodeJsEnvironment {
4339
) {
4440
Throw
4541
}
46-
Write-Verbose -Message 'Test NPM.'
47-
Get-Command -Name 'npm' -CommandType 'Application' -ErrorAction 'Stop' |# `Get-Command` will throw error when nothing is found.
48-
Out-Null# No need the result.
49-
[String]$ExpressionNpmVersionResult = npm --version |
50-
Join-String -Separator "`n"
51-
If (
52-
$ExpressionNpmVersionResult -inotmatch $SemVerRegEx -or
53-
$NpmMinimumVersion -igt [SemVer]::Parse(($ExpressionNpmVersionResult -ireplace '^v', ''))
54-
) {
55-
Throw
56-
}
5742
}
5843
Catch {
59-
$Script:EnvironmentTested = $True
6044
$Script:EnvironmentResult = $False
61-
Write-Output -InputObject $EnvironmentResult
62-
Return
63-
}
64-
$OriginalWorkingDirectory = Get-Location
65-
Write-Verbose -Message 'Test NodeJS wrapper API dependencies.'
66-
Set-Location -LiteralPath $WrapperRoot
67-
Try {
68-
If (
69-
$ReinstallDependencies.IsPresent -or
70-
(
71-
npm outdated |
72-
Join-String -Separator "`n"
73-
) -cmatch 'MISSING'
74-
) {
75-
Write-Verbose -Message 'Install/Reinstall NodeJS wrapper API dependencies.'
76-
npm ci --ignore-scripts --no-audit --no-fund |
77-
Out-Null# No need the result.
78-
If ($LASTEXITCODE -ine 0) {
79-
Throw
80-
}
81-
}
82-
}
83-
Catch {
84-
Set-Location -LiteralPath $OriginalWorkingDirectory
8545
$Script:EnvironmentTested = $True
86-
$Script:EnvironmentResult = $False
8746
Write-Output -InputObject $EnvironmentResult
8847
Return
8948
}
90-
Set-Location -LiteralPath $OriginalWorkingDirectory
91-
$Script:EnvironmentTested = $True
9249
$Script:EnvironmentResult = $True
50+
$Script:EnvironmentTested = $True
9351
Write-Output -InputObject $EnvironmentResult
9452
}
9553
Export-ModuleMember -Function @(

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/artifact/download-all.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/artifact/download.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/artifact/upload.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/cache/restore.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/cache/save.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)