Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ jobs:
- name: Check CHANGELOG.md has a section for the current version
run: node scripts/check-changelog.mjs

# Same job, same reason: it reads files and needs nothing installed, so a lockfile that
# disagrees with its manifest or with the other ecosystem fails here in seconds. v1.12.2
# got through every test and failed only inside tauri build, on all six release legs.
- name: Check the manifests and lockfiles agree
run: node scripts/check-lockfiles.mjs

frontend-tests:
name: Frontend Tests
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -179,7 +185,9 @@ jobs:

- name: Run Rust tests
working-directory: src-tauri
run: cargo test --verbose
# --locked: a Cargo.lock that no longer satisfies Cargo.toml fails the run instead of
# being re-resolved on the runner, where the result is tested and then thrown away.
run: cargo test --locked --verbose

# Both lints gate. They were advisory while the tree was not clean - and an advisory step
# that fails on every run is noise nobody reads, so findings piled up: by v1.9.0 clippy had
Expand All @@ -196,7 +204,7 @@ jobs:
- name: Run Clippy
if: matrix.os == 'ubuntu-latest'
working-directory: src-tauri
run: cargo clippy --all-targets -- -D warnings
run: cargo clippy --locked --all-targets -- -D warnings

- name: Check formatting
if: matrix.os == 'ubuntu-latest'
Expand Down
4 changes: 4 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ disappears from the body and from every update popover.
why `prepare` asserts the three version fields agree.
- `src-tauri/Cargo.lock` carries the crate's own version and is part of every bump commit, but
`sync-version.mjs` does not write it.
- `package-lock.json` carries the version twice and is part of every bump commit too.
`scripts/check-lockfiles.mjs` fails, locally and in the Tests workflow, when any of these
disagree, or when an `@tauri-apps` npm package and its Rust crate are on different minors -
which `tauri build` refuses, and which only the release itself would otherwise reach.

## Verifying a run

Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"scripts": {
"sync-version": "node scripts/sync-version.mjs",
"check:changelog": "node scripts/check-changelog.mjs",
"check:lockfiles": "node scripts/check-lockfiles.mjs",
"check:temporal": "node scripts/check-temporal.mjs",
"predev": "npm run sync-version",
"dev": "tauri dev",
Expand All @@ -45,8 +46,8 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"@tailwindcss/postcss": "^4.1.17",
"@tauri-apps/api": "^2.11.1",
"@tauri-apps/cli": "^2.11.5",
"@tauri-apps/api": "^2.12.4",
"@tauri-apps/cli": "^2.12.4",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.3.1",
"@testing-library/user-event": "^14.6.1",
Expand All @@ -67,12 +68,12 @@
},
"dependencies": {
"@tailwindcss/typography": "^0.5.19",
"@tauri-apps/plugin-autostart": "^2.5.1",
"@tauri-apps/plugin-deep-link": "^2.4.7",
"@tauri-apps/plugin-dialog": "^2.6.0",
"@tauri-apps/plugin-opener": "^2.5.3",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-updater": "^2.10.0",
"@tauri-apps/plugin-autostart": "^2.7.0",
"@tauri-apps/plugin-deep-link": "^2.6.3",
"@tauri-apps/plugin-dialog": "^2.8.4",
"@tauri-apps/plugin-opener": "^2.7.2",
"@tauri-apps/plugin-process": "^2.4.0",
"@tauri-apps/plugin-updater": "^2.14.1",
"@thisux/sveltednd": "^0.0.20",
"@types/dompurify": "^3.0.5",
"clsx": "^2.1.1",
Expand Down
131 changes: 131 additions & 0 deletions scripts/check-lockfiles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// SPDX-License-Identifier: AGPL-3.0-only

// Copyright (C) 2026 Nico Wiedemann
//
// This file is part of Stashpad.
// Stashpad is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero General Public License for more details.

// Verifies that the manifests and lockfiles agree with each other.
//
// node scripts/check-lockfiles.mjs # the working tree
// node scripts/check-lockfiles.mjs --staged # the git index, for the commit preflight
//
// The app carries two dependency trees that have to move together, and each tree has a
// manifest and a lockfile that have to move together too. Nothing else compares them:
// the tests, tsc and `cargo check` all pass on a tree where they disagree. v1.12.2's release
// failed on all six platforms because `npm update` moved five @tauri-apps plugins to new
// minors while their Rust crates stayed behind, and `tauri build` - which only the release
// runs - refuses a pair whose major.minor differs. The same release had also left
// package-lock.json on the previous version number, because the bump never wrote it.
//
// Checks:
// 1. One version everywhere: package.json, both package-lock.json entries,
// tauri.conf.json, Cargo.toml, and the stashpad entry in Cargo.lock.
// 2. package-lock.json was regenerated after the last package.json edit: its root entry
// declares exactly the ranges package.json does.
// 3. Every @tauri-apps npm package has a Rust crate on the same major.minor - the check
// `tauri build` makes, run here so it fails in seconds instead of after the matrix.
//
// Cargo.toml against Cargo.lock is Cargo's own job: CI runs cargo with --locked, which
// fails on a stale Cargo.lock instead of quietly re-resolving it on the runner.

import { readFileSync } from 'fs';
import { execFileSync } from 'child_process';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

const root = join(dirname(fileURLToPath(import.meta.url)), '..');
const staged = process.argv.includes('--staged');

const read = (path) =>
staged
? execFileSync('git', ['show', `:${path}`], { cwd: root, encoding: 'utf8', maxBuffer: 64 << 20 })
: readFileSync(join(root, path), 'utf8');

const errors = [];
const fail = (file, message) => {
errors.push(message);
// An annotation on a runner, a plain line everywhere else.
console.error(process.env.GITHUB_ACTIONS ? `::error file=${file}::${message}` : ` ${file}: ${message}`);
};

const pkg = JSON.parse(read('package.json'));
const lock = JSON.parse(read('package-lock.json'));
const conf = JSON.parse(read('src-tauri/tauri.conf.json'));
const cargoToml = read('src-tauri/Cargo.toml');
const cargoLock = read('src-tauri/Cargo.lock');

/** name -> versions, from every [[package]] in a Cargo.lock. */
const crates = new Map();
for (const block of cargoLock.split('[[package]]').slice(1)) {
const name = block.match(/^name = "(.+)"$/m)?.[1];
const version = block.match(/^version = "(.+)"$/m)?.[1];
if (name && version) crates.set(name, [...(crates.get(name) ?? []), version]);
}

// 1. One version everywhere.
const version = pkg.version;
const cargoVersion = cargoToml.match(/^\[package\][\s\S]*?^version = "(.+)"$/m)?.[1];
const versions = [
['package-lock.json', 'version', lock.version],
['package-lock.json', 'packages[""].version', lock.packages?.['']?.version],
['src-tauri/tauri.conf.json', 'version', conf.version],
['src-tauri/Cargo.toml', '[package] version', cargoVersion],
['src-tauri/Cargo.lock', 'stashpad', crates.get('stashpad')?.[0]],
];
for (const [file, field, found] of versions) {
if (found !== version) {
fail(file, `${field} is ${found ?? 'missing'}, but package.json is ${version}. ` +
`A version bump has to write every file - see .claude/scripts/release-prepare.sh.`);
}
}

// 2. package-lock.json regenerated after package.json changed.
const declared = lock.packages?.[''] ?? {};
for (const section of ['dependencies', 'devDependencies', 'optionalDependencies']) {
const want = pkg[section] ?? {};
const have = declared[section] ?? {};
for (const name of new Set([...Object.keys(want), ...Object.keys(have)])) {
if (want[name] !== have[name]) {
fail('package-lock.json', `${section}.${name} is ${have[name] ?? 'absent'} in the lockfile but ` +
`${want[name] ?? 'absent'} in package.json. Run npm install and commit both.`);
}
}
}

// 3. @tauri-apps npm packages against their crates.
const minor = (v) => v.split('.').slice(0, 2).join('.');
const crateFor = (npmName) => {
const short = npmName.slice('@tauri-apps/'.length);
if (short === 'api') return 'tauri';
if (short.startsWith('plugin-')) return `tauri-plugin-${short.slice('plugin-'.length)}`;
return null; // the CLI and its platform binaries have no crate counterpart
};
for (const [path, entry] of Object.entries(lock.packages ?? {})) {
if (!/^node_modules\/@tauri-apps\/[^/]+$/.test(path)) continue;
const npmName = path.slice('node_modules/'.length);
const crate = crateFor(npmName);
if (!crate) continue;
const crateVersions = crates.get(crate);
if (!crateVersions) {
fail('src-tauri/Cargo.lock', `${npmName} ${entry.version} is installed, but ${crate} is not in Cargo.lock.`);
continue;
}
if (!crateVersions.some((v) => minor(v) === minor(entry.version))) {
fail('src-tauri/Cargo.lock', `${npmName} is ${entry.version} but ${crate} is ${crateVersions.join(', ')}. ` +
`tauri build refuses a pair whose major.minor differs - update both sides together.`);
}
}

if (errors.length) {
console.error(`\ncheck-lockfiles: ${errors.length} problem(s)${staged ? ' in the staged files' : ''}.`);
process.exit(1);
}
console.log(`check-lockfiles: ${version} everywhere, package-lock.json matches package.json, ` +
`every @tauri-apps package matches its crate${staged ? ' (staged files)' : ''}.`);
Loading
Loading