mirror of
https://github.com/actions/download-artifact.git
synced 2025-08-22 23:51:19 +08:00
Compare commits
10 Commits
v4-beta-in
...
patch-zip-
Author | SHA1 | Date | |
---|---|---|---|
|
d2e17e8b67 | ||
|
621be0be95 | ||
|
5be1d38671 | ||
|
465b526e63 | ||
|
8b83831f82 | ||
|
0742efc19b | ||
|
5e4b342272 | ||
|
98c6f16055 | ||
|
9140050fd5 | ||
|
88dadfbcfc |
20551
dist/index.js
vendored
20551
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,8 @@
|
|||||||
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 * as artifact from '@actions/artifact'
|
import artifactClient 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
|
||||||
@@ -30,10 +31,11 @@ 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: artifact.FindOptions = {}
|
const options: 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) {
|
||||||
@@ -50,10 +52,11 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const artifactClient = artifact.create()
|
let artifacts: Artifact[] = []
|
||||||
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
|
||||||
@@ -63,12 +66,20 @@ async function run(): Promise<void> {
|
|||||||
throw new Error(`Artifact '${inputs.name}' not found`)
|
throw new Error(`Artifact '${inputs.name}' not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug('Found named artifact:')
|
core.debug(
|
||||||
core.debug(JSON.stringify(targetArtifact, null, 2))
|
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
|
||||||
|
)
|
||||||
|
|
||||||
artifacts = [targetArtifact]
|
artifacts = [targetArtifact]
|
||||||
} else {
|
} else {
|
||||||
const listArtifactResponse = await artifactClient.listArtifacts(options)
|
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
|
||||||
|
})
|
||||||
|
|
||||||
if (listArtifactResponse.artifacts.length === 0) {
|
if (listArtifactResponse.artifacts.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -76,15 +87,16 @@ 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: path.join(resolvedPath, artifact.name)
|
path: isSingleArtifactDownload
|
||||||
|
? resolvedPath
|
||||||
|
: path.join(resolvedPath, artifact.name)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user