diff --git a/packages/utils/src/lib/create-runner-files.ts b/packages/utils/src/lib/create-runner-files.ts index db0085a5c..5cb402580 100644 --- a/packages/utils/src/lib/create-runner-files.ts +++ b/packages/utils/src/lib/create-runner-files.ts @@ -1,5 +1,6 @@ import { writeFile } from 'node:fs/promises'; import path from 'node:path'; +import { threadId } from 'node:worker_threads'; import type { RunnerFilesPaths } from '@code-pushup/models'; import { ensureDirectoryExists, pluginWorkDir } from './file-system.js'; @@ -13,8 +14,10 @@ export async function createRunnerFiles( pluginSlug: string, configJSON: string, ): Promise { - const timestamp = Date.now().toString(); - const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), timestamp); + // Use timestamp + process ID + threadId + // This prevents race conditions when running the same plugin for multiple projects in parallel + const uniqueId = `${(performance.timeOrigin + performance.now()) * 10}-${process.pid}-${threadId}`; + const runnerWorkDir = path.join(pluginWorkDir(pluginSlug), uniqueId); const runnerConfigPath = path.join(runnerWorkDir, 'plugin-config.json'); const runnerOutputPath = path.join(runnerWorkDir, 'runner-output.json');