mirror of https://github.com/actions/toolkit
consistent promise behavior for download artifact
parent
d3c5f358d1
commit
ce9eae0785
|
@ -164,7 +164,6 @@ describe('download-artifact', () => {
|
||||||
fixtures.blobStorageUrl
|
fixtures.blobStorageUrl
|
||||||
)
|
)
|
||||||
expectExtractedArchive(fixtures.workspaceDir)
|
expectExtractedArchive(fixtures.workspaceDir)
|
||||||
expect(response.success).toBe(true)
|
|
||||||
expect(response.downloadPath).toBe(fixtures.workspaceDir)
|
expect(response.downloadPath).toBe(fixtures.workspaceDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -214,7 +213,6 @@ describe('download-artifact', () => {
|
||||||
fixtures.blobStorageUrl
|
fixtures.blobStorageUrl
|
||||||
)
|
)
|
||||||
expectExtractedArchive(customPath)
|
expectExtractedArchive(customPath)
|
||||||
expect(response.success).toBe(true)
|
|
||||||
expect(response.downloadPath).toBe(customPath)
|
expect(response.downloadPath).toBe(customPath)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -344,7 +342,6 @@ describe('download-artifact', () => {
|
||||||
const response = await downloadArtifactInternal(fixtures.artifactID)
|
const response = await downloadArtifactInternal(fixtures.artifactID)
|
||||||
|
|
||||||
expectExtractedArchive(fixtures.workspaceDir)
|
expectExtractedArchive(fixtures.workspaceDir)
|
||||||
expect(response.success).toBe(true)
|
|
||||||
expect(response.downloadPath).toBe(fixtures.workspaceDir)
|
expect(response.downloadPath).toBe(fixtures.workspaceDir)
|
||||||
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
|
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
|
||||||
expect(mockListArtifacts).toHaveBeenCalledWith({
|
expect(mockListArtifacts).toHaveBeenCalledWith({
|
||||||
|
@ -396,7 +393,6 @@ describe('download-artifact', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
expectExtractedArchive(customPath)
|
expectExtractedArchive(customPath)
|
||||||
expect(response.success).toBe(true)
|
|
||||||
expect(response.downloadPath).toBe(customPath)
|
expect(response.downloadPath).toBe(customPath)
|
||||||
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
|
expect(mockHttpClient).toHaveBeenCalledWith(getUserAgentString())
|
||||||
expect(mockListArtifacts).toHaveBeenCalledWith({
|
expect(mockListArtifacts).toHaveBeenCalledWith({
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
ListArtifactsRequest
|
ListArtifactsRequest
|
||||||
} from '../../generated'
|
} from '../../generated'
|
||||||
import {getBackendIdsFromToken} from '../shared/util'
|
import {getBackendIdsFromToken} from '../shared/util'
|
||||||
|
import {ArtifactNotFoundError} from '../shared/errors'
|
||||||
|
|
||||||
const scrubQueryParameters = (url: string): string => {
|
const scrubQueryParameters = (url: string): string => {
|
||||||
const parsed = new URL(url)
|
const parsed = new URL(url)
|
||||||
|
@ -95,7 +96,7 @@ export async function downloadArtifactPublic(
|
||||||
throw new Error(`Unable to download and extract artifact: ${error.message}`)
|
throw new Error(`Unable to download and extract artifact: ${error.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {success: true, downloadPath}
|
return {downloadPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadArtifactInternal(
|
export async function downloadArtifactInternal(
|
||||||
|
@ -118,10 +119,9 @@ export async function downloadArtifactInternal(
|
||||||
const {artifacts} = await artifactClient.ListArtifacts(listReq)
|
const {artifacts} = await artifactClient.ListArtifacts(listReq)
|
||||||
|
|
||||||
if (artifacts.length === 0) {
|
if (artifacts.length === 0) {
|
||||||
core.warning(
|
throw new ArtifactNotFoundError(
|
||||||
`No artifacts found for ID: ${artifactId}\nAre you trying to download from a different run? Try specifying a github-token with \`actions:read\` scope.`
|
`No artifacts found for ID: ${artifactId}\nAre you trying to download from a different run? Try specifying a github-token with \`actions:read\` scope.`
|
||||||
)
|
)
|
||||||
return {success: false}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artifacts.length > 1) {
|
if (artifacts.length > 1) {
|
||||||
|
@ -148,7 +148,7 @@ export async function downloadArtifactInternal(
|
||||||
throw new Error(`Unable to download and extract artifact: ${error.message}`)
|
throw new Error(`Unable to download and extract artifact: ${error.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {success: true, downloadPath}
|
return {downloadPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolveOrCreateDirectory(
|
async function resolveOrCreateDirectory(
|
||||||
|
|
|
@ -48,7 +48,9 @@ export async function getArtifactPublic(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getArtifactResp.data.artifacts.length === 0) {
|
if (getArtifactResp.data.artifacts.length === 0) {
|
||||||
throw new ArtifactNotFoundError(artifactName)
|
throw new ArtifactNotFoundError(
|
||||||
|
`Artifact not found for name: ${artifactName}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let artifact = getArtifactResp.data.artifacts[0]
|
let artifact = getArtifactResp.data.artifacts[0]
|
||||||
|
@ -86,7 +88,9 @@ export async function getArtifactInternal(
|
||||||
const res = await artifactClient.ListArtifacts(req)
|
const res = await artifactClient.ListArtifacts(req)
|
||||||
|
|
||||||
if (res.artifacts.length === 0) {
|
if (res.artifacts.length === 0) {
|
||||||
throw new ArtifactNotFoundError(artifactName)
|
throw new ArtifactNotFoundError(
|
||||||
|
`Artifact not found for name: ${artifactName}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let artifact = res.artifacts[0]
|
let artifact = res.artifacts[0]
|
||||||
|
|
|
@ -21,8 +21,7 @@ export class InvalidResponseError extends Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ArtifactNotFoundError extends Error {
|
export class ArtifactNotFoundError extends Error {
|
||||||
constructor(name: string) {
|
constructor(message = 'Artifact not found') {
|
||||||
const message = `No artifact found for name: ${name}`
|
|
||||||
super(message)
|
super(message)
|
||||||
this.name = 'ArtifactNotFoundError'
|
this.name = 'ArtifactNotFoundError'
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,6 @@ export interface ListArtifactsResponse {
|
||||||
* *
|
* *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
export interface DownloadArtifactResponse {
|
export interface DownloadArtifactResponse {
|
||||||
/**
|
|
||||||
* If the artifact download was successful
|
|
||||||
*/
|
|
||||||
success: boolean
|
|
||||||
/**
|
/**
|
||||||
* The path where the artifact was downloaded to
|
* The path where the artifact was downloaded to
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue