-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathclearBareClone.ts
More file actions
46 lines (38 loc) · 1.4 KB
/
clearBareClone.ts
File metadata and controls
46 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Action, Step } from '../../actions';
import fs from 'node:fs';
const WORK_DIR = './.remote/work';
const exec = async (req: any, action: Action): Promise<Action> => {
const step = new Step('clearBareClone');
// In test environment, clean up EVERYTHING to prevent memory leaks
if (process.env.NODE_ENV === 'test') {
// TEST: Full cleanup (bare cache + all working copies)
try {
if (fs.existsSync('./.remote')) {
fs.rmSync('./.remote', { recursive: true, force: true });
step.log('Test environment: Full .remote directory cleaned');
} else {
step.log('Test environment: .remote directory already clean');
}
} catch (err) {
step.log(`Warning: Could not clean .remote directory: ${err}`);
}
} else {
// PRODUCTION: Delete ONLY this push's working copy
const workCopy = `${WORK_DIR}/${action.id}`;
if (fs.existsSync(workCopy)) {
try {
fs.rmSync(workCopy, { recursive: true, force: true });
step.log(`Cleaned working copy for push ${action.id}`);
} catch (err) {
step.log(`Warning: Could not clean working copy ${workCopy}: ${err}`);
}
} else {
step.log(`Working copy ${workCopy} not found (may have been already cleaned)`);
}
step.log('Bare cache preserved for reuse');
}
action.addStep(step);
return action;
};
exec.displayName = 'clearBareClone.exec';
export { exec };