This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import { exec } from 'child_process';
|
import { exec, spawn } from 'child_process';
|
||||||
import { promisify } from 'util';
|
|
||||||
import { existsSync, mkdirSync, cpSync, rmSync, readdirSync, readFileSync } from 'fs';
|
import { existsSync, mkdirSync, cpSync, rmSync, readdirSync, readFileSync } from 'fs';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
@@ -40,9 +37,18 @@ function findLatestRelease() {
|
|||||||
|
|
||||||
async function run(cmd, opts = {}) {
|
async function run(cmd, opts = {}) {
|
||||||
log(`> ${cmd}`);
|
log(`> ${cmd}`);
|
||||||
const { stdout, stderr } = await execAsync(cmd, { timeout: 600_000, maxBuffer: 50 * 1024 * 1024, ...opts });
|
return new Promise((resolve, reject) => {
|
||||||
if (stdout) process.stdout.write(stdout);
|
const child = spawn('sh', ['-c', cmd], {
|
||||||
if (stderr) process.stderr.write(stderr);
|
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) {
|
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}`);
|
await run(`git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO_URL} ${buildDir}`);
|
||||||
|
|
||||||
// Read the cloned commit hash
|
// 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();
|
const clonedHash = hashOut.trim();
|
||||||
log(`Cloned commit: ${clonedHash}`);
|
log(`Cloned commit: ${clonedHash}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user