From bb5879294bc4e33b4cb9a27cff33074a61594170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 29 Jul 2024 22:16:51 +0200 Subject: [PATCH] fix: proper error when artifact is not found --- .github/workflows/test.yml | 2 +- src/download-url.ts | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3fdb33b..d2ba53f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,7 +51,7 @@ jobs: - "1" - "> 1.0.0" - "< 2" - - "08a9b6a98b14d3c23b58080bea31513546246c50" + - "dbd320ccfa909053f95be9e1643d80d73286751f" # Disable 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 diff --git a/src/download-url.ts b/src/download-url.ts index c97a59a..15f53ae 100644 --- a/src/download-url.ts +++ b/src/download-url.ts @@ -39,7 +39,11 @@ async function getShaDownloadMeta(options: Input): Promise { (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 { 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 { 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}`, }; }