free-games-claimer/src/version.js
nocci 397871b012
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m13s
Further clean Sonar: merge base RUN, strip comments, node imports
2025-12-30 15:47:28 +00:00

41 lines
1.3 KiB
JavaScript

import { log } from 'node:console';
import { execFile } from 'node:child_process';
const gitBin = process.env.GIT_BIN || '/usr/bin/git';
const runGit = (...args) => new Promise((resolve, reject) => {
execFile(gitBin, args, { cwd: process.cwd() }, (error, stdout, stderr) => {
if (stderr) console.error(`stderr: ${stderr}`);
if (error) {
console.log(`error: ${error.message}`);
if (error.code === 'ENOENT' || error.message.includes('command not found')) {
console.info('Install git to check for updates!');
}
return reject(error);
}
resolve(stdout.trim());
});
});
let sha, date;
if (process.env.NOVNC_PORT) {
log('Running inside Docker.');
['COMMIT', 'BRANCH', 'NOW'].forEach(v => log(` ${v}:`, process.env[v]));
sha = process.env.COMMIT;
date = process.env.NOW;
} else {
log('Not running inside Docker.');
sha = await runGit('rev-parse', 'HEAD');
date = await runGit('show', '-s', '--format=%cD'); // same as format as `date -R` (RFC2822)
}
const gh = await (await fetch('https://api.github.com/repos/vogler/free-games-claimer/commits/main')).json();
log('Local commit:', sha, new Date(date));
log('Online commit:', gh.sha, new Date(gh.commit.committer.date));
if (sha == gh.sha) {
log('Running the latest version!');
} else {
log('Not running the latest version!');
}