Skip to content

Commit b0fecf2

Browse files
committed
20221013A
1 parent 82f9c55 commit b0fecf2

File tree

14 files changed

+206
-179
lines changed

14 files changed

+206
-179
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Please provide as much as you can to help the community leaders for better under
6767
- Your account's platform (e.g.: GitHub, GitLab, ...).
6868
- Your account's username (e.g.: `@octocat`).
6969
- Project's ID or repository URI.
70-
- Project's ID is displayed at the top part of Readme (file: `README.md`), below the project display name (i.e.: header), inside a code block.
70+
- Project's ID is displayed at the top part of the Readme (file: `README.md`), below the project display name (i.e.: header), inside a code block.
7171
- Defendants and witnesses.
7272
- Are defendants include any staffs, moderators, and/or administrators?
7373
- This can affect who will proceed this complaint.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To improve the wiki, create an issue.
3939

4040
This project and repository does not have necessary things to do i18ns and/or translations.
4141

42-
If you want to do i18ns and/or translations on the documentations, documents and/or wiki, please see section "[Documentations, Documents & Wiki](#documentations-documents--wiki)".
42+
If you want to do i18ns and/or translations on the documentations, documents and/or wiki, please see the section "[Documentations, Documents & Wiki](#documentations-documents--wiki)".
4343

4444
## Issues
4545

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Please provide as much as you can to help the security vulnerability report supe
4646
- Your account's platform (e.g.: GitHub, GitLab, ...).
4747
- Your account's username (e.g.: `@octocat`).
4848
- Project's ID or repository URI.
49-
- Project's ID is displayed at the top part of Readme (file: `README.md`), below the project display name (i.e.: header), inside a code block.
49+
- Project's ID is displayed at the top part of the Readme (file: `README.md`), below the project display name (i.e.: header), inside a code block.
5050
- Affected branches, commits, tags, and/or versions.
5151
- Versions must be listed as supported.
5252
- For multiple versions, you can use version range instead.

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

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

244244
# Prerelease string of this module
245-
Prerelease = 'beta2'
245+
Prerelease = 'beta3'
246246

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

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ Import-Module -Name (
1111
.SYNOPSIS
1212
GitHub Actions - Export Artifact
1313
.DESCRIPTION
14-
Export artifact to persist data and/or share with future job in the same workflow.
14+
Export artifact to persist the data and/or share with the future jobs in the same workflow.
1515
.PARAMETER Name
1616
Name of the artifact.
1717
.PARAMETER Path
18-
Paths to the files that need to export as artifact.
18+
Paths of the files that need to export as artifact.
1919
.PARAMETER LiteralPath
20-
Literal paths to the files that need to export as artifact.
20+
Literal paths of the files that need to export as artifact.
2121
.PARAMETER BaseRoot
2222
Absolute literal path of the base root directory of the files for control files structure.
2323
.PARAMETER ContinueOnIssue
24-
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.
24+
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.
2525
.PARAMETER RetentionTime
26-
Duration of the artifact become expire, by days.
26+
Retention time of the artifact, by days.
2727
.OUTPUTS
2828
[PSCustomObject] Metadata of the exported artifact.
2929
#>
@@ -34,7 +34,7 @@ Function Export-Artifact {
3434
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][String]$Name,
3535
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
3636
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
37-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
37+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateScript({ [System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container') }, ErrorMessage = '`{0}` is not an exist and valid GitHub Actions artifact base root!')][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
3838
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('ContinueOnError')][Switch]$ContinueOnIssue,
3939
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('RetentionDay')][Byte]$RetentionTime
4040
)
@@ -48,12 +48,26 @@ Function Export-Artifact {
4848
If ($NoOperation) {
4949
Return
5050
}
51+
Switch ($PSCmdlet.ParameterSetName) {
52+
'LiteralPath' {
53+
[String[]]$PathsProceed = $LiteralPath |
54+
ForEach-Object -Process { [System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $BaseRoot -ChildPath $_) }
55+
}
56+
'Path' {
57+
[String[]]$PathsProceed = @()
58+
ForEach ($Item In $Path) {
59+
Try {
60+
$PathsProceed += Resolve-Path -Path ([System.IO.Path]::IsPathRooted($Item) ? $Item : (Join-Path -Path $BaseRoot -ChildPath $Item))
61+
}
62+
Catch {
63+
$PathsProceed += $Item
64+
}
65+
}
66+
}
67+
}
5168
[Hashtable]$InputObject = @{
5269
Name = $Name
53-
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
54-
$LiteralPath |
55-
ForEach-Object -Process { [WildcardPattern]::Escape($_) }
56-
) : $Path
70+
Path = $PathsProceed
5771
BaseRoot = $BaseRoot
5872
ContinueOnIssue = $ContinueOnIssue.IsPresent
5973
}
@@ -69,15 +83,15 @@ Set-Alias -Name 'Save-Artifact' -Value 'Export-Artifact' -Option 'ReadOnly' -Sco
6983
.SYNOPSIS
7084
GitHub Actions - Import Artifact
7185
.DESCRIPTION
72-
Import artifact that shared data from past job in the same workflow.
86+
Import artifact that shared the data from the past jobs in the same workflow.
7387
.PARAMETER Name
7488
Name of the artifact.
7589
.PARAMETER CreateSubfolder
76-
Whether to create a subfolder with artifact name and put data into here.
90+
Whether to create a subfolder with artifact name and put the data into there.
7791
.PARAMETER All
78-
Import all of the artifacts that shared data from past job in the same workflow; Always create subfolders.
92+
Import all of the artifacts that shared the data from the past jobs in the same workflow; Always create subfolders.
7993
.PARAMETER Destination
80-
Absolute literal path(s) of the destination of the artifact(s).
94+
Absolute literal path of the destination of the artifact(s).
8195
.OUTPUTS
8296
[PSCustomObject] Metadata of the imported artifact.
8397
[PSCustomObject[]] Metadata of the imported artifacts.
@@ -90,7 +104,7 @@ Function Import-Artifact {
90104
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][String]$Name,
91105
[Parameter(ParameterSetName = 'Single', ValueFromPipelineByPropertyName = $True)][Switch]$CreateSubfolder,
92106
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
93-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Dest', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
107+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Dest', 'Path', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
94108
)
95109
Begin {
96110
[Boolean]$NoOperation = !(Test-GitHubActionsEnvironment -Artifact)# When the requirements are not fulfill, only stop this function but not others.

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Import-Module -Name (
1111
.SYNOPSIS
1212
GitHub Actions - Restore Cache
1313
.DESCRIPTION
14-
Restore cache that shared data from past job in the same workflow.
14+
Restore cache that shared the data from the past jobs in the same workflow.
1515
.PARAMETER Key
16-
Key of the cache.
16+
Keys of the cache.
1717
.PARAMETER Path
1818
Paths of the cache.
1919
.PARAMETER LiteralPath
@@ -24,6 +24,8 @@ Whether to not use Azure Blob SDK to download the cache that stored on the Azure
2424
Number of parallel downloads of the cache (only for Azure SDK).
2525
.PARAMETER Timeout
2626
Maximum time for each download request of the cache, by seconds (only for Azure SDK).
27+
.PARAMETER SegmentTimeout
28+
Maximum time for each segment download request of the cache, by minutes; This allows the segment download to get aborted and hence allow the job to proceed with a cache miss.
2729
.OUTPUTS
2830
[String] The key of the cache hit.
2931
#>
@@ -36,30 +38,33 @@ Function Restore-Cache {
3638
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
3739
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('NoAzureSdk')][Switch]$NotUseAzureSdk,
3840
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Alias('Concurrency')][Byte]$DownloadConcurrency,
39-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(5, 900)][UInt16]$Timeout
41+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(5, 900)][UInt16]$Timeout,
42+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 360)][UInt16]$SegmentTimeout = 60
4043
)
4144
Begin {
4245
[Boolean]$NoOperation = !(Test-GitHubActionsEnvironment -Cache)# When the requirements are not fulfill, only stop this function but not others.
4346
If ($NoOperation) {
4447
Write-Error -Message 'Unable to get GitHub Actions cache resources!' -Category 'ResourceUnavailable'
4548
}
49+
$Env:SEGMENT_DOWNLOAD_TIMEOUT_MINS = $SegmentTimeout.ToString()
4650
}
4751
Process {
4852
If ($NoOperation) {
4953
Return
5054
}
5155
[Hashtable]$InputObject = @{
5256
PrimaryKey = $Key[0]
53-
RestoreKey = (
54-
$Key |
55-
Select-Object -SkipIndex 0
56-
) ?? @()
5757
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
5858
$LiteralPath |
5959
ForEach-Object -Process { [WildcardPattern]::Escape($_) }
6060
) : $Path
6161
UseAzureSdk = !$NotUseAzureSdk.IsPresent
6262
}
63+
[String[]]$RestoreKey = $Key |
64+
Select-Object -SkipIndex 0
65+
If ($RestoreKey.Count -igt 0) {
66+
$InputObject.RestoreKey = $RestoreKey
67+
}
6368
If (!$NotUseAzureSdk.IsPresent) {
6469
If ($DownloadConcurrency -igt 0) {
6570
$InputObject.DownloadConcurrency = $DownloadConcurrency
@@ -77,7 +82,7 @@ Set-Alias -Name 'Import-Cache' -Value 'Restore-Cache' -Option 'ReadOnly' -Scope
7782
.SYNOPSIS
7883
GitHub Actions - Save cache
7984
.DESCRIPTION
80-
Save cache to persist data and/or share with future job in the same workflow.
85+
Save cache to persist the data and/or share with the future jobs in the same workflow.
8186
.PARAMETER Key
8287
Key of the cache.
8388
.PARAMETER Path
@@ -96,8 +101,8 @@ Function Save-Cache {
96101
[OutputType([String])]
97102
Param (
98103
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('Name')][String]$Key,
99-
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
100-
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
104+
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
105+
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
101106
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 1MB)][Alias('ChunkSize', 'ChunkSizes', 'UploadChunkSize')][UInt32]$UploadChunkSizes,
102107
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Alias('Concurrency')][Byte]$UploadConcurrency
103108
)
@@ -129,27 +134,6 @@ Function Save-Cache {
129134
}
130135
}
131136
Set-Alias -Name 'Export-Cache' -Value 'Save-Cache' -Option 'ReadOnly' -Scope 'Local'
132-
<#
133-
.SYNOPSIS
134-
GitHub Actions (Private) - Test Cache Key
135-
.DESCRIPTION
136-
Test the key of the GitHub Actions cache whether is valid.
137-
.PARAMETER InputObject
138-
Key of the GitHub Actions cache that need to test.
139-
.OUTPUTS
140-
[Boolean] Test result.
141-
#>
142-
Function Test-CacheKey {
143-
[CmdletBinding()]
144-
[OutputType([Boolean])]
145-
Param (
146-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][Alias('Input', 'Object')][String]$InputObject
147-
)
148-
Process {
149-
$InputObject.Length -ile 512 -and $InputObject -imatch '^[^,\n\r]+$' |
150-
Write-Output
151-
}
152-
}
153137
Export-ModuleMember -Function @(
154138
'Restore-Cache',
155139
'Save-Cache'

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Import-Module -Name (
66
) |
77
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath $_ }
88
) -Prefix 'GitHubActions' -Scope 'Local'
9-
[String[]]$GitHubActionsFileCommandTokensUsed = @()
109
<#
1110
.SYNOPSIS
1211
GitHub Actions (Private) - Format Command Parameter Value
@@ -50,8 +49,11 @@ Function Format-CommandValue {
5049
Write-Output
5150
}
5251
}
53-
Set-Alias -Name 'Format-CommandContent' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
54-
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
52+
@(
53+
'Format-CommandContent',
54+
'Format-CommandMessage'
55+
) |
56+
Set-Alias -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
5557
<#
5658
.SYNOPSIS
5759
GitHub Actions - Write Command
@@ -106,19 +108,22 @@ Function Write-FileCommand {
106108
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][String]$Value
107109
)
108110
Process {
109-
Add-Content -LiteralPath $LiteralPath -Value $(
110-
If ($Value -imatch '^.+$') {
111-
Write-Output -InputObject "$($Name)=$($Value)"
111+
If ($Value -imatch '^.+$') {
112+
Add-Content -LiteralPath $LiteralPath -Value "$Name=$Value" -Confirm:$False -Encoding 'UTF8NoBOM'
113+
}
114+
Else {
115+
[String]$ItemRaw = "$Name=$Value" -ireplace '\r?\n', ''
116+
Do {
117+
[String]$Token = New-GitHubActionsRandomToken -Length 16
112118
}
113-
Else {
114-
Do {
115-
[String]$Token = New-GitHubActionsRandomToken -Length 64
116-
}
117-
While ( $Token -iin $GitHubActionsFileCommandTokensUsed )
118-
$Script:GitHubActionsFileCommandTokensUsed += $Token
119-
Write-Output -InputObject "$Name<<$Token`n$($Value -ireplace '\r?\n', "`n")`n$Token"
120-
}
121-
) -Confirm:$False -Encoding 'UTF8NoBOM'
119+
While ( $ItemRaw -imatch [RegEx]::Escape($Token) )
120+
@(
121+
"$Name<<$Token",
122+
$Value -ireplace '\r?\n', "`n",
123+
$Token
124+
) |
125+
Add-Content -LiteralPath $LiteralPath -Confirm:$False -Encoding 'UTF8NoBOM'
126+
}
122127
}
123128
}
124129
Export-ModuleMember -Function @(

0 commit comments

Comments
 (0)