2022-04-19 20:46:50 -04:00
|
|
|
import { Octokit } from "@octokit/rest";
|
|
|
|
import { throttling } from "@octokit/plugin-throttling";
|
|
|
|
import { retry } from "@octokit/plugin-retry";
|
2022-04-20 00:51:37 -04:00
|
|
|
import * as fs from "fs";
|
2022-04-19 20:46:50 -04:00
|
|
|
|
|
|
|
Octokit.plugin(throttling);
|
|
|
|
Octokit.plugin(retry);
|
|
|
|
const octokit = new Octokit({
|
|
|
|
auth: process.env.GITHUB_TOKEN,
|
2022-04-20 00:51:37 -04:00
|
|
|
userAgent: "open-goal/launcher",
|
2022-04-19 20:46:50 -04:00
|
|
|
log: {
|
2022-04-20 00:51:37 -04:00
|
|
|
debug: () => {},
|
|
|
|
info: () => {},
|
2022-04-19 20:46:50 -04:00
|
|
|
warn: console.warn,
|
2022-04-20 00:51:37 -04:00
|
|
|
error: console.error,
|
2022-04-19 20:46:50 -04:00
|
|
|
},
|
|
|
|
throttle: {
|
|
|
|
onRateLimit: (retryAfter, options) => {
|
|
|
|
octokit.log.warn(
|
2023-07-24 18:38:03 -04:00
|
|
|
`Request quota exhausted for request ${options.method} ${options.url}`,
|
2022-04-19 20:46:50 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
// Retry twice after hitting a rate limit error, then give up
|
|
|
|
if (options.request.retryCount <= 2) {
|
|
|
|
console.log(`Retrying after ${retryAfter} seconds!`);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onAbuseLimit: (retryAfter, options) => {
|
|
|
|
// does not retry, only logs a warning
|
|
|
|
octokit.log.warn(
|
2023-07-24 18:38:03 -04:00
|
|
|
`Abuse detected for request ${options.method} ${options.url}`,
|
2022-04-19 20:46:50 -04:00
|
|
|
);
|
|
|
|
},
|
2022-04-20 00:51:37 -04:00
|
|
|
},
|
2022-04-19 20:46:50 -04:00
|
|
|
});
|
|
|
|
|
2022-10-10 19:45:23 -04:00
|
|
|
// Parse out changes from the markdown body
|
|
|
|
/*
|
2022-04-28 19:59:25 -04:00
|
|
|
|
2022-10-10 19:45:23 -04:00
|
|
|
## What's Changed
|
2023-05-06 20:42:31 -04:00
|
|
|
* jak1/speedruns: Some final touches for speedrunning in jak 1 by @open-goal in https://github.com/open-goal/jak-project/pull/1830
|
2022-10-10 19:45:23 -04:00
|
|
|
|
|
|
|
**Full Changelog**: https://github.com/open-goal/jak-project/compare/v0.1.28...v0.1.29
|
|
|
|
|
|
|
|
*/
|
|
|
|
// Releases take the following format, if there is no `What's Changed` then it's a superfluous release, no changes
|
|
|
|
function changesFromBody(releaseBody) {
|
|
|
|
// Simple parsing to try and stay as little tied to the auto-format as possible
|
|
|
|
// Iterate through the lines, grab all github pull request links
|
|
|
|
let changes = [];
|
2023-03-14 20:14:28 -04:00
|
|
|
const lines = releaseBody.split("\n");
|
2022-10-10 19:45:23 -04:00
|
|
|
for (const line of lines) {
|
|
|
|
// check if the string contains a pull request link
|
|
|
|
if (!line.toLowerCase().match(/.*github.com\/[^/]*\/[^/]*\/pull.*/)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Parse out the critical parts of the line
|
|
|
|
let description = [];
|
|
|
|
let contributor = null;
|
|
|
|
let pullRequestUrl = null;
|
|
|
|
const words = line.replace(/^(\* )/, "").split(" ");
|
|
|
|
let i = 0;
|
|
|
|
while (i < words.length) {
|
|
|
|
const word = words[i];
|
|
|
|
if (word == "by") {
|
|
|
|
// found contributor, the next word should be the contributor
|
|
|
|
if (i + 1 < words.length) {
|
|
|
|
contributor = words[i + 1].replace(/^(@)/, "");
|
2023-03-14 20:14:28 -04:00
|
|
|
i += 2;
|
2022-10-10 19:45:23 -04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (word == "in") {
|
|
|
|
// found url, the next word should be the link
|
|
|
|
if (i + 1 < words.length) {
|
|
|
|
pullRequestUrl = words[i + 1];
|
2023-03-14 20:14:28 -04:00
|
|
|
i += 2;
|
2022-10-10 19:45:23 -04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Otherwise, just add it to the description
|
|
|
|
description.push(word);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
description = description.join(" ");
|
|
|
|
|
|
|
|
// Check if the pull request has already been added
|
|
|
|
let duplicate = false;
|
|
|
|
for (const entry of changes) {
|
|
|
|
if (entry.pullRequestUrl === pullRequestUrl) {
|
|
|
|
duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!duplicate) {
|
|
|
|
// Create the change
|
|
|
|
changes.push({
|
|
|
|
description: description,
|
|
|
|
contributor: contributor,
|
|
|
|
pullRequestUrl: pullRequestUrl,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all values from workflow
|
|
|
|
const releaseId = process.env.RELEASE_ID;
|
|
|
|
|
|
|
|
if (releaseId === undefined || releaseId === "") {
|
|
|
|
console.log("You didn't provide RELEASE_ID");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pull down the `launcher` release metadata
|
2023-03-12 17:04:57 -04:00
|
|
|
const { data: launcherRelease } = await octokit.rest.repos.getRelease({
|
2022-04-19 20:46:50 -04:00
|
|
|
owner: "open-goal",
|
2022-04-30 23:42:49 -04:00
|
|
|
repo: "launcher",
|
2022-10-10 19:45:23 -04:00
|
|
|
release_id: releaseId,
|
2022-04-19 20:46:50 -04:00
|
|
|
});
|
|
|
|
|
2022-10-10 19:45:23 -04:00
|
|
|
if (launcherRelease === undefined) {
|
|
|
|
console.log(`Couldn't find launcher release with id ${releaseId}`);
|
|
|
|
process.exit(1);
|
2022-04-30 23:42:49 -04:00
|
|
|
}
|
2023-07-31 02:15:18 -04:00
|
|
|
console.log(launcherRelease);
|
2022-04-30 23:42:49 -04:00
|
|
|
|
2022-10-10 19:45:23 -04:00
|
|
|
// Get changes for the launcher
|
|
|
|
const launcherChanges = changesFromBody(launcherRelease.body);
|
|
|
|
|
2023-07-31 00:12:44 -04:00
|
|
|
// Retrieve application bundle signatures
|
2022-06-20 22:54:33 -04:00
|
|
|
const { data: releaseAssets } = await octokit.rest.repos.listReleaseAssets({
|
|
|
|
owner: "open-goal",
|
|
|
|
repo: "launcher",
|
2022-10-10 19:45:23 -04:00
|
|
|
release_id: releaseId,
|
2022-06-20 22:54:33 -04:00
|
|
|
per_page: 100,
|
|
|
|
});
|
|
|
|
|
|
|
|
let linuxSignature = "";
|
|
|
|
let windowsSignature = "";
|
2023-07-31 00:12:44 -04:00
|
|
|
let macosSignature = "";
|
2022-06-20 22:54:33 -04:00
|
|
|
for (var i = 0; i < releaseAssets.length; i++) {
|
|
|
|
const asset = releaseAssets[i];
|
|
|
|
if (asset.name.toLowerCase().endsWith("appimage.tar.gz.sig")) {
|
|
|
|
const assetDownload = await octokit.rest.repos.getReleaseAsset({
|
|
|
|
owner: "open-goal",
|
|
|
|
repo: "launcher",
|
|
|
|
asset_id: asset.id,
|
|
|
|
headers: {
|
|
|
|
Accept: "application/octet-stream",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
linuxSignature = Buffer.from(assetDownload.data).toString();
|
|
|
|
}
|
|
|
|
if (asset.name.toLowerCase().endsWith("msi.zip.sig")) {
|
|
|
|
const assetDownload = await octokit.rest.repos.getReleaseAsset({
|
|
|
|
owner: "open-goal",
|
|
|
|
repo: "launcher",
|
|
|
|
asset_id: asset.id,
|
|
|
|
headers: {
|
|
|
|
Accept: "application/octet-stream",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
windowsSignature = Buffer.from(assetDownload.data).toString();
|
|
|
|
}
|
2023-07-31 00:12:44 -04:00
|
|
|
if (asset.name.toLowerCase().endsWith("app.tar.gz.sig")) {
|
|
|
|
const assetDownload = await octokit.rest.repos.getReleaseAsset({
|
|
|
|
owner: "open-goal",
|
|
|
|
repo: "launcher",
|
|
|
|
asset_id: asset.id,
|
|
|
|
headers: {
|
|
|
|
Accept: "application/octet-stream",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
macosSignature = Buffer.from(assetDownload.data).toString();
|
|
|
|
}
|
2022-06-20 22:54:33 -04:00
|
|
|
}
|
|
|
|
|
2022-04-28 19:59:25 -04:00
|
|
|
const releaseMeta = {
|
2022-10-10 19:45:23 -04:00
|
|
|
name: launcherRelease.tag_name,
|
|
|
|
notes: JSON.stringify({
|
2023-02-18 16:50:45 -05:00
|
|
|
changes: launcherChanges,
|
2022-10-10 19:45:23 -04:00
|
|
|
}),
|
|
|
|
pub_date: launcherRelease.created_at,
|
2022-04-28 20:06:44 -04:00
|
|
|
platforms: {
|
2022-06-18 22:12:30 -04:00
|
|
|
"linux-x86_64": {
|
2022-06-20 22:54:33 -04:00
|
|
|
signature: linuxSignature,
|
2022-04-30 23:48:57 -04:00
|
|
|
url: `https://github.com/open-goal/launcher/releases/download/${
|
2022-10-10 19:45:23 -04:00
|
|
|
launcherRelease.tag_name
|
2023-03-12 17:04:57 -04:00
|
|
|
}/OpenGOAL-Launcher_${launcherRelease.tag_name.replace(
|
2022-04-30 23:48:57 -04:00
|
|
|
"v",
|
2023-07-24 18:38:03 -04:00
|
|
|
"",
|
2022-06-18 22:58:47 -04:00
|
|
|
)}_amd64.AppImage.tar.gz`,
|
2022-04-28 19:59:25 -04:00
|
|
|
},
|
2022-06-18 22:12:30 -04:00
|
|
|
"windows-x86_64": {
|
2022-06-20 22:54:33 -04:00
|
|
|
signature: windowsSignature,
|
2022-04-30 23:48:57 -04:00
|
|
|
url: `https://github.com/open-goal/launcher/releases/download/${
|
2022-10-10 19:45:23 -04:00
|
|
|
launcherRelease.tag_name
|
2023-03-12 17:04:57 -04:00
|
|
|
}/OpenGOAL-Launcher_${launcherRelease.tag_name.replace(
|
|
|
|
"v",
|
2023-07-24 18:38:03 -04:00
|
|
|
"",
|
2023-03-12 17:04:57 -04:00
|
|
|
)}_x64_en-US.msi.zip`,
|
2022-04-28 20:06:44 -04:00
|
|
|
},
|
2023-07-31 02:15:18 -04:00
|
|
|
"darwin-x86_64": {
|
|
|
|
signature: macosSignature,
|
2023-07-31 02:19:46 -04:00
|
|
|
url: `https://github.com/open-goal/launcher/releases/download/${launcherRelease.tag_name}/OpenGOAL-Launcher_x64.app.tar.gz`,
|
2023-07-31 00:12:44 -04:00
|
|
|
},
|
2022-04-28 20:06:44 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
fs.writeFileSync(
|
2023-03-12 12:09:34 -04:00
|
|
|
"./.tauri/latest-release-v2.json",
|
2023-07-24 18:38:03 -04:00
|
|
|
JSON.stringify(releaseMeta, null, 2) + "\n",
|
2022-04-28 20:06:44 -04:00
|
|
|
);
|
2022-04-28 19:59:25 -04:00
|
|
|
|
2022-10-10 19:45:23 -04:00
|
|
|
// Publish the release
|
2022-04-30 23:42:49 -04:00
|
|
|
await octokit.rest.repos.updateRelease({
|
|
|
|
owner: "open-goal",
|
|
|
|
repo: "launcher",
|
2022-10-10 19:45:23 -04:00
|
|
|
release_id: launcherRelease.id,
|
2022-04-30 23:48:57 -04:00
|
|
|
draft: false,
|
2022-04-30 23:42:49 -04:00
|
|
|
});
|