Skip to content
Merged
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
26 changes: 18 additions & 8 deletions packages/kbn-ts-type-check-cli/run_type_check_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,20 @@ async function createTypeCheckConfigs(
);
}

async function detectLocalChanges(): Promise<boolean> {
const { stdout } = await execa('git', ['status', '--porcelain'], {
cwd: REPO_ROOT,
});
async function detectLocalChanges(): Promise<string[]> {
const { stdout } = await execa(
'git',
// Some CI environments change these files dynamically, like FIPS but it shouldn't invalidate the cache
['status', '--porcelain', '--', '.', ':!:config/node.options', ':!config/kibana.yml'],
{
cwd: REPO_ROOT,
}
);

return stdout.trim().length > 0;
return stdout
.split('\n')
.map((line) => line.trimEnd())
.filter((line) => line.length > 0);
}

run(
Expand Down Expand Up @@ -172,14 +180,16 @@ run(
didTypeCheckFail = true;
}

const hasLocalChanges = shouldUseArchive ? await detectLocalChanges() : false;
const localChanges = shouldUseArchive ? await detectLocalChanges() : [];
const hasLocalChanges = localChanges.length > 0;

if (shouldUseArchive) {
if (hasLocalChanges) {
const message = `uncommitted changes were detected after the TypeScript build. TypeScript cache artifacts must be generated from a clean working tree.`;
const changedFiles = localChanges.join('\n');
const message = `uncommitted changes were detected after the TypeScript build. TypeScript cache artifacts must be generated from a clean working tree.\nChanged files:\n${changedFiles}`;

if (isCiEnvironment()) {
throw new Error(`Canceling TypeScript cache archive because ${message}`);
throw new Error(`Cancelling TypeScript cache archive because ${message}`);
}

log.info(`Skipping TypeScript cache archive because ${message}`);
Expand Down
Loading