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
7 changes: 5 additions & 2 deletions packages/utils/src/lib/create-runner-files.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,8 +14,10 @@ export async function createRunnerFiles(
pluginSlug: string,
configJSON: string,
): Promise<RunnerFilesPaths> {
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');

Expand Down