Fetch an explicit musrfit revision, compile and validate the scientific runtime, and upload its descriptor, archive, and diagnostics. Require a selected runtime workflow run for Linux packaging, verify restoration through the existing offline installer, and upload a complete package set without implicit release publishing. Fix clean-container ROOT discovery, allow scoped CI container cleanup, support both fpm cache layouts, and cover artifact restoration and build contracts with regression tests.
51 lines
2.3 KiB
JavaScript
51 lines
2.3 KiB
JavaScript
// Copyright (C) 2026 Zaher Salman
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { LocalRuntime } = require('../local-runtime');
|
|
|
|
async function restoreRuntime(bundleDirectory, installationDirectory) {
|
|
const source = path.resolve(bundleDirectory);
|
|
const descriptors = [];
|
|
// upload-artifact retains the content-addressed bundle directory. Accept a
|
|
// direct bundle too, but never silently choose between multiple runtimes.
|
|
for (const entry of await fs.promises.readdir(source, { withFileTypes: true })) {
|
|
const filename = path.join(source, entry.name);
|
|
if (entry.isFile() && entry.name === 'runtime-download.json') {
|
|
descriptors.push(filename);
|
|
} else if (entry.isDirectory()) {
|
|
const descriptor = path.join(filename, 'runtime-download.json');
|
|
if (fs.existsSync(descriptor)) descriptors.push(descriptor);
|
|
}
|
|
}
|
|
if (descriptors.length !== 1) {
|
|
throw new Error('Expected exactly one runtime-download.json in the selected artifact; found ' + descriptors.length);
|
|
}
|
|
// Reuse the desktop installer's checksum, safe extraction, manifest, ELF,
|
|
// executable-mode and startup checks rather than trusting an arbitrary tar.
|
|
const installer = new LocalRuntime({ directory: installationDirectory, timeout: 15000 });
|
|
const plan = await installer.inspectBundle(descriptors[0]);
|
|
const result = await installer.install(plan, new AbortController().signal);
|
|
return result.root;
|
|
}
|
|
|
|
if (require.main === module) {
|
|
const [source, destination] = process.argv.slice(2);
|
|
if (!source || !destination || !process.env.GITHUB_ENV) {
|
|
console.error('Usage: GITHUB_ENV=<env-file> node scripts/ci-restore-runtime.js <artifact-directory> <installation-directory>');
|
|
process.exitCode = 1;
|
|
} else {
|
|
restoreRuntime(source, destination).then(function(root) {
|
|
if (/[\r\n]/.test(root)) throw new Error('Invalid runtime path');
|
|
fs.appendFileSync(process.env.GITHUB_ENV, 'RUNTIME_DIR=' + root + '\n');
|
|
console.log('Verified runtime restored: ' + root);
|
|
}).catch(function(error) {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = { restoreRuntime };
|