mirror of
https://github.com/actions/download-artifact.git
synced 2025-08-20 14:39:53 +08:00
Compare commits
4 Commits
robherley/
...
konradpabj
Author | SHA1 | Date | |
---|---|---|---|
|
18323e2bed | ||
|
59c8579f60 | ||
|
ac384941b4 | ||
|
54ed8ca4ec |
10
action.yml
10
action.yml
@@ -9,18 +9,16 @@ inputs:
|
|||||||
description: 'Destination path'
|
description: 'Destination path'
|
||||||
required: false
|
required: false
|
||||||
github-token:
|
github-token:
|
||||||
description: 'The GitHub token used to authenticate with the GitHub API.
|
description: The GitHub token used to download the artifact
|
||||||
This is required when downloading artifacts from a different repository or from a different workflow run.
|
default: ${{ github.token }}
|
||||||
If this is not specified, the action will attempt to download artifacts from the current repository and the current workflow run.'
|
|
||||||
required: false
|
required: false
|
||||||
repository:
|
repository:
|
||||||
description: 'The repository owner and the repository name joined together by "/".
|
description: 'The repository owner and the repository name joined together by "/".
|
||||||
If github-token is specified, this is the repository that artifacts will be downloaded from.'
|
This specifies the repository that artifacts will be downloaded from. If downloading artifacts from external workflow runs or repositories then the above download-token must be permissions to this repository.'
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.repository }}
|
default: ${{ github.repository }}
|
||||||
run-id:
|
run-id:
|
||||||
description: 'The id of the workflow run where the desired download artifact was uploaded from.
|
description: 'The id of the workflow run where the desired download artifact was uploaded from. If downloading artifacts from anything other than the current workflow run then this needs to be overwritten.'
|
||||||
If github-token is specified, this is the run that artifacts will be downloaded from.'
|
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.run_id }}
|
default: ${{ github.run_id }}
|
||||||
outputs:
|
outputs:
|
||||||
|
1130
dist/index.js
vendored
1130
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
|
||||||
@@ -18,9 +17,9 @@ async function run(): Promise<void> {
|
|||||||
const inputs = {
|
const inputs = {
|
||||||
name: core.getInput(Inputs.Name, {required: false}),
|
name: core.getInput(Inputs.Name, {required: false}),
|
||||||
path: core.getInput(Inputs.Path, {required: false}),
|
path: core.getInput(Inputs.Path, {required: false}),
|
||||||
token: core.getInput(Inputs.GitHubToken, {required: false}),
|
token: core.getInput(Inputs.GitHubToken, {required: true}),
|
||||||
repository: core.getInput(Inputs.Repository, {required: false}),
|
repository: core.getInput(Inputs.Repository, {required: true}),
|
||||||
runID: parseInt(core.getInput(Inputs.RunID, {required: false}))
|
runID: parseInt(core.getInput(Inputs.RunID, {required: true}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputs.path) {
|
if (!inputs.path) {
|
||||||
@@ -31,35 +30,29 @@ async function run(): Promise<void> {
|
|||||||
inputs.path = inputs.path.replace('~', os.homedir())
|
inputs.path = inputs.path.replace('~', os.homedir())
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSingleArtifactDownload = !!inputs.name
|
const isSingleArtifactDownload: boolean = !!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 [owner, repo] = inputs.repository.split('/')
|
||||||
if (inputs.token) {
|
if (!owner || !repo) {
|
||||||
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
|
|
||||||
if (!repositoryOwner || !repositoryName) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`
|
`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
options.findBy = {
|
const artifactClient = artifact.create()
|
||||||
token: inputs.token,
|
let artifacts: artifact.Artifact[] = []
|
||||||
workflowRunId: inputs.runID,
|
|
||||||
repositoryName,
|
|
||||||
repositoryOwner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let artifacts: Artifact[] = []
|
|
||||||
|
|
||||||
if (isSingleArtifactDownload) {
|
if (isSingleArtifactDownload) {
|
||||||
core.info(`Downloading single artifact`)
|
core.info(`Downloading single artifact`)
|
||||||
|
|
||||||
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
||||||
inputs.name,
|
inputs.name,
|
||||||
options
|
inputs.runID,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
inputs.token
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!targetArtifact) {
|
if (!targetArtifact) {
|
||||||
@@ -72,14 +65,14 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
artifacts = [targetArtifact]
|
artifacts = [targetArtifact]
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`)
|
||||||
`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`
|
|
||||||
)
|
|
||||||
|
|
||||||
const listArtifactResponse = await artifactClient.listArtifacts({
|
const listArtifactResponse = await artifactClient.listArtifacts(
|
||||||
latest: true,
|
inputs.runID,
|
||||||
...options
|
owner,
|
||||||
})
|
repo,
|
||||||
|
inputs.token
|
||||||
|
)
|
||||||
|
|
||||||
if (listArtifactResponse.artifacts.length === 0) {
|
if (listArtifactResponse.artifacts.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -92,11 +85,8 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const downloadPromises = artifacts.map(artifact =>
|
const downloadPromises = artifacts.map(artifact =>
|
||||||
artifactClient.downloadArtifact(artifact.id, {
|
artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, {
|
||||||
...options,
|
path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name)
|
||||||
path: isSingleArtifactDownload
|
|
||||||
? resolvedPath
|
|
||||||
: path.join(resolvedPath, artifact.name)
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user