feat: update release workflow to trigger builds via git tags and add publish version script

This commit is contained in:
Tunglies
2025-06-03 13:15:34 +08:00
Unverified
parent 33237fbba8
commit 3a26896644
3 changed files with 81 additions and 4 deletions

View File

@@ -1,7 +1,15 @@
name: Release Build
# TODO: 参照 alpha.yml 修改,实现稳定版发布,只允许通过 git tag 触发
on:
workflow_dispatch:
# ! 为了避免重复发布版本,应当通过独特 git tag 触发。
# ! 不再使用 workflow_dispatch 触发。
# workflow_dispatch:
push:
# ? 应当限制在 main 分支上触发发布。
# branches:
# - main
tags:
- "v*.*.*"
permissions: write-all
env:
CARGO_INCREMENTAL: 0
@@ -13,6 +21,7 @@ concurrency:
jobs:
release:
name: Release Build
strategy:
fail-fast: false
matrix:
@@ -88,6 +97,7 @@ jobs:
args: --target ${{ matrix.target }}
release-for-linux-arm:
name: Release Build for Linux ARM
strategy:
fail-fast: false
matrix:
@@ -209,6 +219,7 @@ jobs:
src-tauri/target/${{ matrix.target }}/release/bundle/rpm/*.rpm
release-for-fixed-webview2:
name: Release Build for Fixed WebView2
strategy:
fail-fast: false
matrix:
@@ -303,6 +314,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release-update:
name: Release Update
runs-on: ubuntu-latest
needs: [release, release-for-linux-arm]
steps:
@@ -353,6 +365,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
submit-to-winget:
name: Submit to Winget
runs-on: ubuntu-latest
needs: [release-update]
steps:

View File

@@ -1,6 +1,6 @@
{
"name": "clash-verge",
"version": "2.3.0-alpha.0",
"version": "2.3.0-alpha",
"license": "GPL-3.0-only",
"scripts": {
"dev": "cross-env RUST_BACKTRACE=1 tauri dev -f verge-dev",
@@ -18,7 +18,7 @@
"portable-fixed-webview2": "node scripts/portable-fixed-webview2.mjs",
"fix-alpha-version": "node scripts/fix-alpha_version.mjs",
"release-version": "node scripts/release-version.mjs",
"release-alpha-version": "node scripts/release-alpha_version.mjs",
"publish-version": "node scripts/publish-version.mjs",
"prepare": "husky",
"fmt": "cargo fmt --manifest-path ./src-tauri/Cargo.toml",
"clippy": "cargo clippy --manifest-path ./src-tauri/Cargo.toml"

View File

@@ -0,0 +1,64 @@
// scripts/publish-version.mjs
import { spawn } from "child_process";
import { existsSync } from "fs";
import path from "path";
const rootDir = process.cwd();
const scriptPath = path.join(rootDir, "scripts", "release-version.mjs");
if (!existsSync(scriptPath)) {
console.error("release-version.mjs not found!");
process.exit(1);
}
const versionArg = process.argv[2];
if (!versionArg) {
console.error("Usage: pnpm publish-version <version>");
process.exit(1);
}
// 1. 调用 release-version.mjs
const runRelease = () =>
new Promise((resolve, reject) => {
const child = spawn("node", [scriptPath, versionArg], { stdio: "inherit" });
child.on("exit", (code) => {
if (code === 0) resolve();
else reject(new Error("release-version failed"));
});
});
// 2. 判断是否需要打 tag
function isSemver(version) {
return /^v?\d+\.\d+\.\d+(-alpha)?$/.test(version);
}
async function run() {
await runRelease();
let tag = null;
if (versionArg === "alpha") {
// 读取 package.json 里的主版本
const pkg = await import(path.join(rootDir, "package.json"), { assert: { type: "json" } });
tag = `v${pkg.default.version}-alpha`;
} else if (isSemver(versionArg)) {
// 1.2.3 或 v1.2.3
tag = versionArg.startsWith("v") ? versionArg : `v${versionArg}`;
}
if (tag) {
// 打 tag 并推送
const { execSync } = await import("child_process");
try {
execSync(`git tag ${tag}`, { stdio: "inherit" });
execSync(`git push origin ${tag}`, { stdio: "inherit" });
console.log(`[INFO]: Git tag ${tag} created and pushed.`);
} catch (e) {
console.error(`[ERROR]: Failed to create or push git tag: ${tag}`);
process.exit(1);
}
} else {
console.log("[INFO]: No git tag created for this version.");
}
}
run();