This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import express from 'express';
|
||||
import compression from 'compression';
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import { exec, spawn } from 'child_process';
|
||||
import { existsSync, mkdirSync, cpSync, rmSync, readdirSync, readFileSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
@@ -40,9 +37,18 @@ function findLatestRelease() {
|
||||
|
||||
async function run(cmd, opts = {}) {
|
||||
log(`> ${cmd}`);
|
||||
const { stdout, stderr } = await execAsync(cmd, { timeout: 600_000, maxBuffer: 50 * 1024 * 1024, ...opts });
|
||||
if (stdout) process.stdout.write(stdout);
|
||||
if (stderr) process.stderr.write(stderr);
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn('sh', ['-c', cmd], {
|
||||
stdio: 'inherit',
|
||||
timeout: 600_000,
|
||||
...opts,
|
||||
});
|
||||
child.on('close', (code) => {
|
||||
if (code !== 0) reject(new Error(`Command failed with exit code ${code}: ${cmd}`));
|
||||
else resolve();
|
||||
});
|
||||
child.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
async function triggerBuild(webhookCommit) {
|
||||
@@ -68,7 +74,12 @@ async function triggerBuild(webhookCommit) {
|
||||
await run(`git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO_URL} ${buildDir}`);
|
||||
|
||||
// Read the cloned commit hash
|
||||
const { stdout: hashOut } = await execAsync('git rev-parse HEAD', { cwd: buildDir });
|
||||
const { stdout: hashOut } = await new Promise((resolve, reject) => {
|
||||
exec('git rev-parse HEAD', { cwd: buildDir }, (err, stdout, stderr) => {
|
||||
if (err) reject(err);
|
||||
else resolve({ stdout, stderr });
|
||||
});
|
||||
});
|
||||
const clonedHash = hashOut.trim();
|
||||
log(`Cloned commit: ${clonedHash}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user