Files
DiunaBI/.github/workflows/buildScripts/downloadArtifacts.js
Michał Zieliński 33d57ac652 WIP: Build & Release
2025-02-12 15:48:33 +01:00

28 lines
960 B
JavaScript

module.exports = async ({ github, context, core, jobId, name }) => {
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: jobId,
});
if (artifacts.data.total_count === 0) {
core.setFailed("No artifacts found for jobID: " + jobId);
return false;
}
const artifact = artifacts.data.artifacts.find(
(artifact) => artifact.name === name
);
if (!artifact) {
core.setFailed(`${name} not found in artifacts`);
return false;
}
const response = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: "zip"
});
require('fs').writeFileSync(`${name}.zip`, Buffer.from(response.data));
require('fs').mkdirSync(`./${jobId}/${name}`, { recursive: true });
require('child_process').execSync(`unzip -o ${name}.zip -d ./${jobId}/${name}`);
};