fix: add --locked to cargo commands and improve version update script
Some checks failed
Test / rust-fmt-check (pull_request) Failing after 1m11s
Test / frontend-typecheck (pull_request) Successful in 1m18s
Test / frontend-tests (pull_request) Successful in 1m21s
Test / rust-clippy (pull_request) Failing after 3m25s
PR Review Automation / review (pull_request) Successful in 3m37s
Test / rust-tests (pull_request) Successful in 5m9s
Some checks failed
Test / rust-fmt-check (pull_request) Failing after 1m11s
Test / frontend-typecheck (pull_request) Successful in 1m18s
Test / frontend-tests (pull_request) Successful in 1m21s
Test / rust-clippy (pull_request) Failing after 3m25s
PR Review Automation / review (pull_request) Successful in 3m37s
Test / rust-tests (pull_request) Successful in 5m9s
- Add --locked to fmt, clippy, and test commands in CI - Remove updateCargoLock() and rely on cargo generate-lockfile - Add .git directory existence check in update-version.mjs - Use package.json as dynamic fallback instead of hardcoded 0.2.50 - Ensure execSync uses shell: false explicitly
This commit is contained in:
parent
007d0ee9d5
commit
9248811076
@ -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
|
||||
|
||||
@ -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}`);
|
||||
|
||||
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@ -7710,5 +7710,3 @@ checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@ -54,3 +54,5 @@ opt-level = "s"
|
||||
strip = true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -43,3 +43,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user