chore: updater proxy

This commit is contained in:
GyDi 2022-03-19 11:14:12 +08:00
parent b756ae39d0
commit ab0d516d91
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084
2 changed files with 37 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import { getOctokit, context } from "@actions/github";
const UPDATE_TAG_NAME = "updater"; const UPDATE_TAG_NAME = "updater";
const UPDATE_JSON_FILE = "update.json"; const UPDATE_JSON_FILE = "update.json";
const UPDATE_JSON_PROXY = "update-proxy.json";
/// generate update.json /// generate update.json
/// upload to update tag's release asset /// upload to update tag's release asset
@ -83,7 +84,7 @@ async function resolveRelease() {
console.log(updateData); console.log(updateData);
// maybe should test the signature as well // maybe should test the signature as well
const { darwin, win64 } = updateData.platforms; const { darwin, win64, linux } = updateData.platforms;
if (!darwin.url) { if (!darwin.url) {
console.log(`[Error]: failed to parse release for darwin`); console.log(`[Error]: failed to parse release for darwin`);
delete updateData.platforms.darwin; delete updateData.platforms.darwin;
@ -92,6 +93,24 @@ async function resolveRelease() {
console.log(`[Error]: failed to parse release for win64`); console.log(`[Error]: failed to parse release for win64`);
delete updateData.platforms.win64; delete updateData.platforms.win64;
} }
if (!linux.url) {
console.log(`[Error]: failed to parse release for linux`);
delete updateData.platforms.linux;
}
// 生成一个代理github的更新文件
// 使用 https://hub.fastgit.xyz/ 做github资源的加速
const updateDataNew = JSON.parse(JSON.stringify(updateData));
Object.keys(updateDataNew.platforms).forEach((key) => {
if (updateDataNew.platforms[key]) {
updateDataNew.platforms[key].url = updateDataNew.platforms[
key
].url.replace("https://github.com/", "https://hub.fastgit.xyz/");
} else {
console.log(`[Error]: updateDataNew.platforms.${key} is null`);
}
});
// update the update.json // update the update.json
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({ const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
@ -99,22 +118,36 @@ async function resolveRelease() {
tag: UPDATE_TAG_NAME, tag: UPDATE_TAG_NAME,
}); });
// delete the old assets
for (let asset of updateRelease.assets) { for (let asset of updateRelease.assets) {
if (asset.name === UPDATE_JSON_FILE) { if (asset.name === UPDATE_JSON_FILE) {
await github.rest.repos.deleteReleaseAsset({ await github.rest.repos.deleteReleaseAsset({
...options, ...options,
asset_id: asset.id, asset_id: asset.id,
}); });
break; }
if (asset.name === UPDATE_JSON_PROXY) {
await github.rest.repos
.deleteReleaseAsset({ ...options, asset_id: asset.id })
.catch(console.error); // do not break the pipeline
} }
} }
// upload assets
await github.rest.repos.uploadReleaseAsset({ await github.rest.repos.uploadReleaseAsset({
...options, ...options,
release_id: updateRelease.id, release_id: updateRelease.id,
name: UPDATE_JSON_FILE, name: UPDATE_JSON_FILE,
data: JSON.stringify(updateData, null, 2), data: JSON.stringify(updateData, null, 2),
}); });
await github.rest.repos.uploadReleaseAsset({
...options,
release_id: updateRelease.id,
name: UPDATE_JSON_PROXY,
data: JSON.stringify(updateDataNew, null, 2),
});
} }
// get the signature file content // get the signature file content

View File

@ -52,7 +52,8 @@
"updater": { "updater": {
"active": true, "active": true,
"endpoints": [ "endpoints": [
"https://github.com/zzzgydi/clash-verge/releases/download/updater/update.json" "https://github.com/zzzgydi/clash-verge/releases/download/updater/update.json",
"https://hub.fastgit.xyz/zzzgydi/clash-verge/releases/download/updater/update-proxy.json"
], ],
"dialog": false, "dialog": false,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDExNUFBNTBBN0FDNEFBRTUKUldUbHFzUjZDcVZhRVRJM25NS3NkSFlFVElxUkNZMzZ6bHUwRVJjb2F3alJXVzRaeDdSaTA2YWYK" "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDExNUFBNTBBN0FDNEFBRTUKUldUbHFzUjZDcVZhRVRJM25NS3NkSFlFVElxUkNZMzZ6bHUwRVJjb2F3alJXVzRaeDdSaTA2YWYK"