1
0
mirror of https://github.com/actions/download-artifact.git synced 2025-12-06 09:47:49 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Rob Herley
ed25d4d912 more debug logs 2023-11-30 22:06:26 -05:00
Rob Herley
db146faf7b tsc & ncc 2023-11-30 21:37:48 -05:00
Rob Herley
6ee005d6b7 adopt new internal artifact api behavior 2023-11-30 21:37:06 -05:00
2 changed files with 18241 additions and 2558 deletions

20765
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,7 @@
import * as os from 'os'
import * as path from 'path'
import * as core from '@actions/core'
import artifactClient from '@actions/artifact'
import type {Artifact, FindOptions} from '@actions/artifact'
import * as artifact from '@actions/artifact'
import {Inputs, Outputs} from './constants'
const PARALLEL_DOWNLOADS = 5
@@ -31,11 +30,10 @@ async function run(): Promise<void> {
inputs.path = inputs.path.replace('~', os.homedir())
}
const isSingleArtifactDownload = !!inputs.name
const resolvedPath = path.resolve(inputs.path)
core.debug(`Resolved path is ${resolvedPath}`)
const options: FindOptions = {}
const options: artifact.FindOptions = {}
if (inputs.token) {
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
if (!repositoryOwner || !repositoryName) {
@@ -52,11 +50,10 @@ async function run(): Promise<void> {
}
}
let artifacts: Artifact[] = []
if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`)
const artifactClient = artifact.create()
let artifacts: artifact.Artifact[] = []
if (inputs.name) {
const {artifact: targetArtifact} = await artifactClient.getArtifact(
inputs.name,
options
@@ -66,20 +63,12 @@ async function run(): Promise<void> {
throw new Error(`Artifact '${inputs.name}' not found`)
}
core.debug(
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
)
core.debug('Found named artifact:')
core.debug(JSON.stringify(targetArtifact, null, 2))
artifacts = [targetArtifact]
} else {
core.info(
`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`
)
const listArtifactResponse = await artifactClient.listArtifacts({
latest: true,
...options
})
const listArtifactResponse = await artifactClient.listArtifacts(options)
if (listArtifactResponse.artifacts.length === 0) {
throw new Error(
@@ -87,16 +76,15 @@ async function run(): Promise<void> {
)
}
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`)
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`)
core.debug(JSON.stringify(listArtifactResponse, null, 2))
artifacts = listArtifactResponse.artifacts
}
const downloadPromises = artifacts.map(artifact =>
artifactClient.downloadArtifact(artifact.id, {
...options,
path: isSingleArtifactDownload
? resolvedPath
: path.join(resolvedPath, artifact.name)
path: path.join(resolvedPath, artifact.name)
})
)