Skip to content

Commit c9ace54

Browse files
committed
Refactor 2
1 parent c1287dd commit c9ace54

28 files changed

+1419
-1319
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A PowerShell module to provide a better and easier way for GitHub Actions to com
1515
### PowerShell
1616

1717
- **Target Version:** >= v7.2.0, &:
18-
- GitHub Actions Runner >= v2.308.0
18+
- GitHub Actions Runner >= v2.310.0
1919
- NodeJS >= v16.13.0 *\[Optional, for NodeJS based wrapper API\]*
2020
- **Domain/Registry:**
2121
- [PowerShell Gallery](https://www.powershellgallery.com/packages/hugoalh.GitHubActionsToolkit)
@@ -37,12 +37,12 @@ A PowerShell module to provide a better and easier way for GitHub Actions to com
3737
- `Add-GitHubActionsPATH`
3838
- `Add-GitHubActionsProblemMatcher`
3939
- `Add-GitHubActionsSecretMask`
40-
- `Add-GitHubActionsStepSummary`
41-
- `Add-GitHubActionsStepSummaryHeader`
42-
- `Add-GitHubActionsStepSummaryImage`
43-
- `Add-GitHubActionsStepSummaryLink`
44-
- `Add-GitHubActionsStepSummarySubscriptText`
45-
- `Add-GitHubActionsStepSummarySuperscriptText`
40+
- `Add-GitHubActionsSummary`
41+
- `Add-GitHubActionsSummaryHeader`
42+
- `Add-GitHubActionsSummaryImage`
43+
- `Add-GitHubActionsSummaryLink`
44+
- `Add-GitHubActionsSummarySubscriptText`
45+
- `Add-GitHubActionsSummarySuperscriptText`
4646
- `Disable-GitHubActionsStdOutCommandEcho`
4747
- `Disable-GitHubActionsStdOutCommandProcess`
4848
- `Enable-GitHubActionsStdOutCommandEcho`
@@ -56,7 +56,7 @@ A PowerShell module to provide a better and easier way for GitHub Actions to com
5656
- `Get-GitHubActionsInput`
5757
- `Get-GitHubActionsOpenIdConnectToken`
5858
- `Get-GitHubActionsState`
59-
- `Get-GitHubActionsStepSummary`
59+
- `Get-GitHubActionsSummary`
6060
- `Get-GitHubActionsWebhookEventPayload`
6161
- `Get-GitHubActionsWorkflowRunUri`
6262
- `Import-GitHubActionsArtifact`
@@ -69,15 +69,12 @@ A PowerShell module to provide a better and easier way for GitHub Actions to com
6969
- `Set-GitHubActionsEnvironmentVariable`
7070
- `Set-GitHubActionsOutput`
7171
- `Set-GitHubActionsState`
72-
- `Set-GitHubActionsStepSummary`
72+
- `Set-GitHubActionsSummary`
7373
- `Test-GitHubActionsEnvironment`
74-
- `Test-GitHubActionsNodeJsEnvironment`
75-
- `Write-GitHubActionsAnnotation`
7674
- `Write-GitHubActionsDebug`
7775
- `Write-GitHubActionsError`
7876
- `Write-GitHubActionsFail`
7977
- `Write-GitHubActionsNotice`
80-
- `Write-GitHubActionsRaw`
8178
- `Write-GitHubActionsWarning`
8279
8380
## ✍️ Example

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
| **Versions** | **Status** | **Target - GitHub Actions Runner** | **Target - PowerShell** | **Target - NodeJS (Wrapper API)** | **Target - NPM (Wrapper API)** |
1515
|:-:|:-:|:-:|:-:|:-:|:-:|
16+
| v2.X.X | L | >= v2.310.0 | >= v7.2.0 | >= v16.13.0 | *N/A* |
1617
| v1.X.X | L | >= v2.308.0 | >= v7.2.0 | >= v16.13.0 | *N/A* |
1718
| v1.4.X \~ v1.7.X | ✔️ | >= v2.303.0 | >= v7.2.0 | >= v14.15.0 | *N/A* |
1819
| v1.3.X | ❌{🐛🧓} | *Unspecified* | >= v7.2.0 | >= v14.15.0 | >= v6.14.8 |

_get-package-members.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
This script is help for copy members to the file `hugoalh.GitHubActionsToolkit.psd1` for best performance, and use for debug.
44
#>
55
[String]$PackageName = 'hugoalh.GitHubActionsToolkit'
6-
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath $PackageName -AdditionalChildPath @("$PackageName.psm1")) -Scope 'Local'
6+
Import-Module -Name @(
7+
(Join-Path -Path $PSScriptRoot -ChildPath "$PackageName\$PackageName.psm1")
8+
) -Scope 'Local'
79
[PSCustomObject[]]$PackageCommands = Get-Command -Module $PackageName -ListImported
810
ForEach ($CommandType In @('Function', 'Alias')) {
911
$PackageCommands |

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 22 additions & 23 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.8.0'
6+
ModuleVersion = '2.0.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = @()
@@ -64,16 +64,18 @@
6464
'Add-PATH',
6565
'Add-ProblemMatcher',
6666
'Add-SecretMask',
67-
'Add-StepSummary',
68-
'Add-StepSummaryHeader',
69-
'Add-StepSummaryImage',
70-
'Add-StepSummaryLink',
71-
'Add-StepSummarySubscriptText',
72-
'Add-StepSummarySuperscriptText',
67+
'Add-Summary',
68+
'Add-SummaryHeader',
69+
'Add-SummaryImage',
70+
'Add-SummaryLink',
71+
'Add-SummarySubscriptText',
72+
'Add-SummarySuperscriptText',
73+
'Clear-EnvironmentVariable',
7374
'Clear-FileCommand',
7475
'Clear-Output',
76+
'Clear-PATH',
7577
'Clear-State',
76-
'Clear-StepSummary',
78+
'Clear-Summary',
7779
'ConvertFrom-CsvM',
7880
'ConvertFrom-CsvS',
7981
'Disable-StdOutCommandEcho',
@@ -85,15 +87,15 @@
8587
'Expand-ToolCacheCompressedFile',
8688
'Export-Artifact',
8789
'Find-ToolCache',
90+
'Format-Markdown',
8891
'Get-DebugStatus',
8992
'Get-Input',
9093
'Get-OpenIdConnectToken',
9194
'Get-State',
92-
'Get-StepSummary',
95+
'Get-Summary',
9396
'Get-WebhookEventPayload',
9497
'Get-WorkflowRunUri',
9598
'Import-Artifact',
96-
'Invoke-NodeJsWrapper',
9799
'Invoke-ToolCacheToolDownloader',
98100
'Register-ToolCacheDirectory',
99101
'Register-ToolCacheFile',
@@ -103,16 +105,13 @@
103105
'Set-EnvironmentVariable',
104106
'Set-Output',
105107
'Set-State',
106-
'Set-StepSummary',
108+
'Set-Summary',
107109
'Test-Environment',
108-
'Test-NodeJsEnvironment',
109-
'Write-Annotation',
110110
'Write-Debug',
111111
'Write-Error',
112112
'Write-Fail',
113113
'Write-FileCommand',
114114
'Write-Notice',
115-
'Write-Raw',
116115
'Write-StdOutCommand',
117116
'Write-Warning'
118117
)
@@ -127,20 +126,18 @@
127126
AliasesToExport = @(
128127
'Add-Mask',
129128
'Add-Secret',
130-
'Add-StepSummaryHyperlink',
131-
'Add-StepSummaryPicture',
132-
'Add-StepSummaryRaw',
133-
'Add-StepSummarySubscript',
134-
'Add-StepSummarySuperscript',
129+
'Add-SummaryHyperlink',
130+
'Add-SummaryPicture',
131+
'Add-SummaryRaw',
132+
'Add-SummarySubscript',
133+
'Add-SummarySuperscript',
135134
'Disable-CommandEcho',
136135
'Disable-CommandProcess',
137136
'Enable-CommandEcho',
138137
'Enable-CommandProcess',
139138
'Enter-Group',
140139
'Exit-Group',
141140
'Expand-ToolCacheArchive',
142-
'Expand-ToolCacheCompressedArchive',
143-
'Expand-ToolCacheFile',
144141
'Export-Cache',
145142
'Get-Event',
146143
'Get-EventPayload',
@@ -151,18 +148,20 @@
151148
'Get-WebhookPayload',
152149
'Get-WorkflowRunUrl',
153150
'Import-Cache',
151+
'Remove-Env',
152+
'Remove-EnvironmentVariable',
154153
'Remove-FileCommand',
155154
'Remove-Output',
155+
'Remove-PATH',
156156
'Remove-State',
157-
'Remove-StepSummary',
157+
'Remove-Summary',
158158
'Restore-Artifact',
159159
'Restore-State',
160160
'Resume-CommandProcess',
161161
'Resume-StdOutCommandProcess',
162162
'Save-Artifact',
163163
'Save-State',
164164
'Set-Env',
165-
'Set-Environment',
166165
'Start-CommandEcho',
167166
'Start-CommandProcess',
168167
'Start-StdOutCommandEcho',

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
[String[]]$ModulesName = @(
33
'artifact',
44
'cache',
5-
'command-base',
6-
'command-control',
5+
'command-file',
6+
'command-stdout',
77
'environment-variable',
88
'log',
99
'markup',
10-
'nodejs-wrapper',
1110
'open-id-connect',
1211
'parameter',
1312
'problem-matcher',
14-
'step-summary',
13+
'summary',
1514
'tool-cache',
1615
'utility'
1716
)
1817
Import-Module -Name (
1918
$ModulesName |
20-
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath 'module' -AdditionalChildPath @("$_.psm1") }
19+
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "module\$_.psm1" }
2120
) -Scope 'Local'
2221
[PSCustomObject[]]$PackageCommands = Get-Command -Module $ModulesName -ListImported
2322
[String[]]$PackageFunctions = $PackageCommands |

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#Requires -PSEdition Core -Version 7.2
2-
Import-Module -Name (
3-
@(
4-
'nodejs-wrapper'
5-
) |
6-
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
2+
Import-Module -Name @(
3+
(Join-Path -Path $PSScriptRoot -ChildPath 'internal\nodejs-wrapper.psm1')
74
) -Prefix 'GitHubActions' -Scope 'Local'
85
<#
96
.SYNOPSIS
107
GitHub Actions - Export Artifact
118
.DESCRIPTION
12-
Export artifact to persist the data and/or share with the future jobs in the same workflow.
9+
Export artifact to share with all of the subsequent jobs in the same workflow, and/or persist the data.
1310
.PARAMETER Name
1411
Name of the artifact.
1512
.PARAMETER Path
@@ -18,49 +15,66 @@ Path of the files that need to export as artifact.
1815
Literal path of the files that need to export as artifact.
1916
.PARAMETER RootDirectory
2017
Absolute literal path of the root directory of the files for control files structure.
21-
.PARAMETER ContinueOnError
22-
Whether the export should continue in the event of files fail to export; If not set and issue is encountered, export will stop and queued files will not export, the partial artifact availables which include files up until the issue; If set and issue is encountered, the issue file will ignore and skip, and queued files will still export, the partial artifact availables which include everything but exclude issue files.
2318
.PARAMETER RetentionDays
24-
Retention days of the artifact.
19+
Retention days of the artifact, override the default value.
20+
.PARAMETER FailFast
21+
Whether to stop export artifact if any of file fail to export due to any of error.
22+
23+
By default, the failed files will skip and ignore, and all of the queued files will still export; The partial artifact will have all of the files except the failed files.
24+
25+
When enable, export will stop, include all of the queued files; The partial artifact will have files up until the failure.
26+
27+
A partial artifact will always associate and available at the end, and the size reported will be the amount of storage that the organization or user will charge for this partial artifact.
2528
.OUTPUTS
2629
[PSCustomObject] Metadata of the exported artifact.
2730
#>
2831
Function Export-Artifact {
2932
[CmdletBinding(DefaultParameterSetName = 'Path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_exportgithubactionsartifact')]
3033
[OutputType([PSCustomObject])]
3134
Param (
32-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][String]$Name,
33-
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
34-
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
35-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateScript({ [System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container') }, ErrorMessage = '`{0}` is not an exist and valid directory!')][Alias('BaseRoot', 'Root')][String]$RootDirectory = $Env:GITHUB_WORKSPACE,
36-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('ContinueOnIssue')][Switch]$ContinueOnError,
37-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, [Int16]::MaxValue)][Alias('RetentionDay', 'RetentionTime')][Int16]$RetentionDays
35+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
36+
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('File', 'Files', 'Paths')][String[]]$Path,
37+
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
38+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('BaseRoot', 'Root')][String]$RootDirectory = $Env:GITHUB_WORKSPACE,
39+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('RetentionDay', 'RetentionTime')][UInt16]$RetentionDays,
40+
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$FailFast
3841
)
3942
Process {
43+
If ($RootDirectory -inotmatch '^.+$') {
44+
Write-Error -Message 'Parameter `RootDirectory` is not a single line string!' -Category 'SyntaxError'
45+
Return
46+
}
47+
If (!([System.IO.Path]::IsPathFullyQualified($RootDirectory) -and (Test-Path -LiteralPath $RootDirectory -PathType 'Container'))) {
48+
Write-Error -Message "``$RootDirectory`` is not a valid and exist directory!" -Category 'ResourceUnavailable'
49+
Return
50+
}
4051
Switch ($PSCmdlet.ParameterSetName) {
4152
'LiteralPath' {
42-
[String[]]$Items = $LiteralPath |
43-
ForEach-Object -Process { [System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $RootDirectory -ChildPath $_) }
53+
[String[]]$Items = $LiteralPath
4454
}
4555
'Path' {
46-
[String[]]$Items = $Path |
47-
ForEach-Object -Process {
56+
[String[]]$Items = @()
57+
ForEach ($P In $Path) {
58+
If ([WildcardPattern]::ContainsWildcardCharacters($P)) {
4859
Try {
49-
Resolve-Path -Path ([System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $RootDirectory -ChildPath $_)) |
50-
Write-Output
60+
$Items += Resolve-Path -Path ([System.IO.Path]::IsPathFullyQualified($P) ? $P : (Join-Path -Path $RootDirectory -ChildPath $P)) |
61+
Select-Object -ExpandProperty 'Path'
5162
}
5263
Catch {
53-
$_ |
54-
Write-Output
64+
$Items += $P
5565
}
5666
}
67+
Else {
68+
$Items += $P
69+
}
70+
}
5771
}
5872
}
5973
[Hashtable]$Argument = @{
6074
'name' = $Name
6175
'items' = $Items
6276
'rootDirectory' = $RootDirectory
63-
'continueOnError' = $ContinueOnError.IsPresent
77+
'continueOnError' = !$FailFast.IsPresent
6478
}
6579
If ($RetentionDays -gt 0) {
6680
$Argument.('retentionDays') = $RetentionDays
@@ -74,43 +88,43 @@ Set-Alias -Name 'Save-Artifact' -Value 'Export-Artifact' -Option 'ReadOnly' -Sco
7488
.SYNOPSIS
7589
GitHub Actions - Import Artifact
7690
.DESCRIPTION
77-
Import artifact that shared the data from the past jobs in the same workflow.
91+
Import artifact that shared from the past jobs in the same workflow.
7892
.PARAMETER Name
7993
Name of the artifact.
80-
.PARAMETER CreateSubfolder
81-
Whether to create a subfolder with artifact name and put the data into there.
82-
.PARAMETER All
83-
Whether to import all of the artifacts that shared the data from the past jobs in the same workflow; Always create subfolders.
8494
.PARAMETER Destination
8595
Absolute literal path of the destination of the artifact(s).
96+
.PARAMETER CreateSubDirectory
97+
Whether to create a sub-directory with artifact name and put the data into there.
98+
.PARAMETER All
99+
Whether to import all of the artifacts that shared from the past jobs in the same workflow; Always create sub-directories.
86100
.OUTPUTS
87101
[PSCustomObject] Metadata of the imported artifact.
88102
[PSCustomObject[]] Metadata of the imported artifacts.
89103
#>
90104
Function Import-Artifact {
91105
[CmdletBinding(DefaultParameterSetName = 'Single', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_importgithubactionsartifact')]
92-
[OutputType([PSCustomObject[]], ParameterSetName = 'All')]
93106
[OutputType([PSCustomObject], ParameterSetName = 'Single')]
107+
[OutputType([PSCustomObject[]], ParameterSetName = 'All')]
94108
Param (
95-
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][String]$Name,
96-
[Parameter(ParameterSetName = 'Single', ValueFromPipelineByPropertyName = $True)][Switch]$CreateSubfolder,
97-
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
98-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Dest', 'Path', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
109+
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
110+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('Dest', 'Path', 'Target')][String]$Destination,
111+
[Parameter(ParameterSetName = 'Single', ValueFromPipelineByPropertyName = $True)][Switch]$CreateSubDirectory,
112+
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All
99113
)
100114
Process {
115+
[Hashtable]$Argument = @{}
116+
If ($Destination.Length -gt 0) {
117+
$Argument.('destination') = $Destination
118+
}
101119
Switch ($PSCmdlet.ParameterSetName) {
102120
'All' {
103-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -Argument @{
104-
'destination' = $Destination
105-
} |
106-
Write-Output
121+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -Argument $Argument |
122+
Write-Output -NoEnumerate
107123
}
108124
'Single' {
109-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -Argument @{
110-
'name' = $Name
111-
'destination' = $Destination
112-
'createSubfolder' = $CreateSubfolder.IsPresent
113-
} |
125+
$Argument.('name') = $Name
126+
$Argument.('createSubDirectory') = $CreateSubDirectory.IsPresent
127+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -Argument $Argument |
114128
Write-Output
115129
}
116130
}

0 commit comments

Comments
 (0)