Compare commits

...

9 Commits

Author SHA1 Message Date
Rob Herley
3132d12662 consume latest toolkit 2023-12-11 14:42:09 -05:00
Jonathan Tamsut
5be1d38671 Merge pull request #243 from actions/robherley/v4-beta-updates
Consume latest @actions/toolkit
2023-12-07 11:52:45 -08:00
Rob Herley
465b526e63 consume latest @actions/toolkit 2023-12-06 19:43:53 -05:00
Rob Herley
8b83831f82 Merge pull request #242 from actions/v4-beta-internal-client
Use internal client when `github-token` is not specified
2023-12-04 13:20:07 -05:00
Rob Herley
0742efc19b set new 'latest' attribute for list operations 2023-12-04 13:08:24 -05:00
Rob Herley
5e4b342272 consume latest @actions/artifact 2023-12-01 13:20:09 -05:00
Rob Herley
98c6f16055 Merge pull request #239 from actions/robherley/bump-v4-beta-toolkit
Bump to latest artifact version from toolkit
2023-11-21 10:58:42 -05:00
Rob Herley
9140050fd5 consume latest @actions/artifact from toolkit 2023-11-20 20:57:50 -05:00
Konrad Pabjan
88dadfbcfc [v4 beta] Fixes to download directory structure (#233)
* Fix extra root extra root directory if downloading single artifact on v4-beta

* Fix for all downloads

* Bump to node20 runtime

* ncc

---------

Co-authored-by: Rob Herley <robherley@github.com>
2023-10-27 10:11:07 -04:00
3 changed files with 3290 additions and 18309 deletions

View File

@@ -9,21 +9,23 @@ inputs:
description: 'Destination path'
required: false
github-token:
description: The GitHub token used to download the artifact
default: ${{ github.token }}
description: 'The GitHub token used to authenticate with the GitHub API.
This is required when downloading artifacts from a different repository or from a different workflow run.
If this is not specified, the action will attempt to download artifacts from the current repository and the current workflow run.'
required: false
repository:
description: 'The repository owner and the repository name joined together by "/".
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.'
If github-token is specified, this is the repository that artifacts will be downloaded from.'
required: false
default: ${{ github.repository }}
run-id:
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.'
description: 'The id of the workflow run where the desired download artifact was uploaded from.
If github-token is specified, this is the run that artifacts will be downloaded from.'
required: false
default: ${{ github.run_id }}
outputs:
download-path:
description: 'Path of artifact download'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'

21526
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -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
@@ -17,9 +18,9 @@ async function run(): Promise<void> {
const inputs = {
name: core.getInput(Inputs.Name, {required: false}),
path: core.getInput(Inputs.Path, {required: false}),
token: core.getInput(Inputs.GitHubToken, {required: true}),
repository: core.getInput(Inputs.Repository, {required: true}),
runID: parseInt(core.getInput(Inputs.RunID, {required: true}))
token: core.getInput(Inputs.GitHubToken, {required: false}),
repository: core.getInput(Inputs.Repository, {required: false}),
runID: parseInt(core.getInput(Inputs.RunID, {required: false}))
}
if (!inputs.path) {
@@ -30,26 +31,35 @@ 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 [owner, repo] = inputs.repository.split('/')
if (!owner || !repo) {
throw new Error(
`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`
)
const options: FindOptions = {}
if (inputs.token) {
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
if (!repositoryOwner || !repositoryName) {
throw new Error(
`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`
)
}
options.findBy = {
token: inputs.token,
workflowRunId: inputs.runID,
repositoryName,
repositoryOwner
}
}
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,
inputs.runID,
owner,
repo,
inputs.token
options
)
if (!targetArtifact) {
@@ -62,13 +72,15 @@ async function run(): Promise<void> {
artifacts = [targetArtifact]
} else {
const listArtifactResponse = await artifactClient.listArtifacts(
inputs.runID,
owner,
repo,
inputs.token
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(
`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`
@@ -80,8 +92,11 @@ async function run(): Promise<void> {
}
const downloadPromises = artifacts.map(artifact =>
artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, {
path: path.join(resolvedPath, artifact.name)
artifactClient.downloadArtifact(artifact.id, {
...options,
path: isSingleArtifactDownload
? resolvedPath
: path.join(resolvedPath, artifact.name)
})
)