-
Notifications
You must be signed in to change notification settings - Fork 12
/
get-workflow-run-artifact.js
35 lines (28 loc) · 1.13 KB
/
get-workflow-run-artifact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module.exports = async (octokit, owner, repo, workflowRunId, artifactName) => {
const { data } = workflowRunId
? await octokit.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: Number(workflowRunId)
}) : await octokit.rest.actions.listArtifactsForRepo({
owner,
repo
})
const artifacts = data.artifacts.filter(a => a.name === artifactName)
if (artifacts.length === 0) {
throw new Error(`No artifacts with name '${artifactName}' found in workflow run ${workflowRunId}`)
}
const artifact = artifacts[0]
console.log(`Getting downloadUrl for artifact ID ${artifact.id}...`)
// This returns a download URL. The URL expires after 1 minute.
const generateDownloadUrl = await octokit.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip'
})
if (!generateDownloadUrl.url) {
throw new Error(`Could not get download URL for artifact ${artifact.id}. Output: ${JSON.stringify(generateDownloadUrl)}`)
}
return generateDownloadUrl.url
}