From fff8c148a8fdd56aa81fcb019f0b5f6c65700c4d Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Tue, 5 Aug 2025 10:56:18 -0700 Subject: [PATCH] fix download path logic when downloading a single artifact by id --- __tests__/download.test.ts | 33 +++++++++++++++++++++++++++++++++ src/download-artifact.ts | 4 +++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/__tests__/download.test.ts b/__tests__/download.test.ts index 032d857..8901ac3 100644 --- a/__tests__/download.test.ts +++ b/__tests__/download.test.ts @@ -371,4 +371,37 @@ describe('download', () => { "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 + }) + ) + }) }) diff --git a/src/download-artifact.ts b/src/download-artifact.ts index 5cc6b17..6f2d782 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -174,7 +174,9 @@ export async function run(): Promise { promise: artifactClient.downloadArtifact(artifact.id, { ...options, path: - isSingleArtifactDownload || inputs.mergeMultiple + isSingleArtifactDownload || + inputs.mergeMultiple || + artifacts.length === 1 ? resolvedPath : path.join(resolvedPath, artifact.name), expectedHash: artifact.digest