fix: proper error when artifact is not found

This commit is contained in:
Jozef Steinhübl 2024-07-29 22:16:51 +02:00
parent 65bc9b03e7
commit bb5879294b
No known key found for this signature in database
GPG Key ID: E6BC90C91973B08F
2 changed files with 17 additions and 5 deletions

View File

@ -51,7 +51,7 @@ jobs:
- "1"
- "> 1.0.0"
- "< 2"
- "08a9b6a98b14d3c23b58080bea31513546246c50"
- "dbd320ccfa909053f95be9e1643d80d73286751f"
# Disable <sha> support for now. This is because Github Artifacts
# expire after 90 days, and we don't have another source of truth yet.
# - "822a00c4d508b54f650933a73ca5f4a3af9a7983" # 1.0.0 commit

View File

@ -39,7 +39,11 @@ async function getShaDownloadMeta(options: Input): Promise<DownloadMeta> {
(res = (await (
await request(
`https://api.github.com/repos/oven-sh/bun/actions/workflows/ci.yml/runs?per_page=100&page=${page}`,
{}
{
headers: {
"Authorization": `Bearer ${options.token}`,
},
}
)
).json()) as Runs)
) {
@ -52,7 +56,11 @@ async function getShaDownloadMeta(options: Input): Promise<DownloadMeta> {
const artifacts = (await (
await request(
`https://api.github.com/repos/oven-sh/bun/actions/runs/${run.id}/artifacts`,
{}
{
headers: {
"Authorization": `Bearer ${options.token}`,
},
}
)
).json()) as { artifacts: { name: string; archive_download_url: string }[] };
@ -62,9 +70,13 @@ async function getShaDownloadMeta(options: Input): Promise<DownloadMeta> {
avx2 ? "-baseline" : ""
}${profile ? "-profile" : ""}`;
const artifact = artifacts.artifacts.find((item) => item.name === name);
if (!artifact) {
throw new Error(`Failed to find artifact '${name}' in run '${run.id}'`);
}
return {
url: artifacts.artifacts.find((item) => item.name === name)
.archive_download_url,
url: artifact.archive_download_url,
auth: `Bearer ${token}`,
};
}