chore: enhance publish ci
This commit is contained in:
parent
c9c06f8a3d
commit
81ee989f1f
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: CI
|
name: Release CI
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ jobs:
|
|||||||
yarn run check
|
yarn run check
|
||||||
|
|
||||||
- name: Tauri build
|
- name: Tauri build
|
||||||
uses: tauri-apps/tauri-action@v0
|
uses: tauri-apps/tauri-action@b9ce5d7dc68082d21d30a60103b0ab8c5ddae3a1
|
||||||
# enable cache even though failed
|
# enable cache even though failed
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
@ -95,6 +95,5 @@ jobs:
|
|||||||
|
|
||||||
- name: Release update.json
|
- name: Release update.json
|
||||||
run: yarn run release
|
run: yarn run release
|
||||||
continue-on-error: true
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { createRequire } from "module";
|
import fetch from "node-fetch";
|
||||||
import { getOctokit, context } from "@actions/github";
|
import { getOctokit, context } from "@actions/github";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const UPDATE_TAG_NAME = "updater";
|
||||||
|
const UPDATE_JSON_FILE = "update.json";
|
||||||
|
|
||||||
/// generate update.json
|
/// generate update.json
|
||||||
/// upload to update tag's release asset
|
/// upload to update tag's release asset
|
||||||
@ -10,46 +11,85 @@ async function resolveRelease() {
|
|||||||
throw new Error("GITHUB_TOKEN is required");
|
throw new Error("GITHUB_TOKEN is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageJson = require("../package.json");
|
const options = { owner: context.repo.owner, repo: context.repo.repo };
|
||||||
|
const github = getOctokit(process.env.GITHUB_TOKEN);
|
||||||
|
|
||||||
|
const { data: tags } = await github.rest.repos.listTags({
|
||||||
|
...options,
|
||||||
|
per_page: 10,
|
||||||
|
page: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
// get the latest publish tag
|
||||||
|
const tag = tags.find((t) => t.name.startsWith("v"));
|
||||||
|
|
||||||
|
console.log(tag);
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
const { data: latestRelease } = await github.rest.repos.getReleaseByTag({
|
||||||
|
...options,
|
||||||
|
tag: tag.name,
|
||||||
|
});
|
||||||
|
|
||||||
const { version } = packageJson;
|
|
||||||
const urlPrefix = "https://github.com/zzzgydi/clash-verge/releases/download";
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
name: `v${version}`,
|
name: tag.name,
|
||||||
notes: `Version ${version} is available now!!!`,
|
notes: latestRelease.body, // use the release body directly
|
||||||
pub_date: new Date().toISOString(),
|
pub_date: new Date().toISOString(),
|
||||||
platforms: {
|
platforms: {
|
||||||
win64: {
|
win64: { signature: "", url: "" },
|
||||||
signature: "",
|
darwin: { signature: "", url: "" },
|
||||||
url: `${urlPrefix}/v${version}/clash-verge_${version}_x64.msi.zip`,
|
|
||||||
},
|
|
||||||
darwin: {
|
|
||||||
signature: "",
|
|
||||||
url: `${urlPrefix}/v${version}/clash-verge.app.tar.gz`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`Generating Version "${version}" update.json`);
|
const promises = latestRelease.assets.map(async (asset) => {
|
||||||
|
const { name, browser_download_url } = asset;
|
||||||
|
|
||||||
const github = getOctokit(process.env.GITHUB_TOKEN);
|
// win64 url
|
||||||
|
if (/\.msi\.zip$/.test(name)) {
|
||||||
const { data: release } = await github.rest.repos.getReleaseByTag({
|
updateData.platforms.win64.url = browser_download_url;
|
||||||
owner: context.repo.owner,
|
}
|
||||||
repo: context.repo.repo,
|
// darwin url
|
||||||
tag: "updater",
|
if (/\.app\.tar\.gz$/.test(name)) {
|
||||||
});
|
updateData.platforms.darwin.url = browser_download_url;
|
||||||
const { data: assets } = await github.rest.repos.listReleaseAssets({
|
}
|
||||||
owner: context.repo.owner,
|
// win64 signature
|
||||||
repo: context.repo.repo,
|
if (/\.msi\.zip\.sig$/.test(name)) {
|
||||||
release_id: release.id,
|
updateData.platforms.win64.signature = await getSignature(
|
||||||
|
browser_download_url
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// darwin signature
|
||||||
|
if (/\.app\.tar\.gz\.sig$/.test(name)) {
|
||||||
|
updateData.platforms.darwin.signature = await getSignature(
|
||||||
|
browser_download_url
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let asset of assets) {
|
await Promise.allSettled(promises);
|
||||||
if (asset.name === "update.json") {
|
console.log(updateData);
|
||||||
|
|
||||||
|
// maybe should test the signature as well
|
||||||
|
const { darwin, win64 } = updateData.platforms;
|
||||||
|
if (!darwin.url) {
|
||||||
|
console.log(`[Error]: failed to parse release for darwin`);
|
||||||
|
delete updateData.platforms.darwin;
|
||||||
|
}
|
||||||
|
if (!win64.url) {
|
||||||
|
console.log(`[Error]: failed to parse release for win64`);
|
||||||
|
delete updateData.platforms.win64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the update.json
|
||||||
|
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
|
||||||
|
...options,
|
||||||
|
tag: UPDATE_TAG_NAME,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let asset of updateRelease.assets) {
|
||||||
|
if (asset.name === UPDATE_JSON_FILE) {
|
||||||
await github.rest.repos.deleteReleaseAsset({
|
await github.rest.repos.deleteReleaseAsset({
|
||||||
owner: context.repo.owner,
|
...options,
|
||||||
repo: context.repo.repo,
|
|
||||||
asset_id: asset.id,
|
asset_id: asset.id,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -57,12 +97,21 @@ async function resolveRelease() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await github.rest.repos.uploadReleaseAsset({
|
await github.rest.repos.uploadReleaseAsset({
|
||||||
owner: context.repo.owner,
|
...options,
|
||||||
repo: context.repo.repo,
|
release_id: updateRelease.id,
|
||||||
release_id: release.id,
|
name: UPDATE_JSON_FILE,
|
||||||
name: "update.json",
|
|
||||||
data: JSON.stringify(updateData, null, 2),
|
data: JSON.stringify(updateData, null, 2),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveRelease();
|
// get the signature file content
|
||||||
|
async function getSignature(url) {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/octet-stream" },
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveRelease().catch(console.error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user