Skip to content

Commit

Permalink
Fixed reviewed points
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Stillhammer <[email protected]>
  • Loading branch information
pollenjp and eifinger committed Nov 30, 2024
1 parent db2faa9 commit d59153e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 83 deletions.
97 changes: 28 additions & 69 deletions dist/setup/index.js

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

20 changes: 19 additions & 1 deletion src/download/download-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ export async function downloadVersion(
}

export async function resolveVersion(
version: string,
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;
}
23 changes: 10 additions & 13 deletions src/setup-uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "./download/download-version";
import { restoreCache } from "./cache/restore-cache";

import { getLatestReleaseVersion } from "./download/download-latest";
import {
type Architecture,
getArch,
Expand Down Expand Up @@ -70,20 +69,15 @@ async function setupUv(
checkSum: string | undefined,
githubToken: string,
): Promise<{ uvDir: string; version: string }> {
const resolvedVersion = await resolveVersion(
versionInput === "latest"
? await getLatestReleaseVersion(githubToken)
: versionInput,
githubToken,
);

const resolvedVersion = await resolveVersion(versionInput, githubToken);
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
if (toolCacheResult.installedPath) {
core.info(`Found uv in tool-cache for ${resolvedVersion}`);
core.setOutput("uv-cache-hit", true);
return { uvDir: toolCacheResult.installedPath, version: resolvedVersion };
core.info(`Found uv in tool-cache for ${toolCacheResult.version}`);
return {
uvDir: toolCacheResult.installedPath,
version: toolCacheResult.version,
};
}
core.setOutput("uv-cache-hit", false);

const downloadVersionResult = await downloadVersion(
platform,
Expand All @@ -93,7 +87,10 @@ async function setupUv(
githubToken,
);

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

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

0 comments on commit d59153e

Please sign in to comment.