diff --git a/.github/workflows/check_updates.generated.yml b/.github/workflows/check_updates.generated.yml index 832d1a6..8aa5cd0 100644 --- a/.github/workflows/check_updates.generated.yml +++ b/.github/workflows/check_updates.generated.yml @@ -26,6 +26,7 @@ jobs: - name: Run script env: OPENAI_API_KEY: '${{ secrets.OPENAI_API_KEY }}' + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' CODEX_MODEL: gpt-6.1-sol REVIEW_MODEL: gpt-6-astra run: |- diff --git a/.github/workflows/check_updates.ts b/.github/workflows/check_updates.ts index 123c93b..8a9258b 100755 --- a/.github/workflows/check_updates.ts +++ b/.github/workflows/check_updates.ts @@ -27,6 +27,8 @@ const buildJob = { name: "Run script", env: { OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}", + // for the requests the update script makes to GitHub + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}", // model that fixes/wires up the Mago update (Codex) CODEX_MODEL: "gpt-6.1-sol", // separate model that independently reviews the changes diff --git a/scripts/update.ts b/scripts/update.ts index 138a504..e262d9a 100644 --- a/scripts/update.ts +++ b/scripts/update.ts @@ -183,8 +183,8 @@ async function getLatestMagoVersions(): Promise { async function updateRustToolchain(magoVersion: string) { const content = await $.request( - `https://raw.githubusercontent.com/carthage-software/mago/${magoVersion}/Cargo.toml`, - ).text(); + `https://api.github.com/repos/carthage-software/mago/contents/Cargo.toml?ref=${encodeURIComponent(magoVersion)}`, + ).header(getGitHubHeaders()).text(); const match = content.match(/rust-version\s*=\s*"([^"]+)"/); if (match == null) { throw new Error("Could not find rust-version in mago's Cargo.toml."); @@ -214,3 +214,13 @@ async function getLatestCrateVersion(crateName: string): Promise { $.logLight(`Latest ${crateName} version on crates.io:`, latestVersion); return latestVersion; } + +// Asks the GitHub API for raw file content. It authenticates when there's a +// token, since unauthenticated requests get rate limited on the runners' shared IPs. +function getGitHubHeaders(): Record { + const token = Deno.env.get("GITHUB_TOKEN"); + return { + accept: "application/vnd.github.raw+json", + ...(token ? { authorization: `Bearer ${token}` } : {}), + }; +}