Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve latest version instead of downloading latest release #178

Merged
merged 12 commits into from
Nov 30, 2024
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
For an example workflow, see
[here](https://github.com/charliermarsh/autobot/blob/e42c66659bf97b90ca9ff305a19cc99952d0d43f/.github/workflows/ci.yaml).
> [!TIP]
>
> Using `latest` requires to download the uv executable on every run, which incurs a cost
> (especially on self-hosted runners). As a best practice, consider pinning the version to a
> specific release.

### Install a specific version
```yaml
Expand Down
153 changes: 31 additions & 122 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions src/download/download-latest.ts

This file was deleted.

22 changes: 20 additions & 2 deletions src/download/download-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ export async function downloadVersion(
return { version: resolvedVersion, cachedToolDir };
}

async function resolveVersion(
version: string,
export async function resolveVersion(
versionInput: string,
githubToken: string,
): Promise<string> {
const version =
versionInput === "latest"
? await getLatestVersion(githubToken)
: versionInput;
if (tc.isExplicitVersion(version)) {
core.debug(`Version ${version} is an explicit version.`);
return version;
Expand All @@ -95,3 +99,17 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
});
return response.map((release) => release.tag_name);
}

async function getLatestVersion(githubToken: string) {
const octokit = github.getOctokit(githubToken);

const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER,
repo: REPO,
});

if (!latestRelease) {
throw new Error("Could not determine latest release.");
}
return latestRelease.tag_name;
}
52 changes: 21 additions & 31 deletions src/setup-uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as path from "node:path";
import {
downloadVersion,
tryGetFromToolCache,
resolveVersion,
} from "./download/download-version";
import { restoreCache } from "./cache/restore-cache";

import { downloadLatest } from "./download/download-latest";
import {
type Architecture,
getArch,
Expand Down Expand Up @@ -69,38 +69,28 @@ async function setupUv(
checkSum: string | undefined,
githubToken: string,
): Promise<{ uvDir: string; version: string }> {
let installedPath: string | undefined;
let cachedToolDir: string;
let version: string;
if (versionInput === "latest") {
const latestResult = await downloadLatest(
platform,
arch,
checkSum,
githubToken,
);
version = latestResult.version;
cachedToolDir = latestResult.cachedToolDir;
} else {
const toolCacheResult = tryGetFromToolCache(arch, versionInput);
version = toolCacheResult.version;
installedPath = toolCacheResult.installedPath;
if (installedPath) {
core.info(`Found uv in tool-cache for ${versionInput}`);
return { uvDir: installedPath, version };
}
const versionResult = await downloadVersion(
platform,
arch,
versionInput,
checkSum,
githubToken,
);
cachedToolDir = versionResult.cachedToolDir;
version = versionResult.version;
const resolvedVersion = await resolveVersion(versionInput, githubToken);
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
eifinger marked this conversation as resolved.
Show resolved Hide resolved
if (toolCacheResult.installedPath) {
core.info(`Found uv in tool-cache for ${toolCacheResult.version}`);
return {
uvDir: toolCacheResult.installedPath,
version: toolCacheResult.version,
};
}

return { uvDir: cachedToolDir, version };
const downloadVersionResult = await downloadVersion(
platform,
arch,
resolvedVersion,
checkSum,
githubToken,
);

return {
uvDir: downloadVersionResult.cachedToolDir,
version: downloadVersionResult.version,
};
}

function addUvToPath(cachedPath: string): void {
Expand Down