This commit is contained in:
2025-06-29 23:45:33 -07:00
parent 98f47d8061
commit f4f2700a5a
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
module.exports = async ({
github,
context,
core
}) => {
const owner = context.repo.owner;
const repo = context.repo.repo;
// See: https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#list-repository-workflows
const workflows = await github.rest.actions.listRepoWorkflows({
owner,
repo
})
const workflow = workflows.data.workflows.find(w => w.path.includes(process.env.WORKFLOW_FILENAME));
if (!workflow) {
core.setFailed("No matching workflow found.");
return;
}
// See: https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository
const runs = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: workflow.id,
status: "success",
per_page: 1
})
if (runs.data.total_count === 0) {
core.setFailed("No workflow runs found.");
return;
}
// See: https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runs.data.workflow_runs[0].id
});
// Other formats are not supported by the GitHub API for downloading artifacts.
const extension = "zip"
const artifact = artifacts.data.artifacts.find(artifact => artifact.name === process.env.ARTIFACT_NAME);
if (artifact) {
// See: https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#download-an-artifact
const response = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: extension
});
const artifactFilename = process.env.ARTIFACT_FILENAME || `${artifact.name}.${extension}`;
require('fs').writeFileSync(artifactFilename, Buffer.from(response.data));
console.log("Artifact downloaded successfully.");
const unzip_dir = process.env.UNZIP_DIR;
if (unzip_dir) {
console.log("Unzipping artifact to directory: %s", unzip_dir);
require('child_process').execSync(`unzip -o ${artifactFilename} -d ${process.env.UNZIP_DIR}`);
}
} else {
core.setFailed("No artifact found.");
}
}