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:
Konrad Pabjan 2020-07-30 12:01:38 +02:00 committed by GitHub
parent 83fcc74d04
commit 381af06b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 11 deletions

View file

@ -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)