Skip to content

Commit e81f36c

Browse files
committed
fix(ci): tighten Cargo.lock version matching
1 parent a05f4a5 commit e81f36c

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

scripts/prepare-resources/version-sync.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const readAstrbotVersionFromPyproject = async ({ sourceDir }) => {
5151

5252
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
5353
const CARGO_LOCK_PACKAGE_HEADER = /^\s*\[\[package\]\]\s*(?:#.*)?$/;
54+
const CARGO_LOCK_VERSION_LINE = /^\s*version\s*=/;
5455

5556
class CargoLockPackageNotFoundError extends Error {
5657
constructor(packageName) {
@@ -132,7 +133,7 @@ const updateCargoLockPackageVersion = ({ cargoLock, packageName, version }) => {
132133
}
133134

134135
for (let index = packageNameLineIndex + 1; index < end; index += 1) {
135-
if (!lines[index].trimStart().startsWith('version')) {
136+
if (!CARGO_LOCK_VERSION_LINE.test(lines[index])) {
136137
continue;
137138
}
138139

scripts/prepare-resources/version-sync.test.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,50 @@ version = "9.9.9"
207207
}
208208
});
209209

210+
test('syncDesktopVersionFiles only updates the version key, not similarly prefixed keys', async () => {
211+
const tempDir = await mkdtemp(path.join(os.tmpdir(), 'astrbot-sync-'));
212+
try {
213+
const srcTauriDir = path.join(tempDir, 'src-tauri');
214+
await mkdir(srcTauriDir, { recursive: true });
215+
216+
await writeFile(
217+
path.join(tempDir, 'package.json'),
218+
`${JSON.stringify({ name: 'test', version: '0.1.0' }, null, 2)}\n`,
219+
'utf8',
220+
);
221+
await writeFile(
222+
path.join(srcTauriDir, 'tauri.conf.json'),
223+
`${JSON.stringify({ version: '0.1.0' }, null, 2)}\n`,
224+
'utf8',
225+
);
226+
await writeFile(
227+
path.join(srcTauriDir, 'Cargo.toml'),
228+
`[package]\nname = "${DESKTOP_TAURI_CRATE_NAME}"\nversion = "0.1.0"\n`,
229+
'utf8',
230+
);
231+
await writeFile(
232+
path.join(srcTauriDir, 'Cargo.lock'),
233+
`version = 4
234+
235+
[[package]]
236+
name = "${DESKTOP_TAURI_CRATE_NAME}"
237+
versioned_dep = "keep-me"
238+
version = "0.1.0"
239+
`,
240+
'utf8',
241+
);
242+
243+
await syncDesktopVersionFiles({ projectRoot: tempDir, version: '2.3.4' });
244+
245+
const cargoLock = await readFile(path.join(srcTauriDir, 'Cargo.lock'), 'utf8');
246+
247+
assert.match(cargoLock, /versioned_dep = "keep-me"/);
248+
assert.match(cargoLock, /version = "2.3.4"/);
249+
} finally {
250+
await rm(tempDir, { recursive: true, force: true });
251+
}
252+
});
253+
210254
test('syncDesktopVersionFiles skips Cargo.lock updates when the desktop crate is missing', async () => {
211255
const tempDir = await mkdtemp(path.join(os.tmpdir(), 'astrbot-sync-'));
212256
const warnings = [];

0 commit comments

Comments
 (0)