Skip to content

Commit 952824a

Browse files
committed
Refactor input handling
This is in preparation for caching with non-empty output directories, where we will cache the `.zip` file instead. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 306b047 commit 952824a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import {readdirSync} from 'fs'
55

66
async function run(): Promise<void> {
77
try {
8-
const {artifactName, download, cacheId} = await get(
8+
const {artifactName, stripPrefix, download, cacheId} = await get(
99
core.getInput('repository'),
1010
core.getInput('definitionId'),
1111
core.getInput('artifact'),
1212
core.getInput('stripPrefix')
1313
)
1414
const outputDirectory = core.getInput('path') || artifactName
1515
let useCache = core.getInput('cache') === 'true'
16-
const verbose = core.getInput('verbose')
16+
const verbose: number | boolean = ((input?: string) =>
17+
input && input.match(/^\d+$/) ? parseInt(input) : input === 'true')(
18+
core.getInput('verbose')
19+
)
1720

1821
const isDirectoryEmpty = (path: string): boolean => {
1922
try {
@@ -40,10 +43,7 @@ async function run(): Promise<void> {
4043

4144
if (needToDownload) {
4245
core.info(`Downloading ${artifactName}`)
43-
await download(
44-
outputDirectory,
45-
verbose.match(/^\d+$/) ? parseInt(verbose) : verbose === 'true'
46-
)
46+
await download(outputDirectory, verbose)
4747

4848
try {
4949
if (useCache && !(await saveCache([outputDirectory], cacheId))) {

src/downloader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function get(
100100
stripPrefix?: string
101101
): Promise<{
102102
artifactName: string
103+
stripPrefix: string
103104
cacheId: string
104105
download: (
105106
outputDirectory: string,
@@ -152,6 +153,10 @@ export async function get(
152153
url = await getURL()
153154
}
154155

156+
if (!stripPrefix) {
157+
stripPrefix = `${artifactName}/`
158+
}
159+
155160
const download = async (
156161
outputDirectory: string,
157162
verbose: number | boolean = false
@@ -184,5 +189,5 @@ export async function get(
184189
}
185190

186191
const cacheId = `${repository}-${definitionId}-${artifactName}-${data.value[0].id}`
187-
return {artifactName, download, cacheId}
192+
return {artifactName, stripPrefix, download, cacheId}
188193
}

0 commit comments

Comments
 (0)