mirror of
https://github.com/actions/download-artifact.git
synced 2025-08-20 14:39:53 +08:00
Compare commits
10 Commits
v4-beta-in
...
patch-zip-
Author | SHA1 | Date | |
---|---|---|---|
|
d2e17e8b67 | ||
|
621be0be95 | ||
|
5be1d38671 | ||
|
465b526e63 | ||
|
8b83831f82 | ||
|
0742efc19b | ||
|
5e4b342272 | ||
|
98c6f16055 | ||
|
9140050fd5 | ||
|
88dadfbcfc |
20731
dist/index.js
vendored
20731
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 path from 'path'
|
||||
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'
|
||||
|
||||
const PARALLEL_DOWNLOADS = 5
|
||||
@@ -30,10 +31,11 @@ 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: artifact.FindOptions = {}
|
||||
const options: FindOptions = {}
|
||||
if (inputs.token) {
|
||||
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
|
||||
if (!repositoryOwner || !repositoryName) {
|
||||
@@ -50,10 +52,11 @@ async function run(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const artifactClient = artifact.create()
|
||||
let artifacts: artifact.Artifact[] = []
|
||||
let artifacts: Artifact[] = []
|
||||
|
||||
if (isSingleArtifactDownload) {
|
||||
core.info(`Downloading single artifact`)
|
||||
|
||||
if (inputs.name) {
|
||||
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
||||
inputs.name,
|
||||
options
|
||||
@@ -63,12 +66,20 @@ async function run(): Promise<void> {
|
||||
throw new Error(`Artifact '${inputs.name}' not found`)
|
||||
}
|
||||
|
||||
core.debug('Found named artifact:')
|
||||
core.debug(JSON.stringify(targetArtifact, null, 2))
|
||||
core.debug(
|
||||
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
|
||||
)
|
||||
|
||||
artifacts = [targetArtifact]
|
||||
} 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) {
|
||||
throw new Error(
|
||||
@@ -76,15 +87,16 @@ async function run(): Promise<void> {
|
||||
)
|
||||
}
|
||||
|
||||
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`)
|
||||
core.debug(JSON.stringify(listArtifactResponse, null, 2))
|
||||
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`)
|
||||
artifacts = listArtifactResponse.artifacts
|
||||
}
|
||||
|
||||
const downloadPromises = artifacts.map(artifact =>
|
||||
artifactClient.downloadArtifact(artifact.id, {
|
||||
...options,
|
||||
path: path.join(resolvedPath, artifact.name)
|
||||
path: isSingleArtifactDownload
|
||||
? resolvedPath
|
||||
: path.join(resolvedPath, artifact.name)
|
||||
})
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user