mirror of
https://github.com/actions/download-artifact.git
synced 2025-08-15 05:05:05 +00:00
Download artifacts to dedicated subfolder when no name or id specified
This commit is contained in:
parent
de96f4613b
commit
73a7c368bf
@ -406,4 +406,122 @@ describe('download', () => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('downloads single artifact to dedicated folders named after the artifact within provided path', async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
|
||||||
|
const testPath = '/test/path'
|
||||||
|
const mockArtifacts = [
|
||||||
|
{id: 101, name: 'frontend-build', size: 2048, digest: 'abc123'}
|
||||||
|
]
|
||||||
|
|
||||||
|
mockInputs({
|
||||||
|
[Inputs.Name]: '',
|
||||||
|
[Inputs.Pattern]: '',
|
||||||
|
[Inputs.ArtifactIds]: '',
|
||||||
|
[Inputs.Path]: testPath,
|
||||||
|
[Inputs.MergeMultiple]: false
|
||||||
|
})
|
||||||
|
|
||||||
|
jest
|
||||||
|
.spyOn(artifact, 'listArtifacts')
|
||||||
|
.mockImplementation(() => Promise.resolve({artifacts: mockArtifacts}))
|
||||||
|
|
||||||
|
jest
|
||||||
|
.spyOn(artifact, 'downloadArtifact')
|
||||||
|
.mockImplementation(() => Promise.resolve({digestMismatch: false}))
|
||||||
|
|
||||||
|
await run()
|
||||||
|
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
|
// Verify the artifact is downloaded to its own folder within the provided path
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
|
||||||
|
101,
|
||||||
|
expect.objectContaining({
|
||||||
|
path: path.join(path.resolve(testPath), 'frontend-build'),
|
||||||
|
expectedHash: 'abc123'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
'No input name, artifact-ids or pattern filtered specified, downloading all artifacts'
|
||||||
|
)
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
'An extra directory with the artifact name will be created for each download'
|
||||||
|
)
|
||||||
|
expect(core.info).toHaveBeenCalledWith('Total of 1 artifact(s) downloaded')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'download-path',
|
||||||
|
path.resolve(testPath)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('downloads multiple artifacts to separate folders named after each artifact within provided path', async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
|
||||||
|
const testPath = '/test/path'
|
||||||
|
const mockArtifacts = [
|
||||||
|
{id: 101, name: 'frontend-build', size: 2048, digest: 'abc123'},
|
||||||
|
{id: 102, name: 'backend-build', size: 4096, digest: 'def456'},
|
||||||
|
{id: 103, name: 'test-results', size: 1024, digest: 'ghi789'}
|
||||||
|
]
|
||||||
|
|
||||||
|
mockInputs({
|
||||||
|
[Inputs.Name]: '',
|
||||||
|
[Inputs.Pattern]: '',
|
||||||
|
[Inputs.ArtifactIds]: '',
|
||||||
|
[Inputs.Path]: testPath,
|
||||||
|
[Inputs.MergeMultiple]: false
|
||||||
|
})
|
||||||
|
|
||||||
|
jest
|
||||||
|
.spyOn(artifact, 'listArtifacts')
|
||||||
|
.mockImplementation(() => Promise.resolve({artifacts: mockArtifacts}))
|
||||||
|
|
||||||
|
jest
|
||||||
|
.spyOn(artifact, 'downloadArtifact')
|
||||||
|
.mockImplementation(() => Promise.resolve({digestMismatch: false}))
|
||||||
|
|
||||||
|
await run()
|
||||||
|
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledTimes(3)
|
||||||
|
|
||||||
|
// Verify each artifact is downloaded to its own folder within the provided path
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
|
||||||
|
101,
|
||||||
|
expect.objectContaining({
|
||||||
|
path: path.join(path.resolve(testPath), 'frontend-build'),
|
||||||
|
expectedHash: 'abc123'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
|
||||||
|
102,
|
||||||
|
expect.objectContaining({
|
||||||
|
path: path.join(path.resolve(testPath), 'backend-build'),
|
||||||
|
expectedHash: 'def456'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
|
||||||
|
103,
|
||||||
|
expect.objectContaining({
|
||||||
|
path: path.join(path.resolve(testPath), 'test-results'),
|
||||||
|
expectedHash: 'ghi789'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
'No input name, artifact-ids or pattern filtered specified, downloading all artifacts'
|
||||||
|
)
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
'An extra directory with the artifact name will be created for each download'
|
||||||
|
)
|
||||||
|
expect(core.info).toHaveBeenCalledWith('Total of 3 artifact(s) downloaded')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'download-path',
|
||||||
|
path.resolve(testPath)
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -176,7 +176,7 @@ export async function run(): Promise<void> {
|
|||||||
path:
|
path:
|
||||||
isSingleArtifactDownload ||
|
isSingleArtifactDownload ||
|
||||||
inputs.mergeMultiple ||
|
inputs.mergeMultiple ||
|
||||||
artifacts.length === 1
|
(artifacts.length === 1 && isDownloadByIds)
|
||||||
? resolvedPath
|
? resolvedPath
|
||||||
: path.join(resolvedPath, artifact.name),
|
: path.join(resolvedPath, artifact.name),
|
||||||
expectedHash: artifact.digest
|
expectedHash: artifact.digest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user