Skip to content

Commit fff8c14

Browse files
committed
fix download path logic when downloading a single artifact by id
1 parent 448e3f8 commit fff8c14

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

__tests__/download.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,37 @@ describe('download', () => {
371371
"Inputs 'name' and 'artifact-ids' cannot be used together. Please specify only one."
372372
)
373373
})
374+
375+
test('downloads single artifact by ID to same path as by name', async () => {
376+
const mockArtifact = {
377+
id: 456,
378+
name: 'test-artifact',
379+
size: 1024,
380+
digest: 'def456'
381+
}
382+
383+
mockInputs({
384+
[Inputs.Name]: '',
385+
[Inputs.Pattern]: '',
386+
[Inputs.ArtifactIds]: '456',
387+
[Inputs.Path]: '/test/path'
388+
})
389+
390+
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
391+
Promise.resolve({
392+
artifacts: [mockArtifact]
393+
})
394+
)
395+
396+
await run()
397+
398+
// Verify it downloads directly to the specified path (not nested in artifact name subdirectory)
399+
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
400+
456,
401+
expect.objectContaining({
402+
path: '/test/path', // Should be the resolved path directly, not /test/path/test-artifact
403+
expectedHash: mockArtifact.digest
404+
})
405+
)
406+
})
374407
})

src/download-artifact.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export async function run(): Promise<void> {
174174
promise: artifactClient.downloadArtifact(artifact.id, {
175175
...options,
176176
path:
177-
isSingleArtifactDownload || inputs.mergeMultiple
177+
isSingleArtifactDownload ||
178+
inputs.mergeMultiple ||
179+
artifacts.length === 1
178180
? resolvedPath
179181
: path.join(resolvedPath, artifact.name),
180182
expectedHash: artifact.digest

0 commit comments

Comments
 (0)