Skip to content

Commit 1cf7808

Browse files
authored
chore: update version sync to refresh cargo lock (#486)
1 parent 4db6e67 commit 1cf7808

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

scripts/sync-version.cjs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,41 @@ cargoToml = cargoToml.replace(/^version = ".*"$/m, `version = "${newVersion}"`)
3939
// Write updated Cargo.toml
4040
fs.writeFileSync(cargoTomlPath, cargoToml)
4141

42-
if (currentVersion === newVersion) {
42+
// Read Cargo.lock
43+
const cargoLockPath = path.join(__dirname, '../src-tauri/Cargo.lock')
44+
let cargoLock = fs.readFileSync(cargoLockPath, 'utf8')
45+
46+
// Extract current version from Cargo.lock for algokit-lora package
47+
const lockCurrentVersionMatch = cargoLock.match(/\[\[package\]\]\s*\nname = "algokit-lora"\s*\nversion = "(.+?)"/s)
48+
const lockCurrentVersion = lockCurrentVersionMatch ? lockCurrentVersionMatch[1] : 'unknown'
49+
50+
console.log(`🔒 Current Cargo.lock version: ${lockCurrentVersion}`)
51+
52+
// Update version in Cargo.lock for algokit-lora package
53+
cargoLock = cargoLock.replace(/(\[\[package\]\]\s*\nname = "algokit-lora"\s*\nversion = ")([^"]+)(")/s, `$1${newVersion}$3`)
54+
55+
// Write updated Cargo.lock
56+
fs.writeFileSync(cargoLockPath, cargoLock)
57+
58+
if (currentVersion === newVersion && lockCurrentVersion === newVersion) {
4359
console.log(`✅ Versions already synchronized at ${newVersion}`)
4460
} else {
4561
console.log(`✅ Updated Cargo.toml version: ${currentVersion}${newVersion}`)
62+
console.log(`✅ Updated Cargo.lock version: ${lockCurrentVersion}${newVersion}`)
4663
}
4764

48-
// Verify the change was applied correctly
65+
// Verify the changes were applied correctly
4966
const updatedCargoToml = fs.readFileSync(cargoTomlPath, 'utf8')
5067
const verifyVersionMatch = updatedCargoToml.match(/^version = "(.+)"$/m)
5168
const verifyVersion = verifyVersionMatch ? verifyVersionMatch[1] : 'unknown'
5269

53-
if (verifyVersion !== newVersion) {
54-
console.error(`❌ Version sync failed! Expected ${newVersion}, got ${verifyVersion}`)
70+
const updatedCargoLock = fs.readFileSync(cargoLockPath, 'utf8')
71+
const verifyLockVersionMatch = updatedCargoLock.match(/\[\[package\]\]\s*\nname = "algokit-lora"\s*\nversion = "(.+?)"/s)
72+
const verifyLockVersion = verifyLockVersionMatch ? verifyLockVersionMatch[1] : 'unknown'
73+
74+
if (verifyVersion !== newVersion || verifyLockVersion !== newVersion) {
75+
console.error(`❌ Cargo.toml version sync failed! Expected ${newVersion}, got ${verifyVersion}`)
76+
console.error(`❌ Cargo.lock version sync failed! Expected ${newVersion}, got ${verifyLockVersion}`)
5577
process.exit(1)
5678
}
5779

0 commit comments

Comments
 (0)