2024-09-05 08:06:45 -04:00
|
|
|
import * as github from "@actions/github";
|
|
|
|
|
import * as core from "@actions/core";
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
import { OWNER, REPO } from "./utils/utils";
|
|
|
|
|
import { createReadStream, promises as fs } from "fs";
|
|
|
|
|
import * as readline from "readline";
|
|
|
|
|
import * as semver from "semver";
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
import { updateChecksums } from "./download/checksum/update-known-checksums";
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
2024-09-05 08:06:45 -04:00
|
|
|
const checksumFilePath = process.argv.slice(2)[0];
|
|
|
|
|
const defaultVersionFilePath = process.argv.slice(2)[1];
|
|
|
|
|
const github_token = process.argv.slice(2)[2];
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
const octokit = github.getOctokit(github_token);
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
|
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
|
|
|
|
|
owner: OWNER,
|
2024-09-05 08:06:45 -04:00
|
|
|
repo: REPO,
|
|
|
|
|
});
|
|
|
|
|
const downloadUrls: string[] = response.flatMap((release) =>
|
2024-08-23 23:58:26 +02:00
|
|
|
release.assets
|
2024-09-05 08:06:45 -04:00
|
|
|
.filter((asset) => asset.name.endsWith(".sha256"))
|
|
|
|
|
.map((asset) => asset.browser_download_url),
|
|
|
|
|
);
|
|
|
|
|
await updateChecksums(checksumFilePath, downloadUrls);
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
|
const latestVersion = response
|
2024-09-05 08:06:45 -04:00
|
|
|
.map((release) => release.tag_name)
|
|
|
|
|
.sort(semver.rcompare)[0];
|
|
|
|
|
core.setOutput("latest-version", latestVersion);
|
|
|
|
|
await updateDefaultVersion(defaultVersionFilePath, latestVersion);
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function updateDefaultVersion(
|
|
|
|
|
filePath: string,
|
2024-09-05 08:06:45 -04:00
|
|
|
latestVersion: string,
|
2024-08-23 23:58:26 +02:00
|
|
|
): Promise<void> {
|
2024-09-05 08:06:45 -04:00
|
|
|
const fileStream = createReadStream(filePath);
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
2024-09-05 08:06:45 -04:00
|
|
|
input: fileStream,
|
|
|
|
|
});
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
let foundDescription = false;
|
|
|
|
|
const lines = [];
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
|
for await (let line of rl) {
|
|
|
|
|
if (
|
|
|
|
|
!foundDescription &&
|
|
|
|
|
line.includes("description: 'The version of uv to install'")
|
|
|
|
|
) {
|
2024-09-05 08:06:45 -04:00
|
|
|
foundDescription = true;
|
|
|
|
|
} else if (foundDescription && line.includes("default: ")) {
|
|
|
|
|
line = line.replace(/'[^']*'/, `'${latestVersion}'`);
|
|
|
|
|
foundDescription = false;
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
2024-09-05 08:06:45 -04:00
|
|
|
lines.push(line);
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
await fs.writeFile(filePath, lines.join("\n"));
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
run();
|