mirror of
https://code.forgejo.org/forgejo/download-artifact.git
synced 2025-05-16 20:27:48 +02:00
support globbing artifact list & merging download directory
This commit is contained in:
parent
1bd0606e08
commit
c4c6db724f
7 changed files with 5065 additions and 3005 deletions
|
@ -3,7 +3,9 @@ export enum Inputs {
|
|||
Path = 'path',
|
||||
GitHubToken = 'github-token',
|
||||
Repository = 'repository',
|
||||
RunID = 'run-id'
|
||||
RunID = 'run-id',
|
||||
Pattern = 'pattern',
|
||||
MergeMultiple = 'merge-multiple'
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as path from 'path'
|
|||
import * as core from '@actions/core'
|
||||
import artifactClient from '@actions/artifact'
|
||||
import type {Artifact, FindOptions} from '@actions/artifact'
|
||||
import {Minimatch} from 'minimatch'
|
||||
import {Inputs, Outputs} from './constants'
|
||||
|
||||
const PARALLEL_DOWNLOADS = 5
|
||||
|
@ -20,7 +21,9 @@ async function run(): Promise<void> {
|
|||
path: core.getInput(Inputs.Path, {required: false}),
|
||||
token: core.getInput(Inputs.GitHubToken, {required: false}),
|
||||
repository: core.getInput(Inputs.Repository, {required: false}),
|
||||
runID: parseInt(core.getInput(Inputs.RunID, {required: false}))
|
||||
runID: parseInt(core.getInput(Inputs.RunID, {required: false})),
|
||||
pattern: core.getInput(Inputs.Pattern, {required: false}),
|
||||
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {required: false})
|
||||
}
|
||||
|
||||
if (!inputs.path) {
|
||||
|
@ -80,23 +83,36 @@ async function run(): Promise<void> {
|
|||
latest: true,
|
||||
...options
|
||||
})
|
||||
artifacts = listArtifactResponse.artifacts
|
||||
|
||||
if (listArtifactResponse.artifacts.length === 0) {
|
||||
throw new Error(
|
||||
`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`
|
||||
core.debug(`Found ${artifacts.length} artifacts in run`)
|
||||
|
||||
if (inputs.pattern) {
|
||||
core.info(`Filtering artifacts by pattern '${inputs.pattern}'`)
|
||||
const matcher = new Minimatch(inputs.pattern)
|
||||
artifacts = artifacts.filter(artifact => matcher.match(artifact.name))
|
||||
core.debug(
|
||||
`Filtered from ${listArtifactResponse.artifacts.length} to ${artifacts.length} artifacts`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`)
|
||||
artifacts = listArtifactResponse.artifacts
|
||||
if (artifacts.length) {
|
||||
core.info(`Preparing to download the following artifacts:`)
|
||||
artifacts.forEach(artifact => {
|
||||
core.info(
|
||||
`- ${artifact.name} (ID: ${artifact.id}, Size: ${artifact.size})`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const downloadPromises = artifacts.map(artifact =>
|
||||
artifactClient.downloadArtifact(artifact.id, {
|
||||
...options,
|
||||
path: isSingleArtifactDownload
|
||||
? resolvedPath
|
||||
: path.join(resolvedPath, artifact.name)
|
||||
path:
|
||||
isSingleArtifactDownload || inputs.mergeMultiple
|
||||
? resolvedPath
|
||||
: path.join(resolvedPath, artifact.name)
|
||||
})
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue