'use strict';
// The website version manifest is both the Admin Panel's release source and the
// human-readable version block on /install/. This runs the real release helper
// against a temporary website without network access.
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const root = path.resolve(__dirname, '..');
const helper = path.join(root, 'releases/update-website-version-info.sh');
const dockerfile = fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8');
const pin = pattern => {
const match = dockerfile.match(pattern);
assert.ok(match, `Dockerfile is missing version pin ${pattern}`);
return match[1];
};
const wekanVersion = pin(/^ARG VERSION=([^\s]+)$/m);
const meteorVersion = fs.readFileSync(path.join(root, '.meteor/release'), 'utf8')
.trim().replace(/^METEOR@/, '');
const nodeVersion = pin(/^\s*NODE_VERSION=v([^\s\\]+).*$/m);
const npmVersion = pin(/^\s*NPM_VERSION=([^\s\\]+).*$/m);
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'wekan-version-info-'));
const fixtureRepo = path.join(temp, 'wekan');
fs.mkdirSync(path.join(temp, 'install'));
fs.mkdirSync(path.join(fixtureRepo, '.meteor'), { recursive: true });
fs.writeFileSync(path.join(fixtureRepo, 'Dockerfile'), dockerfile.replace(
/METEOR_RELEASE=METEOR@[^\s\\]+/,
'METEOR_RELEASE=METEOR@3.5.2-beta.0'));
fs.copyFileSync(path.join(root, '.meteor/release'),
path.join(fixtureRepo, '.meteor/release'));
fs.writeFileSync(path.join(temp, 'install/index.html'),
'Install v11.29
${expected}`),
'the install page contains the exact version manifest as literal text');
const before = fs.readFileSync(path.join(temp, 'version.txt'), 'utf8');
const rejected = run('');
assert.notEqual(rejected.status, 0, 'a non-version FerretDB response must fail');
assert.equal(fs.readFileSync(path.join(temp, 'version.txt'), 'utf8'), before,
'invalid input cannot overwrite the last valid manifest');
const releaseWebsite = fs.readFileSync(
path.join(root, 'releases/release-website.sh'), 'utf8');
const localRelease = fs.readFileSync(path.join(root, 'releases/version.sh'), 'utf8');
const workflow = fs.readFileSync(
path.join(root, '.github/workflows/release-all.yml'), 'utf8');
assert.match(releaseWebsite, /update-website-version-info\.sh/);
assert.match(localRelease, /update-website-version-info\.sh/);
assert.match(localRelease,
/METEOR_RELEASE=\$\(tr -d '[^']*' < \.meteor\/release \| head -1\)/,
'release bump synchronizes Docker metadata from the canonical Meteor pin');
assert.match(localRelease, /METEOR_RELEASE=\$\{METEOR_RELEASE\}/,
'the synchronized prerelease is written to Dockerfile');
assert.ok(fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8')
.includes(`METEOR_RELEASE=METEOR@${meteorVersion}`),
'Docker metadata currently matches .meteor/release');
assert.match(workflow, /INPUT_OLD_VERSION: \$\{\{ inputs\.old_version \}\}[\s\S]*?release-website\.sh "\$\{INPUT_OLD_VERSION\}" "\$\{INPUT_NEW_VERSION\}"/,
'release-all website job runs the script that generates both destinations');
fs.rmSync(temp, { recursive: true, force: true });
console.log('websiteVersionInfo: manifest, install page and release wiring passed');