Do not expect GITHUB_TOKEN to be set or valid (#262)
Some checks failed
Check dist/ / check-dist (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Release Drafter / ✏️ Draft release (push) Has been cancelled
test-cache-windows / test-setup-cache (push) Has been cancelled
test-cache / test-setup-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache (auto, ubuntu-latest) (push) Has been cancelled
test-cache / test-setup-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache (false, ubuntu-latest) (push) Has been cancelled
test-cache / test-setup-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache (true, ubuntu-latest) (push) Has been cancelled
test-cache / test-setup-cache-requirements-txt (push) Has been cancelled
test-cache / test-setup-cache-dependency-glob (push) Has been cancelled
test-cache / test-setup-cache-local (push) Has been cancelled
test-cache / test-tilde-expansion-cache-local-path (push) Has been cancelled
test-cache / test-tilde-expansion-cache-dependency-glob (push) Has been cancelled
test-cache / test-no-python-version (push) Has been cancelled
test-windows / test-default-version (push) Has been cancelled
test / build (push) Has been cancelled
test / test-default-version (macos-14) (push) Has been cancelled
test / test-default-version (macos-latest) (push) Has been cancelled
test / test-default-version (ubuntu-latest) (push) Has been cancelled
test / test-specific-version (0.3) (push) Has been cancelled
test / test-specific-version (0.3.0) (push) Has been cancelled
test / test-specific-version (0.3.2) (push) Has been cancelled
test / test-specific-version (0.3.x) (push) Has been cancelled
test / test-specific-version (>=0.3.0) (push) Has been cancelled
test / test-semver-range (push) Has been cancelled
test / test-pyproject-file-version (push) Has been cancelled
test / test-uv-file-version (push) Has been cancelled
test / test-checksum (4d9279ad5ca596b1e2d703901d508430eb07564dc4d8837de9e2fca9c90f8ecd, ubuntu-latest) (push) Has been cancelled
test / test-checksum (a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218, macos-latest) (push) Has been cancelled
test / test-with-explicit-token (push) Has been cancelled
test / test-uvx (push) Has been cancelled
test / test-tool-install (macos-14) (push) Has been cancelled
test / test-tool-install (macos-latest) (push) Has been cancelled
test / test-tool-install (ubuntu-latest) (push) Has been cancelled
test / test-tool-install (windows-latest) (push) Has been cancelled
test / test-tilde-expansion-tool-dirs (push) Has been cancelled
test / test-python-version (macos-latest) (push) Has been cancelled
test / test-python-version (ubuntu-latest) (push) Has been cancelled
test / test-python-version (windows-latest) (push) Has been cancelled
test / test-malformed-pyproject-file-fallback (push) Has been cancelled
test-cache-windows / test-restore-cache (push) Has been cancelled
test-cache / test-restore-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (auto, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (false, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (true, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache-requirements-txt (push) Has been cancelled
test-cache / test-restore-cache-dependency-glob (push) Has been cancelled
test-cache / test-restore-cache-local (push) Has been cancelled
test-cache / cleanup-tilde-expansion-tests (push) Has been cancelled

This fixes issues with GHES

Fixes: #221
This commit is contained in:
Kevin Stillhammer 2025-01-30 14:37:07 +01:00 committed by GitHub
parent 2625dd350b
commit 4db96194c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 8078 additions and 8774 deletions

View file

@ -2,15 +2,14 @@ import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as path from "node:path";
import { promises as fs } from "node:fs";
import {
GITHUB_COM_API,
OWNER,
REPO,
TOOL_CACHE_NAME,
} from "../utils/constants";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum";
import * as github from "@actions/github";
import { Octokit } from "@octokit/core";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
const PaginatingOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
export function tryGetFromToolCache(
arch: Architecture,
@ -96,8 +95,26 @@ export async function resolveVersion(
}
async function getAvailableVersions(githubToken: string): Promise<string[]> {
const octokit = github.getOctokit(githubToken, { baseUrl: GITHUB_COM_API });
try {
const octokit = new PaginatingOctokit({
auth: githubToken,
});
return await getReleaseTagNames(octokit);
} catch (err) {
if ((err as Error).message.includes("Bad credentials")) {
core.info(
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
);
const octokit = new PaginatingOctokit();
return await getReleaseTagNames(octokit);
}
throw err;
}
}
async function getReleaseTagNames(
octokit: InstanceType<typeof PaginatingOctokit>,
): Promise<string[]> {
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER,
repo: REPO,
@ -106,15 +123,37 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
}
async function getLatestVersion(githubToken: string) {
const octokit = github.getOctokit(githubToken, { baseUrl: GITHUB_COM_API });
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER,
repo: REPO,
const octokit = new PaginatingOctokit({
auth: githubToken,
});
let latestRelease: { tag_name: string } | undefined;
try {
latestRelease = await getLatestRelease(octokit);
} catch (err) {
if ((err as Error).message.includes("Bad credentials")) {
core.info(
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
);
const octokit = new PaginatingOctokit();
latestRelease = await getLatestRelease(octokit);
} else {
throw err;
}
}
if (!latestRelease) {
throw new Error("Could not determine latest release.");
}
return latestRelease.tag_name;
}
async function getLatestRelease(
octokit: InstanceType<typeof PaginatingOctokit>,
) {
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER,
repo: REPO,
});
return latestRelease;
}

View file

@ -1,16 +1,22 @@
import * as github from "@actions/github";
import * as core from "@actions/core";
import { GITHUB_COM_API, OWNER, REPO } from "./utils/constants";
import * as semver from "semver";
import * as core from "@actions/core";
import { Octokit } from "@octokit/core";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { OWNER, REPO } from "./utils/constants";
import { updateChecksums } from "./download/checksum/update-known-checksums";
const PaginatingOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0];
const github_token = process.argv.slice(2)[1];
const octokit = github.getOctokit(github_token, { baseUrl: GITHUB_COM_API });
const octokit = new PaginatingOctokit({
auth: github_token,
});
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER,

View file

@ -1,4 +1,3 @@
export const REPO = "uv";
export const OWNER = "astral-sh";
export const TOOL_CACHE_NAME = "uv";
export const GITHUB_COM_API = "https://api.github.com";