feat: add support for unzip argument in downloadArtifact (#1)

This commit is contained in:
Shiipou 2025-12-03 14:09:44 +01:00 committed by shiipou
parent f093f21ca4
commit 0f36edbf53
5 changed files with 43885 additions and 12190 deletions

View File

@ -50,13 +50,15 @@ jobs:
echo "Lorem ipsum dolor sit amet" > path/to/artifact-A/file-A.txt
echo "Hello world from file B" > path/to/artifact-B/file-B.txt
- name: Upload artifact A
- id: artifact-a
name: Upload artifact A
uses: actions/upload-artifact@v4
with:
name: Artifact-A-${{ matrix.runs-on }}
path: path/to/artifact-A
- name: Upload artifact B
- id: artifact-b
name: Upload artifact B
uses: actions/upload-artifact@v4
with:
name: Artifact-B-${{ matrix.runs-on }}
@ -131,3 +133,63 @@ jobs:
Write-Error "File contents of downloaded artifacts are incorrect"
}
shell: pwsh
# Test glob downloading both artifacts to same directory in zip format
- name: Download all Zipped Artifacts
uses: ./
with:
pattern: Artifact-*
unzip: false
path: single/directory
merge-multiple: true
- name: Verify successful download
run: |
$fileA = "$(ls single/directory/Artifact-A-*.zip)"
$fileB = "$(ls single/directory/Artifact-B-*.zip)"
if(!(Test-Path -path $fileA) -or !(Test-Path -path $fileB))
{
Write-Error "Expected files do not exist"
}
unzip $fileA -d single/directory/
unzip $fileB -d single/directory/
$fileA = "single/directory/file-A.txt"
$fileB = "single/directory/file-B.txt"
if(!((Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $fileB) -ceq "Hello world from file B"))
{
Write-Error "File contents of downloaded artifacts are incorrect"
}
shell: pwsh
# Test glob downloading both artifacts using it's ids to same directory in zip format
- name: Download all Zipped Artifacts
uses: ./
with:
artifact-ids: ${{ steps.artifact-a.outputs.artifact-id }},${{ steps.artifact-b.outputs.artifact-id }}
unzip: false
path: single/directory
merge-multiple: true
- name: Verify successful download
run: |
$fileA = "$(ls single/directory/Artifact-A-*.zip)"
$fileB = "$(ls single/directory/Artifact-B-*.zip)"
if(!(Test-Path -path $fileA) -or !(Test-Path -path $fileB))
{
Write-Error "Expected files do not exist"
}
unzip $fileA -d single/directory/
unzip $fileB -d single/directory/
$fileA = "single/directory/file-A.txt"
$fileB = "single/directory/file-B.txt"
if(!((Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $fileB) -ceq "Hello world from file B"))
{
Write-Error "File contents of downloaded artifacts are incorrect"
}
shell: pwsh

View File

@ -8,6 +8,10 @@ inputs:
artifact-ids:
description: 'IDs of the artifacts to download, comma-separated. Either inputs `artifact-ids` or `name` can be used, but not both.'
required: false
unzip:
description: 'Whenever to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".'
required: false
default: '*'
path:
description: 'Destination path. Supports basic tilde expansion. Defaults to $GITHUB_WORKSPACE'
required: false

55967
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,8 @@ export enum Inputs {
RunID = 'run-id',
Pattern = 'pattern',
MergeMultiple = 'merge-multiple',
ArtifactIds = 'artifact-ids'
ArtifactIds = 'artifact-ids',
UnZip = "unzip"
}
export enum Outputs {

View File

@ -26,7 +26,8 @@ export async function run(): Promise<void> {
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {
required: false
}),
artifactIds: core.getInput(Inputs.ArtifactIds, {required: false})
artifactIds: core.getInput(Inputs.ArtifactIds, {required: false}),
unzip: core.getInput(Inputs.UnZip, {required: false})
}
if (!inputs.path) {
@ -169,19 +170,25 @@ export async function run(): Promise<void> {
})
}
const downloadPromises = artifacts.map(artifact => ({
name: artifact.name,
promise: artifactClient.downloadArtifact(artifact.id, {
...options,
path:
isSingleArtifactDownload ||
inputs.mergeMultiple ||
artifacts.length === 1
? resolvedPath
: path.join(resolvedPath, artifact.name),
expectedHash: artifact.digest
})
}))
const unzip_list = inputs.unzip.split(',');
const downloadPromises = artifacts.map(artifact => {
const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name);
return {
name: artifact.name,
promise: artifactClient.downloadArtifact(artifact.id, {
...options,
unzip,
artifactName: artifact.name,
path:
isSingleArtifactDownload ||
inputs.mergeMultiple ||
artifacts.length === 1
? resolvedPath
: path.join(resolvedPath, artifact.name),
expectedHash: artifact.digest
})
};
});
const chunkedPromises = chunk(downloadPromises, PARALLEL_DOWNLOADS)
for (const chunk of chunkedPromises) {