mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 06:29:57 +08:00
Revert "fix(desktop): block shared primary dev migrations (#409)"
This reverts commit a629cd90de.
恢复 #409 之前的共享 dev migration 语义;未含 #409 之后 main 上其他提交(fix cmd log 已保留)��\82
Signed-off-by: david <david@xd.com>
83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
import { spawnSync } from 'node:child_process';
|
|
|
|
const DRIZZLE_PATH = 'apps/desktop/drizzle';
|
|
|
|
function git(repoRoot, args, { allowFailure = false } = {}) {
|
|
const result = spawnSync('git', args, {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
});
|
|
if (result.status !== 0 && !allowFailure) {
|
|
const detail = `${result.stderr ?? ''}${result.stdout ?? ''}`.trim();
|
|
throw new Error(`git ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function resolveMigrationBaseRef(repoRoot) {
|
|
const baseRef = 'origin/main';
|
|
if (
|
|
git(repoRoot, ['rev-parse', '--verify', '--quiet', `${baseRef}^{commit}`], {
|
|
allowFailure: true,
|
|
}).status === 0
|
|
) {
|
|
return baseRef;
|
|
}
|
|
throw new Error(
|
|
'cannot resolve origin/main; fetch origin before starting shared desktop dev',
|
|
);
|
|
}
|
|
|
|
/** Find committed branch-only and uncommitted migration artifacts. */
|
|
export function findUnmergedMigrationArtifacts(repoRoot) {
|
|
const baseRef = resolveMigrationBaseRef(repoRoot);
|
|
const committed = git(repoRoot, [
|
|
'diff',
|
|
'--name-only',
|
|
`${baseRef}...HEAD`,
|
|
'--',
|
|
DRIZZLE_PATH,
|
|
]).stdout
|
|
.split(/\r?\n/)
|
|
.filter(Boolean);
|
|
const workingTree = git(repoRoot, [
|
|
'status',
|
|
'--porcelain=v1',
|
|
'--untracked-files=all',
|
|
'--',
|
|
DRIZZLE_PATH,
|
|
]).stdout
|
|
.split(/\r?\n/)
|
|
.filter(Boolean);
|
|
return {
|
|
baseRef,
|
|
committed: [...new Set(committed)].sort(),
|
|
workingTree: [...new Set(workingTree)].sort(),
|
|
};
|
|
}
|
|
|
|
export function usesIsolatedUserData(argv) {
|
|
return argv.some((arg) => arg === '--isolated' || arg.startsWith('--isolated='));
|
|
}
|
|
|
|
/**
|
|
* Shared userData may only execute migrations that are already canonical on origin/main.
|
|
* Run this before the restart pipeline stops any existing Cindy instance.
|
|
*/
|
|
export function assertSharedDevMigrationPolicy(repoRoot, argv) {
|
|
if (usesIsolatedUserData(argv)) return;
|
|
const artifacts = findUnmergedMigrationArtifacts(repoRoot);
|
|
if (artifacts.committed.length === 0 && artifacts.workingTree.length === 0) return;
|
|
const detail = [
|
|
...artifacts.committed.map((file) => `committed: ${file}`),
|
|
...artifacts.workingTree.map((line) => `working tree: ${line}`),
|
|
].join('\n ');
|
|
throw new Error(
|
|
`Shared Cindy userData cannot run migration artifacts that are not canonical on ${artifacts.baseRef}.\n` +
|
|
` ${detail}\n` +
|
|
'Rebase and renumber the migration before shared testing, or explicitly use a named sandbox: ' +
|
|
'pnpm restart:desktop:remote -- --isolated=<name>',
|
|
);
|
|
}
|