Compare commits

..

1 Commits

Author SHA1 Message Date
Rob Herley
9140050fd5 consume latest @actions/artifact from toolkit 2023-11-20 20:57:50 -05:00
3 changed files with 130 additions and 776 deletions

View File

@@ -9,23 +9,21 @@ 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:
download-path: download-path:
description: 'Path of artifact download' description: 'Path of artifact download'
runs: runs:
using: 'node20' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

843
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -17,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) {
@@ -33,42 +33,41 @@ async function run(): Promise<void> {
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 [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 = {
token: inputs.token,
workflowRunId: inputs.runID,
repositoryName,
repositoryOwner
}
}
const artifactClient = artifact.create() const artifactClient = artifact.create()
let artifacts: artifact.Artifact[] = [] let artifacts: artifact.Artifact[] = []
if (inputs.name) { if (inputs.name) {
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) {
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) const listArtifactResponse = await artifactClient.listArtifacts(
inputs.runID,
owner,
repo,
inputs.token
)
if (listArtifactResponse.artifacts.length === 0) { if (listArtifactResponse.artifacts.length === 0) {
throw new Error( throw new Error(
@@ -76,14 +75,12 @@ 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, owner, repo, inputs.token, {
...options,
path: path.join(resolvedPath, artifact.name) path: path.join(resolvedPath, artifact.name)
}) })
) )