-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.js
More file actions
28 lines (24 loc) · 982 Bytes
/
worker.js
File metadata and controls
28 lines (24 loc) · 982 Bytes
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
import { workerData } from 'worker_threads';
import { cloneRepository } from './git/cloneRepository.js';
import { runScript } from './scripts/runScript.js';
import { checkForCommits } from './git/checkForNewCommits.js';
import { logInfo, logError } from './utils/logger.js';
import fs from 'fs';
async function processRepository(config) {
const { remote_url, local_path, branch } = config.repository;
try {
if (!fs.existsSync(local_path)) {
await cloneRepository(remote_url, local_path, branch);
}
const newCommits = await checkForCommits(local_path, branch);
if (newCommits) {
for (const script of config.scripts) {
await runScript(script.command, local_path, script.allowedExitCodes);
}
logInfo(`CI/CD pipeline completed for ${remote_url}!`);
}
} catch (error) {
logError(`Error processing repository: ${error}`);
}
}
processRepository(workerData);