web/.forgejo/tests/web-deploy.test.mjs
unimatrixgit 8cb398e06f
All checks were successful
DuneRealms Web CI / web (push) Successful in 6m58s
Point web CI deployment to the dedicated host
2026-12-03 08:38:16 +01:00

54 lines
2.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
const workflow = readFileSync(new URL('../workflows/web-deploy.yml', import.meta.url), 'utf8');
const steps = new Map(
workflow.split(/^ - name: /m).slice(1).map(chunk => {
const lineEnd = chunk.indexOf('\n');
return [chunk.slice(0, lineEnd).trim(), chunk.slice(lineEnd + 1)];
})
);
const production = "github.repository == 'unimatrix/web' && github.ref == 'refs/heads/main'";
function step(name) {
assert.ok(steps.has(name), 'Expected workflow step: ' + name);
return steps.get(name);
}
test('development can dispatch a build and production still builds on main pushes', () => {
assert.match(workflow, /^ workflow_dispatch:\s*$/m);
assert.match(workflow, /^ push:\r?\n branches:\r?\n - main\r?$/m);
assert.equal(workflow.match(/^ if: (.+)$/m)?.[1].trim(),
"github.repository == 'unimatrix/web' || (github.repository == 'dev/MC' && github.event_name == 'workflow_dispatch')");
for (const name of ['Verify deployment policy', 'Build and test website']) {
assert.doesNotMatch(step(name), /^ if:/m);
}
});
test('checkout fetches the exact event commit from the repository running the workflow', () => {
const checkout = step('Check out exact revision');
assert.match(checkout, /fetch --depth=1 "https:\/\/www\.dunerealms\.com\/git\/\$\{GITHUB_REPOSITORY\}\.git" "\$GITHUB_SHA"/);
assert.match(checkout, /git checkout --detach FETCH_HEAD\r?\n\s+test "\$\(git rev-parse HEAD\)" = "\$GITHUB_SHA"/);
assert.doesNotMatch(checkout, /unimatrix\/web/);
});
test('publication comparison, artifact upload and deployment require canonical main', () => {
for (const name of ['Prepare publication comparison', 'Upload website build', 'Trigger deployment after successful CI']) {
assert.equal(step(name).match(/^ if: (.+)$/m)?.[1].trim(), production);
}
assert.match(step('Prepare publication comparison'), /publication-changes\.mjs "\$BEFORE" "\$GITHUB_SHA"/);
assert.match(step('Upload website build'), /uses: actions\/upload-artifact@v3/);
assert.match(step('Trigger deployment after successful CI'), /StrictHostKeyChecking=yes[^\n]+"\$GITHUB_SHA"/);
for (const [name, body] of steps) {
if (name !== 'Trigger deployment after successful CI') assert.doesNotMatch(body, /DUNEREALMS_DEPLOY_KEY|ssh .*dunedeploy@/);
}
});
test('deployment uses the verified dedicated host and its pinned SSH key', () => {
const deploy = step('Trigger deployment after successful CI');
assert.ok(deploy.includes('95.216.100.187 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICdHgR/5lVFKbOpAYR2+/Bi5LSg+8nDCSm77mJOmJKRg'));
assert.ok(deploy.includes('dunedeploy@95.216.100.187'));
assert.ok(!deploy.includes('91.107.196.242'));
});