mirror of
https://code.forgejo.org/forgejo/download-artifact.git
synced 2025-05-16 20:27:48 +02:00
Add support for tilde expansion (#50)
* Add support for tilde expansion * Print resolved path with debug * Update README * README * Only replace tilde in certain scenarios * Fix
This commit is contained in:
parent
83fcc74d04
commit
381af06b42
4 changed files with 49 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as artifact from '@actions/artifact'
|
||||
import * as os from 'os'
|
||||
import {resolve} from 'path'
|
||||
import {Inputs, Outputs} from './constants'
|
||||
|
||||
|
@ -8,6 +9,15 @@ async function run(): Promise<void> {
|
|||
const name = core.getInput(Inputs.Name, {required: false})
|
||||
const path = core.getInput(Inputs.Path, {required: false})
|
||||
|
||||
let resolvedPath
|
||||
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
|
||||
if (path.startsWith(`~`)) {
|
||||
resolvedPath = resolve(path.replace('~', os.homedir()))
|
||||
} else {
|
||||
resolvedPath = resolve(path)
|
||||
}
|
||||
core.debug(`Resolved path is ${resolvedPath}`)
|
||||
|
||||
const artifactClient = artifact.create()
|
||||
if (!name) {
|
||||
// download all artifacts
|
||||
|
@ -15,7 +25,9 @@ async function run(): Promise<void> {
|
|||
core.info(
|
||||
'Creating an extra directory for each artifact that is being downloaded'
|
||||
)
|
||||
const downloadResponse = await artifactClient.downloadAllArtifacts(path)
|
||||
const downloadResponse = await artifactClient.downloadAllArtifacts(
|
||||
resolvedPath
|
||||
)
|
||||
core.info(`There were ${downloadResponse.length} artifacts downloaded`)
|
||||
for (const artifact of downloadResponse) {
|
||||
core.info(
|
||||
|
@ -30,7 +42,7 @@ async function run(): Promise<void> {
|
|||
}
|
||||
const downloadResponse = await artifactClient.downloadArtifact(
|
||||
name,
|
||||
path,
|
||||
resolvedPath,
|
||||
downloadOptions
|
||||
)
|
||||
core.info(
|
||||
|
@ -39,7 +51,7 @@ async function run(): Promise<void> {
|
|||
}
|
||||
// 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.setOutput(Outputs.DownloadPath, resolvedPath)
|
||||
core.info('Artifact download has finished successfully')
|
||||
} catch (err) {
|
||||
core.setFailed(err.message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue