From 23d63cada645ea21c67d1db01637ebee4f19a470 Mon Sep 17 00:00:00 2001 From: imengying Date: Mon, 10 Aug 2026 20:42:44 +0800 Subject: [PATCH] Fixes and improvements --- .github/workflows/release.yml | 27 +++++++++------------------ agent/src/main.rs | 5 ++++- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3f46ec..92930f1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,47 +3,37 @@ name: Build tagged release on: push: tags: - - "*.*.*" + - "v*.*.*" workflow_dispatch: inputs: version: - description: Three-part release version, for example 0.0.1 + description: Tag version with a v prefix, for example v0.0.1 required: true - default: 0.0.1 + default: v0.0.1 permissions: contents: write jobs: metadata: - name: Validate version + name: Validate tag runs-on: ubuntu-latest outputs: version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@v6 - id: version - name: Validate three-part version + name: Validate three-part tag shell: bash env: RAW_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }} run: | - version="${RAW_VERSION#v}" - if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Tag must be a three-part version such as v1.2.3 or 1.2.3" >&2 + if [[ ! "$RAW_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Tag must use the v-prefixed format v1.2.3" >&2 exit 1 fi - root_version=$(node -p "require('./package.json').version") - frontend_version=$(node -p "require('./frontend/package.json').version") - worker_version=$(awk -F '"' '/^version = / { print $2; exit }' Cargo.toml) - agent_version=$(awk -F '"' '/^version = / { print $2; exit }' agent/Cargo.toml) - for package_version in "$root_version" "$frontend_version" "$worker_version" "$agent_version"; do - if [ "$package_version" != "$version" ]; then - echo "Tag version $version does not match package version $package_version" >&2 - exit 1 - fi - done + version="${RAW_VERSION#v}" echo "version=$version" >> "$GITHUB_OUTPUT" agent: @@ -52,6 +42,7 @@ jobs: runs-on: ${{ matrix.runner }} env: CARGO_TARGET_DIR: target/agent + CF_MONITOR_AGENT_VERSION: ${{ needs.metadata.outputs.version }} strategy: fail-fast: false matrix: diff --git a/agent/src/main.rs b/agent/src/main.rs index ff95a60..3ab3530 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -23,7 +23,10 @@ use sysinfo::{Disks, Networks, System}; #[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))] compile_error!("cf-monitor-agent supports Linux, Windows, and macOS"); -const VERSION: &str = env!("CARGO_PKG_VERSION"); +const VERSION: &str = match option_env!("CF_MONITOR_AGENT_VERSION") { + Some(version) if !version.is_empty() => version, + _ => env!("CARGO_PKG_VERSION"), +}; const RELEASE_DOWNLOAD_BASE: &str = "https://github.com/imengying/CF-Monitor/releases/latest/download"; const PROBE_ATTEMPTS: usize = 4;