Skip to content

Commit

Permalink
chore: updater proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Mar 19, 2022
1 parent b756ae3 commit ab0d516
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
37 changes: 35 additions & 2 deletions scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getOctokit, context } from "@actions/github";

const UPDATE_TAG_NAME = "updater";
const UPDATE_JSON_FILE = "update.json";
const UPDATE_JSON_PROXY = "update-proxy.json";

/// generate update.json
/// upload to update tag's release asset
Expand Down Expand Up @@ -83,7 +84,7 @@ async function resolveRelease() {
console.log(updateData);

// maybe should test the signature as well
const { darwin, win64 } = updateData.platforms;
const { darwin, win64, linux } = updateData.platforms;
if (!darwin.url) {
console.log(`[Error]: failed to parse release for darwin`);
delete updateData.platforms.darwin;
Expand All @@ -92,29 +93,61 @@ async function resolveRelease() {
console.log(`[Error]: failed to parse release for 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
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
...options,
tag: UPDATE_TAG_NAME,
});

// delete the old assets
for (let asset of updateRelease.assets) {
if (asset.name === UPDATE_JSON_FILE) {
await github.rest.repos.deleteReleaseAsset({
...options,
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({
...options,
release_id: updateRelease.id,
name: UPDATE_JSON_FILE,
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
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"updater": {
"active": true,
"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,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDExNUFBNTBBN0FDNEFBRTUKUldUbHFzUjZDcVZhRVRJM25NS3NkSFlFVElxUkNZMzZ6bHUwRVJjb2F3alJXVzRaeDdSaTA2YWYK"
Expand Down

0 comments on commit ab0d516

Please sign in to comment.