Skip to content

Commit 642df6c

Browse files
committed
Update functions *-GitHubActionsArtifact
1 parent 5fffa5c commit 642df6c

File tree

4 files changed

+84
-29
lines changed

4 files changed

+84
-29
lines changed

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 3 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 = '2.0.0'
6+
ModuleVersion = '2.1.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = @()
@@ -88,6 +88,7 @@
8888
'Export-Artifact',
8989
'Find-ToolCache',
9090
'Format-Markdown',
91+
'Get-Artifact',
9192
'Get-DebugStatus',
9293
'Get-Input',
9394
'Get-OpenIdConnectToken',
@@ -218,7 +219,7 @@
218219
ReleaseNotes = '(Please visit https://github.com/hugoalh-studio/ghactions-toolkit-powershell/releases.)'
219220

220221
# Prerelease string of this module
221-
# Prerelease = ''
222+
Prerelease = 'beta1'
222223

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

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ Path of the files that need to export as artifact.
1515
Literal path of the files that need to export as artifact.
1616
.PARAMETER RootDirectory
1717
Absolute literal path of the root directory of the files for control files structure.
18-
.PARAMETER RetentionDays
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.
18+
.PARAMETER CompressionLevel
19+
Level of compression for Zlib to be applied to the artifact archive. The value can range from 0 to 9.
2420
25-
When enable, export will stop, include all of the queued files; The partial artifact will have files up until the failure.
21+
- 0: No compression
22+
- 1: Best speed
23+
- 6: Default compression (same as GNU Gzip)
24+
- 9: Best compression
2625
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.
26+
Higher levels will result in better compression, but will take longer to complete. For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads.
27+
.PARAMETER RetentionDays
28+
Retention days of the artifact, override the default value.
2829
.OUTPUTS
2930
[PSCustomObject] Metadata of the exported artifact.
3031
#>
@@ -36,8 +37,9 @@ Function Export-Artifact {
3637
[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,
3738
[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,
3839
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('BaseRoot', 'Root')][String]$RootDirectory = $Env:GITHUB_WORKSPACE,
40+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(0,9, ErrorMessage = 'Value is not a valid compression level!')][Int16]$CompressionLevel = -1,
3941
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('RetentionDay', 'RetentionTime')][UInt16]$RetentionDays,
40-
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$FailFast
42+
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$FailFast# Deprecated.
4143
)
4244
Process {
4345
If ($RootDirectory -inotmatch '^.+$') {
@@ -74,7 +76,9 @@ Function Export-Artifact {
7476
'name' = $Name
7577
'items' = $Items
7678
'rootDirectory' = $RootDirectory
77-
'continueOnError' = !$FailFast.IsPresent
79+
}
80+
If ($CompressionLevel -gt -1) {
81+
$Argument.('compressionLevel') = $CompressionLevel
7882
}
7983
If ($RetentionDays -gt 0) {
8084
$Argument.('retentionDays') = $RetentionDays
@@ -86,53 +90,103 @@ Function Export-Artifact {
8690
Set-Alias -Name 'Save-Artifact' -Value 'Export-Artifact' -Option 'ReadOnly' -Scope 'Local'
8791
<#
8892
.SYNOPSIS
93+
GitHub Actions - Get Artifact
94+
.DESCRIPTION
95+
Get artifact that shared from the previous jobs in the current workflow run.
96+
.PARAMETER Name
97+
Name of the artifact.
98+
.PARAMETER All
99+
Whether to get all of the artifacts that shared from the previous jobs in the current workflow run.
100+
.PARAMETER Latest
101+
Whether to filter the workflow run's artifacts to the latest by name. In the case of reruns, this can be useful to avoid duplicates.
102+
.OUTPUTS
103+
[PSCustomObject] Metadata of the artifact.
104+
[PSCustomObject[]] Metadata of the artifacts.
105+
#>
106+
Function Get-Artifact {
107+
[CmdletBinding(DefaultParameterSetName = 'Single', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_getgithubactionsartifact')]
108+
[OutputType([PSCustomObject], ParameterSetName = 'Single')]
109+
[OutputType([PSCustomObject[]], ParameterSetName = 'All')]
110+
Param (
111+
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
112+
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
113+
[Parameter(ParameterSetName = 'All')][Switch]$Latest
114+
)
115+
Process {
116+
[Hashtable]$Argument = @{}
117+
Switch ($PSCmdlet.ParameterSetName) {
118+
'All' {
119+
$Argument.('latest') = $Latest.IsPresent
120+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/list' -Argument $Argument |
121+
Write-Output
122+
}
123+
'Single' {
124+
$Argument.('name') = $Name
125+
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/get' -Argument $Argument |
126+
Write-Output
127+
}
128+
}
129+
}
130+
}
131+
<#
132+
.SYNOPSIS
89133
GitHub Actions - Import Artifact
90134
.DESCRIPTION
91135
Import artifact that shared from the previous jobs in the current workflow run.
136+
.PARAMETER Id
137+
ID of the artifact.
92138
.PARAMETER Name
93139
Name of the artifact.
94140
.PARAMETER Destination
95141
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.
98142
.PARAMETER All
99143
Whether to import all of the artifacts that shared from the previous jobs in the current workflow run; Always create sub-directories.
100144
.OUTPUTS
101145
[PSCustomObject] Metadata of the imported artifact.
102146
[PSCustomObject[]] Metadata of the imported artifacts.
103147
#>
104148
Function Import-Artifact {
105-
[CmdletBinding(DefaultParameterSetName = 'Single', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_importgithubactionsartifact')]
106-
[OutputType([PSCustomObject], ParameterSetName = 'Single')]
149+
[CmdletBinding(DefaultParameterSetName = 'SingleId', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_importgithubactionsartifact')]
150+
[OutputType([PSCustomObject], ParameterSetName = ('SingleId', 'SingleName'))]
107151
[OutputType([PSCustomObject[]], ParameterSetName = 'All')]
108152
Param (
109-
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
153+
[Parameter(Mandatory = $True, ParameterSetName = 'SingleId', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][UInt64]$Id,
154+
[Parameter(Mandatory = $True, ParameterSetName = 'SingleName', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
110155
[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
156+
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
157+
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$CreateSubDirectory# Deprecated.
113158
)
114159
Process {
115-
[Hashtable]$Argument = @{}
116-
If ($Destination.Length -gt 0) {
117-
$Argument.('destination') = $Destination
118-
}
119160
Switch ($PSCmdlet.ParameterSetName) {
120161
'All' {
121-
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -Argument $Argument |
162+
Get-Artifact -All -Latest |
163+
ForEach-Object -Process {
164+
Import-Artifact -Id $_.id -Destination "$Destination/$($_.name)"
165+
} |
122166
Write-Output
123167
}
124-
'Single' {
125-
$Argument.('name') = $Name
126-
$Argument.('createSubDirectory') = $CreateSubDirectory.IsPresent
168+
'SingleId' {
169+
[Hashtable]$Argument = @{
170+
'id' = $Id
171+
}
172+
If ($Destination.Length -gt 0) {
173+
$Argument.('path') = $Destination
174+
}
127175
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -Argument $Argument |
128176
Write-Output
129177
}
178+
'SingleName' {
179+
[PSCustomObject]$ArtifactMeta = Get-Artifact -Name $Name
180+
Import-Artifact -Id $ArtifactMeta.id -Destination $Destination |
181+
Write-Output
182+
}
130183
}
131184
}
132185
}
133186
Set-Alias -Name 'Restore-Artifact' -Value 'Import-Artifact' -Option 'ReadOnly' -Scope 'Local'
134187
Export-ModuleMember -Function @(
135188
'Export-Artifact',
189+
'Get-Artifact',
136190
'Import-Artifact'
137191
) -Alias @(
138192
'Restore-Artifact',

hugoalh.GitHubActionsToolkit/nodejs-wrapper/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs-wrapper-source/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ switch (input.$name) {
6565
try {
6666
const result: GitHubActionsArtifactListResponse = await new GitHubActionsArtifactClient().listArtifacts({
6767
findBy: input.findBy,
68-
latest: true
68+
latest: input.latest
6969
});
7070
await resolveSuccess(result.artifacts);
7171
} catch (error) {

0 commit comments

Comments
 (0)