Resolve latest version instead of downloading latest release (#178)

This commit is contained in:
pollenJP(@'ω'@) 2024-12-01 03:12:35 +09:00 committed by GitHub
parent 8bdd012be5
commit 38f3f10444
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 234 deletions

View file

@ -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;
@ -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;
}