Skip to content

Commit

Permalink
fix: proper error when artifact is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jul 29, 2024
1 parent 65bc9b0 commit bb58792
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions src/download-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand All @@ -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 }[] };

Expand All @@ -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}`,
};
}
Expand Down

0 comments on commit bb58792

Please sign in to comment.