Files
grafana/.github/workflows/scripts/get-workflow-run-artifact.js
Levente Balogh 8ed5b95f42 Chore: change triggering of the detect-breaking-changes Github flow (#43188)
* chore: only run the breaking-changes flow on pull requests

* chore: run the detect-breaking-changes flow on opening a PR

* chore: use

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* Wip

* trying to get workflow split running.

* trying to trigger workflow.

* trying to trigger.

* Splits levitate job into two workflows.

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2022-01-03 12:48:12 +01:00

45 lines
1.3 KiB
JavaScript

module.exports = async ({ github, context, core, runId, artifactName }) => {
try {
const AdmZip = require('adm-zip');
const fs = require('fs');
const { owner, repo } = context.repo;
const { data } = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId,
});
const artifact = data.artifacts.find(a => a.name === artifactName);
if (!artifact) {
throw new Error(`Could not find artifact ${artifactName} in workflow (${runId})`);
}
const zip = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: "zip",
});
const dir = `./tmp/${artifactName}`;
await mkdirRecursive(fs, dir);
const admZip = new AdmZip(Buffer.from(zip.data));
admZip.extractAllTo(dir, true);
return dir;
} catch (error) {
core.restFailed(error.message);
}
}
async function mkdirRecursive(fs, path) {
return new Promise((resolve, reject) => {
fs.mkdir(path, { recursive: true }, (error) => {
if (error) return reject(error);
return resolve();
});
});
}