1
0
Fork 0
mirror of https://code.forgejo.org/actions/download-artifact.git synced 2024-12-23 12:36:01 +01:00

Fix for all downloads

This commit is contained in:
Konrad Pabjan 2023-10-26 22:29:16 -04:00
parent 54ed8ca4ec
commit ac384941b4
2 changed files with 10 additions and 4 deletions

6
dist/index.js vendored
View file

@ -118706,16 +118706,17 @@ 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('/');
if (!owner || !repo) { if (!owner || !repo) {
throw new Error(`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`); throw new Error(`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`);
} }
const isSingleArtifactDownload = !!inputs.name;
const artifactClient = artifact.create(); const artifactClient = artifact.create();
let artifacts = []; let artifacts = [];
if (isSingleArtifactDownload) { 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`);
@ -118724,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}'`);
@ -118732,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: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, inputs.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}`)
@ -40,11 +41,12 @@ async function run(): Promise<void> {
) )
} }
const isSingleArtifactDownload = !!inputs.name
const artifactClient = artifact.create() const artifactClient = artifact.create()
let artifacts: artifact.Artifact[] = [] let artifacts: artifact.Artifact[] = []
if (isSingleArtifactDownload) { 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,
@ -63,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,
@ -82,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: isSingleArtifactDownload? resolvedPath : path.join(resolvedPath, inputs.name) path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name)
}) })
) )