Compare commits

..

3 Commits

Author SHA1 Message Date
Rob Herley
ed25d4d912 more debug logs 2023-11-30 22:06:26 -05:00
Rob Herley
db146faf7b tsc & ncc 2023-11-30 21:37:48 -05:00
Rob Herley
6ee005d6b7 adopt new internal artifact api behavior 2023-11-30 21:37:06 -05:00
2 changed files with 18243 additions and 2563 deletions

20772
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -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
@@ -31,11 +30,10 @@ 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: FindOptions = {} const options: artifact.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) {
@@ -52,11 +50,10 @@ async function run(): Promise<void> {
} }
} }
let artifacts: Artifact[] = [] const artifactClient = artifact.create()
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
@@ -66,20 +63,12 @@ async function run(): Promise<void> {
throw new Error(`Artifact '${inputs.name}' not found`) throw new Error(`Artifact '${inputs.name}' not found`)
} }
core.debug( core.debug('Found named artifact:')
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})` core.debug(JSON.stringify(targetArtifact, null, 2))
)
artifacts = [targetArtifact] artifacts = [targetArtifact]
} else { } else {
core.info( const listArtifactResponse = await artifactClient.listArtifacts(options)
`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(
@@ -87,16 +76,15 @@ 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: isSingleArtifactDownload path: path.join(resolvedPath, artifact.name)
? resolvedPath
: path.join(resolvedPath, artifact.name)
}) })
) )