[v4 beta] Fixes to download directory structure (#233)

* Fix extra root extra root directory if downloading single artifact on v4-beta

* Fix for all downloads

* Bump to node20 runtime

* ncc

---------

Co-authored-by: Rob Herley <robherley@github.com>
This commit is contained in:
Konrad Pabjan 2023-10-27 10:11:07 -04:00 committed by GitHub
parent 896d1bb258
commit 88dadfbcfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -25,5 +25,5 @@ outputs:
download-path: download-path:
description: 'Path of artifact download' description: 'Path of artifact download'
runs: runs:
using: 'node16' using: 'node20'
main: 'dist/index.js' main: 'dist/index.js'

7
dist/index.js vendored
View File

@ -118706,6 +118706,7 @@ function run() {
if (inputs.path.startsWith(`~`)) { if (inputs.path.startsWith(`~`)) {
inputs.path = inputs.path.replace('~', os.homedir()); inputs.path = inputs.path.replace('~', os.homedir());
} }
const isSingleArtifactDownload = !!inputs.name;
const resolvedPath = path.resolve(inputs.path); const resolvedPath = path.resolve(inputs.path);
core.debug(`Resolved path is ${resolvedPath}`); core.debug(`Resolved path is ${resolvedPath}`);
const [owner, repo] = inputs.repository.split('/'); const [owner, repo] = inputs.repository.split('/');
@ -118714,7 +118715,8 @@ function run() {
} }
const artifactClient = artifact.create(); const artifactClient = artifact.create();
let artifacts = []; let artifacts = [];
if (inputs.name) { if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`);
const { artifact: targetArtifact } = yield artifactClient.getArtifact(inputs.name, inputs.runID, owner, repo, inputs.token); const { artifact: targetArtifact } = yield artifactClient.getArtifact(inputs.name, inputs.runID, owner, repo, inputs.token);
if (!targetArtifact) { if (!targetArtifact) {
throw new Error(`Artifact '${inputs.name}' not found`); throw new Error(`Artifact '${inputs.name}' not found`);
@ -118723,6 +118725,7 @@ function run() {
artifacts = [targetArtifact]; artifacts = [targetArtifact];
} }
else { else {
core.info(`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`);
const listArtifactResponse = yield artifactClient.listArtifacts(inputs.runID, owner, repo, inputs.token); const listArtifactResponse = yield artifactClient.listArtifacts(inputs.runID, owner, repo, inputs.token);
if (listArtifactResponse.artifacts.length === 0) { if (listArtifactResponse.artifacts.length === 0) {
throw new Error(`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`); throw new Error(`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`);
@ -118731,7 +118734,7 @@ function run() {
artifacts = listArtifactResponse.artifacts; artifacts = listArtifactResponse.artifacts;
} }
const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, {
path: path.join(resolvedPath, artifact.name) path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name)
})); }));
const chunkedPromises = exports.chunk(downloadPromises, PARALLEL_DOWNLOADS); const chunkedPromises = exports.chunk(downloadPromises, PARALLEL_DOWNLOADS);
for (const chunk of chunkedPromises) { for (const chunk of chunkedPromises) {

View File

@ -30,6 +30,7 @@ async function run(): Promise<void> {
inputs.path = inputs.path.replace('~', os.homedir()) inputs.path = inputs.path.replace('~', os.homedir())
} }
const isSingleArtifactDownload: boolean = !!inputs.name
const resolvedPath = path.resolve(inputs.path) const resolvedPath = path.resolve(inputs.path)
core.debug(`Resolved path is ${resolvedPath}`) core.debug(`Resolved path is ${resolvedPath}`)
@ -43,7 +44,9 @@ async function run(): Promise<void> {
const artifactClient = artifact.create() const artifactClient = artifact.create()
let artifacts: artifact.Artifact[] = [] let artifacts: artifact.Artifact[] = []
if (inputs.name) { if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`)
const {artifact: targetArtifact} = await artifactClient.getArtifact( const {artifact: targetArtifact} = await artifactClient.getArtifact(
inputs.name, inputs.name,
inputs.runID, inputs.runID,
@ -62,6 +65,8 @@ async function run(): Promise<void> {
artifacts = [targetArtifact] artifacts = [targetArtifact]
} else { } else {
core.info(`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`)
const listArtifactResponse = await artifactClient.listArtifacts( const listArtifactResponse = await artifactClient.listArtifacts(
inputs.runID, inputs.runID,
owner, owner,
@ -81,7 +86,7 @@ async function run(): Promise<void> {
const downloadPromises = artifacts.map(artifact => const downloadPromises = artifacts.map(artifact =>
artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, {
path: path.join(resolvedPath, artifact.name) path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name)
}) })
) )