chore: use execFile for git commands in version check
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m11s

This commit is contained in:
nocci 2025-12-30 14:31:17 +00:00
parent f82c158a6b
commit e4b1f60a66

View file

@ -1,15 +1,15 @@
// check if running the latest version
import { log } from 'console';
import { exec } from 'child_process';
import { execFile } from 'child_process';
const execp = cmd => new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
const runGit = (...args) => new Promise((resolve, reject) => {
execFile('git', args, { cwd: process.cwd() }, (error, stdout, stderr) => {
if (stderr) console.error(`stderr: ${stderr}`);
// if (stdout) console.log(`stdout: ${stdout}`);
if (error) {
console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) {
if (error.code === 'ENOENT' || error.message.includes('command not found')) {
console.info('Install git to check for updates!');
}
return reject(error);
@ -29,8 +29,8 @@ if (process.env.NOVNC_PORT) {
date = process.env.NOW;
} else {
log('Not running inside Docker.');
sha = await execp('git rev-parse HEAD');
date = await execp('git show -s --format=%cD'); // same as format as `date -R` (RFC2822)
sha = await runGit('rev-parse', 'HEAD');
date = await runGit('show', '-s', '--format=%cD'); // same as format as `date -R` (RFC2822)
// date = await execp('git show -s --format=%ch'); // %ch is same as --date=human (short/relative)
}