s3si.ts/gui/scripts/make-update.ts

106 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-03-12 23:19:53 -04:00
import { Octokit } from "npm:@octokit/rest@19.0.7";
const TAG_PREFIX = "gui-";
type Platform =
| "darwin-x86_64"
| "darwin-aarch64"
| "linux-x86_64"
| "windows-x86_64";
const PLATFORMS: Platform[] = [
"darwin-x86_64",
"darwin-aarch64",
"linux-x86_64",
"windows-x86_64",
];
2023-03-09 05:53:42 -05:00
const PlatformSuffix: Record<Platform, string> = {
2023-03-12 23:19:53 -04:00
"darwin-x86_64": ".app.tar.gz",
"darwin-aarch64": ".app.tar.gz",
"linux-x86_64": ".AppImage.tar.gz",
"windows-x86_64": ".msi.zip",
};
2023-03-09 05:53:42 -05:00
type File = {
2023-03-12 23:19:53 -04:00
signature: string;
url: string;
};
2023-03-09 05:53:42 -05:00
type UpdateJson = {
2023-03-12 23:19:53 -04:00
version: string;
notes: string;
pub_date: string;
platforms: Record<Platform, File>;
};
2023-03-09 05:53:42 -05:00
const REPO = {
2023-03-12 23:19:53 -04:00
owner: "spacemeowx2",
repo: "s3si.ts",
};
2023-03-09 05:53:42 -05:00
const octokit = new Octokit({
2023-03-12 23:19:53 -04:00
auth: Deno.env.get("GITHUB_TOKEN"),
2023-03-09 05:53:42 -05:00
});
async function findFirstGuiRelease() {
let page = 1;
while (true) {
const { data: list } = await octokit.repos.listReleases({
...REPO,
page,
2023-03-12 23:19:53 -04:00
});
2023-03-09 05:53:42 -05:00
if (list.length === 0) {
2023-03-12 23:19:53 -04:00
return undefined;
2023-03-09 05:53:42 -05:00
}
for (const release of list) {
if (release.tag_name.startsWith(TAG_PREFIX)) {
2023-03-12 23:19:53 -04:00
return release;
2023-03-09 05:53:42 -05:00
}
}
page += 1;
}
}
const release = await findFirstGuiRelease();
2023-03-12 23:19:53 -04:00
const version = release?.tag_name.slice(TAG_PREFIX.length) ?? "unknown";
const notes = release?.body ?? "unknown";
const pub_date = release?.published_at ?? "unknown";
2023-03-09 05:53:42 -05:00
async function makePlatforms(r: typeof release) {
const assets = r?.assets ?? [];
2023-03-12 23:19:53 -04:00
const platforms = Object.fromEntries(PLATFORMS.map((p) => {
const asset = assets.find((i) => i.name.endsWith(PlatformSuffix[p]));
2023-03-09 05:53:42 -05:00
if (!asset) {
2023-03-12 23:19:53 -04:00
throw new Error(`Asset not found for ${p}`);
2023-03-09 05:53:42 -05:00
}
return [p, {
2023-03-12 23:19:53 -04:00
signature: asset.browser_download_url + ".sig",
2023-03-09 05:53:42 -05:00
url: asset.browser_download_url,
2023-03-12 23:19:53 -04:00
}];
2023-03-09 05:53:42 -05:00
})) as Record<Platform, File>;
2023-03-12 23:19:53 -04:00
return platforms;
2023-03-09 05:53:42 -05:00
}
const updateJson: UpdateJson = {
version,
notes,
pub_date,
platforms: await makePlatforms(release),
2023-03-12 23:19:53 -04:00
};
2023-03-09 05:53:42 -05:00
// fetch signatures
for (const platform of PLATFORMS) {
const file = updateJson.platforms[platform];
const res = await fetch(file.signature);
file.signature = await res.text();
}
console.log(JSON.stringify(updateJson, null, 2));