diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 7b431a10..3054821d 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -37,12 +37,12 @@ jobs: key: ${{ runner.os }}-cargo-linux-amd64-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-linux-amd64- - - name: Install dependencies - run: npm install --legacy-peer-deps - - name: Update version from Git - run: node scripts/update-version.mjs + - name: Install dependencies + run: npm install --legacy-peer-deps + - name: Update version from Git + run: node scripts/update-version.mjs - run: cargo generate-lockfile --manifest-path src-tauri/Cargo.toml - - run: cargo fmt --manifest-path src-tauri/Cargo.toml --check + - run: cargo fmt --locked --manifest-path src-tauri/Cargo.toml --check rust-clippy: runs-on: ubuntu-latest @@ -77,7 +77,7 @@ jobs: key: ${{ runner.os }}-cargo-linux-amd64-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-linux-amd64- - - run: cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warnings + - run: cargo clippy --locked --manifest-path src-tauri/Cargo.toml -- -D warnings rust-tests: runs-on: ubuntu-latest @@ -112,7 +112,7 @@ jobs: key: ${{ runner.os }}-cargo-linux-amd64-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-linux-amd64- - - run: cargo test --manifest-path src-tauri/Cargo.toml -- --test-threads=1 + - run: cargo test --locked --manifest-path src-tauri/Cargo.toml -- --test-threads=1 frontend-typecheck: runs-on: ubuntu-latest diff --git a/scripts/update-version.mjs b/scripts/update-version.mjs index d8300674..08583761 100644 --- a/scripts/update-version.mjs +++ b/scripts/update-version.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node import { execSync } from 'child_process'; -import { readFileSync, writeFileSync, existsSync } from 'fs'; +import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'; import { resolve, dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -16,11 +16,19 @@ function isValidSemver(version) { return /^[0-9]+\.[0-9]+\.[0-9]+$/.test(version); } +function validateGitRepo(root) { + if (!existsSync(resolve(root, '.git'))) { + throw new Error(`Not a Git repository: ${root}`); + } +} + function getVersionFromGit() { + validateGitRepo(projectRoot); try { const output = execSync('git describe --tags --abbrev=0', { encoding: 'utf-8', - cwd: projectRoot + cwd: projectRoot, + shell: false }); let version = output.trim(); @@ -29,13 +37,29 @@ function getVersionFromGit() { // Validate it's a valid semver if (!isValidSemver(version)) { - console.warn(`Invalid version format "${version}" from git describe, falling back to 0.2.50`); - return '0.2.50'; + const pkgJsonVersion = getFallbackVersion(); + console.warn(`Invalid version format "${version}" from git describe, using package.json fallback: ${pkgJsonVersion}`); + return pkgJsonVersion; } return version; } catch (e) { - console.warn('Failed to get version from Git tags, using fallback: 0.2.50'); + const pkgJsonVersion = getFallbackVersion(); + console.warn(`Failed to get version from Git tags, using package.json fallback: ${pkgJsonVersion}`); + return pkgJsonVersion; + } +} + +function getFallbackVersion() { + const pkgPath = resolve(projectRoot, 'package.json'); + if (!existsSync(pkgPath)) { + return '0.2.50'; + } + try { + const content = readFileSync(pkgPath, 'utf-8'); + const json = JSON.parse(content); + return json.version || '0.2.50'; + } catch { return '0.2.50'; } } @@ -77,50 +101,11 @@ function updateTOML(path, version) { console.log(`✓ Updated ${path} to ${version}`); } -function updateCargoLock(version) { - const lockPath = resolve(projectRoot, 'src-tauri/Cargo.lock'); - if (!existsSync(lockPath)) { - throw new Error(`Cargo.lock not found: ${lockPath}`); - } - - const content = readFileSync(lockPath, 'utf-8'); - const lines = content.split('\n'); - const output = []; - - let inTrcaaPackage = false; - - for (const line of lines) { - if (line.match(/^\[\[package\]\]/)) { - inTrcaaPackage = false; - } - - if (inTrcaaPackage && line.match(/^name\s*=\s*"trcaa"/)) { - output.push(line); - continue; - } - - if (inTrcaaPackage && line.match(/^version\s*=\s*"/)) { - output.push(`version = "${version}"`); - inTrcaaPackage = false; - } else { - output.push(line); - } - - if (line.match(/^name\s*=\s*"trcaa"/)) { - inTrcaaPackage = true; - } - } - - writeFileSync(lockPath, output.join('\n') + '\n', 'utf-8'); - console.log(`✓ Updated Cargo.lock to ${version}`); -} - const version = getVersionFromGit(); console.log(`Setting version to: ${version}`); updatePackageJson(version); updateTOML('src-tauri/Cargo.toml', version); updateTOML('src-tauri/tauri.conf.json', version); -updateCargoLock(version); console.log(`✓ All version fields updated to ${version}`); diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5e1d8bd9..f8de467c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -7710,5 +7710,3 @@ checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296" dependencies = [ "zune-core", ] - - diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 298db0c9..c43ff61a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -54,3 +54,5 @@ opt-level = "s" strip = true + + diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 888de4f4..84be9cc8 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -43,3 +43,5 @@ } } + +