fix download path logic when downloading a single artifact by id

This commit is contained in:
GrantBirki 2025-08-05 10:56:18 -07:00
parent 448e3f862a
commit fff8c148a8
No known key found for this signature in database
GPG Key ID: 65497A530F6F9405
2 changed files with 36 additions and 1 deletions

View File

@ -371,4 +371,37 @@ describe('download', () => {
"Inputs 'name' and 'artifact-ids' cannot be used together. Please specify only one." "Inputs 'name' and 'artifact-ids' cannot be used together. Please specify only one."
) )
}) })
test('downloads single artifact by ID to same path as by name', async () => {
const mockArtifact = {
id: 456,
name: 'test-artifact',
size: 1024,
digest: 'def456'
}
mockInputs({
[Inputs.Name]: '',
[Inputs.Pattern]: '',
[Inputs.ArtifactIds]: '456',
[Inputs.Path]: '/test/path'
})
jest.spyOn(artifact, 'listArtifacts').mockImplementation(() =>
Promise.resolve({
artifacts: [mockArtifact]
})
)
await run()
// Verify it downloads directly to the specified path (not nested in artifact name subdirectory)
expect(artifact.downloadArtifact).toHaveBeenCalledWith(
456,
expect.objectContaining({
path: '/test/path', // Should be the resolved path directly, not /test/path/test-artifact
expectedHash: mockArtifact.digest
})
)
})
}) })

View File

@ -174,7 +174,9 @@ export async function run(): Promise<void> {
promise: artifactClient.downloadArtifact(artifact.id, { promise: artifactClient.downloadArtifact(artifact.id, {
...options, ...options,
path: path:
isSingleArtifactDownload || inputs.mergeMultiple isSingleArtifactDownload ||
inputs.mergeMultiple ||
artifacts.length === 1
? resolvedPath ? resolvedPath
: path.join(resolvedPath, artifact.name), : path.join(resolvedPath, artifact.name),
expectedHash: artifact.digest expectedHash: artifact.digest