-
Notifications
You must be signed in to change notification settings - Fork 0
/
do.ts
66 lines (60 loc) · 2.14 KB
/
do.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Octokit } from "@octokit/rest";
const { GH_TOKEN } = process.env;
let octokit = new Octokit();
if (GH_TOKEN) {
octokit = new Octokit({auth: GH_TOKEN!});
}
interface outputItem {
asset_name: string;
output_file: string;
}
let toDo: outputItem[] = [
{
asset_name: "installer.exe",
output_file: "latest.txt"
},
{
asset_name: "CorporateClash.dmg",
output_file: "latest_macos.txt"
}
];
(async () => {
let release = await octokit.repos.getLatestRelease({ owner: "CorporateClash", repo: "pyside2-releases" });
for await (const todoItem of toDo) {
let _assets = release.data.assets.filter(asset => asset.name == todoItem.asset_name);
if (_assets.length != 1) {
console.log(`Error: unable to find ${todoItem.asset_name} in the latest release on GitHub.`);
continue;
}
let itemAsset = _assets[0];
console.log(itemAsset.browser_download_url);
let existing = await octokit.repos.getContents({
owner: "CorporateClash",
repo: "pyside2-releases",
path: todoItem.output_file,
}).catch((err) => { console.log(err); console.log(`Failed getting ${todoItem.output_file}, assuming nonexistant`); });
if (!process.env.GITHUB_ACTIONS) continue;
if (existing) {
await octokit.repos.createOrUpdateFile({
owner: "CorporateClash",
repo: "pyside2-releases",
path: todoItem.output_file,
// @ts-ignore
sha: existing.data.sha,
message: "Update latest release url",
content: Buffer.from(itemAsset.browser_download_url).toString('base64')
});
}
else {
await octokit.repos.createOrUpdateFile({
owner: "CorporateClash",
repo: "pyside2-releases",
path: todoItem.output_file,
message: "Update latest release url",
content: Buffer.from(itemAsset.browser_download_url).toString('base64')
});
}
}
console.log("Done!")
process.exit(0)
})()