feat: add support for alpha updates and enhance updater functionality

This commit is contained in:
Tunglies 2025-03-11 00:24:31 +08:00
parent d470bf2dd9
commit 3c7768b379
3 changed files with 88 additions and 43 deletions

View File

@ -2,9 +2,14 @@ import fetch from "node-fetch";
import { getOctokit, context } from "@actions/github"; import { getOctokit, context } from "@actions/github";
import { resolveUpdateLog } from "./updatelog.mjs"; import { resolveUpdateLog } from "./updatelog.mjs";
// Add stable update JSON filenames
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"; const UPDATE_JSON_PROXY = "update-proxy.json";
// Add alpha update JSON filenames
const ALPHA_TAG_NAME = "updater-alpha";
const ALPHA_UPDATE_JSON_FILE = "update-alpha.json";
const ALPHA_UPDATE_JSON_PROXY = "update-alpha-proxy.json";
/// generate update.json /// generate update.json
/// upload to update tag's release asset /// upload to update tag's release asset
@ -18,24 +23,43 @@ async function resolveUpdater() {
const { data: tags } = await github.rest.repos.listTags({ const { data: tags } = await github.rest.repos.listTags({
...options, ...options,
per_page: 10, per_page: 20, // Increase to have more chances to find alpha tags
page: 1, page: 1,
}); });
// get the latest publish tag // Get the latest stable tag and alpha tag
const tag = tags.find((t) => t.name.startsWith("v")); const stableTag = tags.find(
(t) => t.name.startsWith("v") && !t.name.includes("alpha"),
);
const alphaTag = tags.find((t) => t.name.includes("alpha"));
console.log(tag); console.log("Stable tag:", stableTag);
console.log("Alpha tag:", alphaTag);
console.log(); console.log();
const { data: latestRelease } = await github.rest.repos.getReleaseByTag({ // Process stable release
await processRelease(github, options, stableTag, false);
// Process alpha release if found
if (alphaTag) {
await processRelease(github, options, alphaTag, true);
}
}
// Process a release (stable or alpha) and generate update files
async function processRelease(github, options, tag, isAlpha) {
if (!tag) return;
const { data: release } = await github.rest.repos.getReleaseByTag({
...options, ...options,
tag: tag.name, tag: tag.name,
}); });
const updateData = { const updateData = {
name: tag.name, name: tag.name,
notes: await resolveUpdateLog(tag.name), // use updatelog.md notes: await resolveUpdateLog(tag.name).catch(
() => "No changelog available",
),
pub_date: new Date().toISOString(), pub_date: new Date().toISOString(),
platforms: { platforms: {
win64: { signature: "", url: "" }, // compatible with older formats win64: { signature: "", url: "" }, // compatible with older formats
@ -56,9 +80,10 @@ async function resolveUpdater() {
}, },
}; };
const promises = latestRelease.assets.map(async (asset) => { const promises = release.assets.map(async (asset) => {
const { name, browser_download_url } = asset; const { name, browser_download_url } = asset;
// Process all the platform URL and signature data
// win64 url // win64 url
if (name.endsWith("x64-setup.exe")) { if (name.endsWith("x64-setup.exe")) {
updateData.platforms.win64.url = browser_download_url; updateData.platforms.win64.url = browser_download_url;
@ -143,8 +168,7 @@ async function resolveUpdater() {
} }
}); });
// 生成一个代理github的更新文件 // Generate a proxy update file for accelerated GitHub resources
// 使用 https://hub.fastgit.xyz/ 做github资源的加速
const updateDataNew = JSON.parse(JSON.stringify(updateData)); const updateDataNew = JSON.parse(JSON.stringify(updateData));
Object.entries(updateDataNew.platforms).forEach(([key, value]) => { Object.entries(updateDataNew.platforms).forEach(([key, value]) => {
@ -156,42 +180,59 @@ async function resolveUpdater() {
} }
}); });
// update the update.json // Get the appropriate updater release based on isAlpha flag
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({ const releaseTag = isAlpha ? ALPHA_TAG_NAME : UPDATE_TAG_NAME;
...options,
tag: UPDATE_TAG_NAME,
});
// delete the old assets try {
for (let asset of updateRelease.assets) { const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
if (asset.name === UPDATE_JSON_FILE) { ...options,
await github.rest.repos.deleteReleaseAsset({ tag: releaseTag,
...options, });
asset_id: asset.id,
}); // File names based on release type
const jsonFile = isAlpha ? ALPHA_UPDATE_JSON_FILE : UPDATE_JSON_FILE;
const proxyFile = isAlpha ? ALPHA_UPDATE_JSON_PROXY : UPDATE_JSON_PROXY;
// Delete existing assets with these names
for (let asset of updateRelease.assets) {
if (asset.name === jsonFile) {
await github.rest.repos.deleteReleaseAsset({
...options,
asset_id: asset.id,
});
}
if (asset.name === proxyFile) {
await github.rest.repos
.deleteReleaseAsset({ ...options, asset_id: asset.id })
.catch(console.error); // do not break the pipeline
}
} }
if (asset.name === UPDATE_JSON_PROXY) { // Upload new assets
await github.rest.repos await github.rest.repos.uploadReleaseAsset({
.deleteReleaseAsset({ ...options, asset_id: asset.id }) ...options,
.catch(console.error); // do not break the pipeline release_id: updateRelease.id,
} name: jsonFile,
data: JSON.stringify(updateData, null, 2),
});
await github.rest.repos.uploadReleaseAsset({
...options,
release_id: updateRelease.id,
name: proxyFile,
data: JSON.stringify(updateDataNew, null, 2),
});
console.log(
`Successfully uploaded ${isAlpha ? "alpha" : "stable"} update files to ${releaseTag}`,
);
} catch (error) {
console.error(
`Failed to process ${isAlpha ? "alpha" : "stable"} release:`,
error.message,
);
} }
// upload new 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 // get the signature file content

View File

@ -511,5 +511,7 @@
"Fallback IP CIDR": "Fallback IP CIDR", "Fallback IP CIDR": "Fallback IP CIDR",
"IP CIDRs not using fallback servers": "IP CIDRs not using fallback servers, comma separated", "IP CIDRs not using fallback servers": "IP CIDRs not using fallback servers, comma separated",
"Fallback Domain": "Fallback Domain", "Fallback Domain": "Fallback Domain",
"Domains using fallback servers": "Domains using fallback servers, comma separated" "Domains using fallback servers": "Domains using fallback servers, comma separated",
"Enable Alpha Channel": "Enable Alpha Channel",
"Alpha versions may contain experimental features and bugs": "Alpha versions may contain experimental features and bugs"
} }

View File

@ -503,5 +503,7 @@
"Fallback IP CIDR": "回退 IP CIDR", "Fallback IP CIDR": "回退 IP CIDR",
"IP CIDRs not using fallback servers": "不使用回退服务器的 IP CIDR用逗号分隔", "IP CIDRs not using fallback servers": "不使用回退服务器的 IP CIDR用逗号分隔",
"Fallback Domain": "回退域名", "Fallback Domain": "回退域名",
"Domains using fallback servers": "使用回退服务器的域名,用逗号分隔" "Domains using fallback servers": "使用回退服务器的域名,用逗号分隔",
"Enable Alpha Channel": "启用 Alpha 通道",
"Alpha versions may contain experimental features and bugs": "Alpha 版本可能包含实验性功能和已知问题"
} }