mirror of
https://github.com/actions/download-artifact.git
synced 2025-12-06 22:35:36 +08:00
Compare commits
3 Commits
robherley/
...
v4-beta-in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed25d4d912 | ||
|
|
db146faf7b | ||
|
|
6ee005d6b7 |
20772
dist/index.js
vendored
20772
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,7 @@
|
|||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import artifactClient from '@actions/artifact'
|
import * as artifact from '@actions/artifact'
|
||||||
import type {Artifact, FindOptions} from '@actions/artifact'
|
|
||||||
import {Inputs, Outputs} from './constants'
|
import {Inputs, Outputs} from './constants'
|
||||||
|
|
||||||
const PARALLEL_DOWNLOADS = 5
|
const PARALLEL_DOWNLOADS = 5
|
||||||
@@ -31,11 +30,10 @@ async function run(): Promise<void> {
|
|||||||
inputs.path = inputs.path.replace('~', os.homedir())
|
inputs.path = inputs.path.replace('~', os.homedir())
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSingleArtifactDownload = !!inputs.name
|
|
||||||
const resolvedPath = path.resolve(inputs.path)
|
const resolvedPath = path.resolve(inputs.path)
|
||||||
core.debug(`Resolved path is ${resolvedPath}`)
|
core.debug(`Resolved path is ${resolvedPath}`)
|
||||||
|
|
||||||
const options: FindOptions = {}
|
const options: artifact.FindOptions = {}
|
||||||
if (inputs.token) {
|
if (inputs.token) {
|
||||||
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
|
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
|
||||||
if (!repositoryOwner || !repositoryName) {
|
if (!repositoryOwner || !repositoryName) {
|
||||||
@@ -52,11 +50,10 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let artifacts: Artifact[] = []
|
const artifactClient = artifact.create()
|
||||||
|
let artifacts: artifact.Artifact[] = []
|
||||||
if (isSingleArtifactDownload) {
|
|
||||||
core.info(`Downloading single artifact`)
|
|
||||||
|
|
||||||
|
if (inputs.name) {
|
||||||
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
||||||
inputs.name,
|
inputs.name,
|
||||||
options
|
options
|
||||||
@@ -66,20 +63,12 @@ async function run(): Promise<void> {
|
|||||||
throw new Error(`Artifact '${inputs.name}' not found`)
|
throw new Error(`Artifact '${inputs.name}' not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(
|
core.debug('Found named artifact:')
|
||||||
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
|
core.debug(JSON.stringify(targetArtifact, null, 2))
|
||||||
)
|
|
||||||
|
|
||||||
artifacts = [targetArtifact]
|
artifacts = [targetArtifact]
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
const listArtifactResponse = await artifactClient.listArtifacts(options)
|
||||||
`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
|
|
||||||
})
|
|
||||||
|
|
||||||
if (listArtifactResponse.artifacts.length === 0) {
|
if (listArtifactResponse.artifacts.length === 0) {
|
||||||
throw new Error(
|
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
|
artifacts = listArtifactResponse.artifacts
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadPromises = artifacts.map(artifact =>
|
const downloadPromises = artifacts.map(artifact =>
|
||||||
artifactClient.downloadArtifact(artifact.id, {
|
artifactClient.downloadArtifact(artifact.id, {
|
||||||
...options,
|
...options,
|
||||||
path: isSingleArtifactDownload
|
path: path.join(resolvedPath, artifact.name)
|
||||||
? resolvedPath
|
|
||||||
: path.join(resolvedPath, artifact.name)
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user