Skip to content
Closed
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
14 changes: 11 additions & 3 deletions publisher/publisher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const path = require('path');
const fs = require('fs');
const { spawn: spawnProcess, execFile } = require('child_process');

Check failure on line 4 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

'execFile' is assigned a value but never used
const Database = require('sqlite3').Database;
const bcrypt = require('bcrypt');
const session = require('express-session');
Expand Down Expand Up @@ -320,7 +321,7 @@

this.stats.addTask('Publisher', Utilities.formatDuration(pollInterval)); // or however you want to display the frequency

this.taskProcessor = setInterval(async () => {

Check warning on line 324 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
if (this.shutdownRequested) return;

if (this.isProcessing) {
Expand Down Expand Up @@ -668,11 +669,11 @@
let err = '';
npm.stdout.on('data', () => { /* ignore */ });
npm.stderr.on('data', (d) => { err += d.toString(); });
npm.on('error', async (e) => {

Check warning on line 672 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
await this.logTaskMessage(taskId, 'warn', 'Could not run npm to update SUSHI: ' + e.message);
resolve();
});
npm.on('close', async (code) => {

Check warning on line 676 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
if (code === 0) {
let version = '';
try {
Expand Down Expand Up @@ -712,7 +713,7 @@
stderr += data.toString();
});

git.on('close', async (code) => {

Check warning on line 716 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
if (code === 0) {
await this.logTaskMessage(task.id, 'info', 'Repository cloned successfully');
resolve();
Expand All @@ -723,7 +724,7 @@
}
});

git.on('error', async (error) => {

Check warning on line 727 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
await this.logTaskMessage(task.id, 'error', 'Git clone error: ' + error.message);
reject(error);
});
Expand Down Expand Up @@ -767,7 +768,7 @@
// Heartbeat: emit a status line every 60s regardless of stdout activity,
// so silent phases of the Publisher (e.g. "Validating Resources") still
// surface a signal-of-life in the task log.
const heartbeat = setInterval(async () => {

Check warning on line 771 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
const elapsedMs = Date.now() - buildStart;
const sinceDataMs = Date.now() - lastDataAt;
let logKb = 0;
Expand All @@ -783,7 +784,7 @@
);
}, 60 * 1000);

java.on('close', async (code) => {

Check warning on line 787 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
logStream.end();

if (code === 0) {
Expand All @@ -796,7 +797,7 @@
}
});

java.on('error', async (error) => {

Check warning on line 800 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
logStream.end();
await this.logTaskMessage(taskId, 'error', 'IG Publisher error: ' + error.message);
reject(error);
Expand All @@ -804,7 +805,7 @@

// Timeout configurable via publisher.igPublisherTimeoutMinutes (default: 60 minutes)
const timeoutMinutes = this.config.igPublisherTimeoutMinutes || 60;
const timeout = setTimeout(async () => {

Check warning on line 808 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
java.kill();
logStream.end();
await this.logTaskMessage(taskId, 'error', 'IG Publisher timed out after ' + timeoutMinutes + ' minutes');
Expand Down Expand Up @@ -1231,7 +1232,7 @@

// Heartbeat: emit a status line every 60s regardless of stdout activity,
// so silent phases of the Publisher still surface a signal-of-life.
const heartbeat = setInterval(async () => {

Check warning on line 1235 in publisher/publisher.js

View workflow job for this annotation

GitHub Actions / Code Quality

Promise returned in function argument where a void return was expected
const elapsedMs = Date.now() - buildStart;
const sinceDataMs = Date.now() - lastDataAt;
let logKb = 0;
Expand Down Expand Up @@ -2694,13 +2695,20 @@
});
}

async runCommand(command, args, options, taskId, description) {
const { spawn } = require('child_process');
async runCommand(cmdName, args, options, taskId, description) {
let safeCmd;
if (cmdName === 'git') {
safeCmd = 'git';
} else if (cmdName === 'bash') {
safeCmd = 'bash';
} else {
throw new Error('Command not allowed: ' + cmdName);
}

await this.logTaskMessage(taskId, 'info', description);

return new Promise((resolve, reject) => {
const proc = spawn(command, args, {
const proc = spawnProcess(safeCmd, args, {
stdio: ['pipe', 'pipe', 'pipe'],
...options
});
Expand Down
Loading