1
0
Fork 0
mirror of https://code.forgejo.org/actions/download-artifact.git synced 2024-12-23 12:36:01 +01:00
download-artifact/src/download-artifact.ts
Konrad Pabjan 7e5b6f00de
Misc Download Artifact Improvements (#43)
* Various improvements to download-artifact

* Resolve input path

* README updates

* PR feedback
2020-07-15 12:09:31 +02:00

49 lines
1.7 KiB
TypeScript

import * as core from '@actions/core'
import * as artifact from '@actions/artifact'
import {resolve} from 'path'
import {Inputs, Outputs} from './constants'
async function run(): Promise<void> {
try {
const name = core.getInput(Inputs.Name, {required: false})
const path = core.getInput(Inputs.Path, {required: false})
const artifactClient = artifact.create()
if (!name) {
// download all artifacts
core.info('No artifact name specified, downloading all artifacts')
core.info(
'Creating an extra directory for each artifact that is being downloaded'
)
const downloadResponse = await artifactClient.downloadAllArtifacts(path)
core.info(`There were ${downloadResponse.length} artifacts downloaded`)
for (const artifact of downloadResponse) {
core.info(
`Artifact ${artifact.artifactName} was downloaded to ${artifact.downloadPath}`
)
}
} else {
// download a single artifact
core.info(`Starting download for ${name}`)
const downloadOptions = {
createArtifactFolder: false
}
const downloadResponse = await artifactClient.downloadArtifact(
name,
path,
downloadOptions
)
core.info(
`Artifact ${downloadResponse.artifactName} was downloaded to ${downloadResponse.downloadPath}`
)
}
// output the directory that the artifact(s) was/were downloaded to
// if no path is provided, an empty string resolves to the current working directory
core.setOutput(Outputs.DownloadPath, resolve(path))
core.info('Artifact download has finished successfully')
} catch (err) {
core.setFailed(err.message)
}
}
run()