mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
build.sh and the releases/ scripts wrote all over the machine: temporary files to /tmp and macOS's /var/folders, downloads and release zips to ~/Downloads or ~/Lataukset, Meteor to ~/.meteor, Node.js to /usr/local (sudo n) or ~/.nvm, the npm cache to ~/.npm, Volta to ~/.volta, the Sandstorm toolchain to ~/projects, and PATH lines into ~/.zshrc and ~/.bashrc. A sandboxed editor (Flatpak on Linux, sandbox-exec on macOS) can reach only the checkout, and a container's own /tmp is a few hundred megabytes. Everything is in .tools/ now, which git and Meteor ignore: - releases/tools-env.sh, sourced by build.sh and every script that writes files, sets TMPDIR/TMP/TEMP to .tools/tmp (also downloads and release zips), NVM_DIR, npm_config_cache, VOLTA_HOME and the meteor-spk directory to .tools/, METEOR_WAREHOUSE_DIR to .tools/.meteor once Meteor is installed there, and puts those tools first on PATH, so no shell rc file is edited. HOME is not moved: git needs ~/.gitconfig and ~/.ssh. A TMPDIR already inside a .tools/ is kept, so a test's own directory there stays its own; without a writable one it stops rather than fall back to /tmp. It never fails a caller running set -euo pipefail. - macOS's mktemp ignores TMPDIR when given no template, so every mktemp names one: mktemp "$TMPDIR/name.XXXXXX". Fixed /tmp files are in $TMPDIR. - build.sh installs Node.js on Linux into .tools/n (N_PREFIX, no sudo), nvm on macOS into .tools/nvm (PROFILE=/dev/null: no rc file edited), and Meteor with HOME=.tools for the installer only, into .tools/.meteor. build.sh is replaced, not edited in place, while it may be running. - Containers get this checkout's .tools/tmp as their /tmp: every db-conformance database (MariaDB's temporary tables were verified to land there, and MongoDB's socket) and the repack container, which empty it themselves before they are removed. install-node-for-arch.sh requires the mounted TMPDIR. - tests/run-node-suites.cjs gives every suite TMPDIR in .tools/tmp, and the tests that copied a script into a fixture copy tools-env.sh too; tests that pinned ~/.meteor, the rc file edits, sudo n or /tmp/manifest.json pin the .tools/ places now and say why. tests/toolsDirOnly.test.cjs runs tools-env.sh against a TMPDIR already set elsewhere and under set -euo pipefail, and fails on any script that makes a temporary file without naming .tools/tmp, writes to the home directory, or edits a shell rc file, or on a container whose /tmp is its own. Thanks to xet7 !
74 lines
4.4 KiB
JavaScript
74 lines
4.4 KiB
JavaScript
'use strict';
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { spawnSync } = require('node:child_process');
|
|
const root = path.resolve(__dirname, '..');
|
|
const tmpRoot = path.join(root, '.tools/tmp');
|
|
fs.mkdirSync(tmpRoot, { recursive: true });
|
|
|
|
function fixture(fn) {
|
|
const dir = fs.mkdtempSync(path.join(tmpRoot, 'release-version-'));
|
|
try {
|
|
fs.mkdirSync(path.join(dir, 'releases'));
|
|
fs.mkdirSync(path.join(dir, 'bin'));
|
|
for (const name of ['latest-release-version.sh', 'check-upcoming-release.sh', 'tools-env.sh']) {
|
|
fs.copyFileSync(path.join(root, 'releases', name), path.join(dir, 'releases', name));
|
|
}
|
|
// Run the actual preflight only. Never include the publishing portion.
|
|
const source = fs.readFileSync(path.join(root, 'releases/release-all.sh'), 'utf8');
|
|
fs.writeFileSync(path.join(dir, 'releases/preflight.sh'), source.split('DATE="$(date +%F)"')[0] + '\nprintf "%s %s\\n" "$OLD" "$NEW"\n');
|
|
fs.writeFileSync(path.join(dir, 'releases/ensure-tools.sh'), 'ensure_tools() { :; }\n');
|
|
fs.writeFileSync(path.join(dir, 'releases/fix-changelog-hashes.sh'), 'exit 0\n');
|
|
// Dependency checks are covered by releaseTelemetry/remoteRelease; this fixture
|
|
// isolates version selection and refuses all other git/gh operations.
|
|
fs.writeFileSync(path.join(dir, 'releases/check-telemetry.py'), '# audited fixture\n');
|
|
fs.writeFileSync(path.join(dir, 'releases/remote-release.py'), '# audited fixture\n');
|
|
fs.writeFileSync(path.join(dir, 'bin/gh'), '#!/bin/sh\n[ \"$1 $2\" = \"auth status\" ] || exit 99\n', { mode: 0o755 });
|
|
fs.writeFileSync(path.join(dir, 'bin/git'), '#!/bin/bash\ncase "$1" in\nbranch) echo main;;\nremote) echo git@github.com:wekan/wekan.git;;\nls-remote) [ "${OFFLINE:-0}" = 0 ] || exit 1; printf "%s\\n" "$REMOTE_TAGS";;\ntag) printf "%s\\n" "$LOCAL_TAGS";;\n*) exit 99;;\nesac\n', { mode: 0o755 });
|
|
const notes = '# Upcoming WeKan ® release\n\n**In short:** Fix release builds.\n\n<details>\n<summary><a href="https://example.com">Fix</a></summary>\n</details>\n# v11.89 2026-09-20 WeKan ® release\n';
|
|
fs.writeFileSync(path.join(dir, 'CHANGELOG.md'), notes);
|
|
fs.writeFileSync(path.join(dir, 'package.json'), '{\n "version": "v11.89.0",\n "private": true\n}\n');
|
|
const run = (env = {}, args = []) => {
|
|
const result = spawnSync('bash', [path.join(dir, 'releases/preflight.sh'), ...args], {
|
|
encoding: 'utf8', env: { ...process.env, TMPDIR: tmpRoot, PATH: path.join(dir, 'bin') + path.delimiter + process.env.PATH,
|
|
REMOTE_TAGS: '', LOCAL_TAGS: '', ...env },
|
|
});
|
|
assert.equal(fs.readFileSync(path.join(dir, 'CHANGELOG.md'), 'utf8'), notes);
|
|
return result;
|
|
};
|
|
fn(run, dir);
|
|
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
}
|
|
|
|
test('stale changelog cannot reuse a local or remote release tag', () => fixture(run => {
|
|
for (const env of [{ LOCAL_TAGS: 'v11.90' }, { REMOTE_TAGS: 'abc\trefs/tags/v11.90\nabc\trefs/tags/v11.90^{}' }]) {
|
|
const result = run(env);
|
|
assert.equal(result.status, 0, result.stderr);
|
|
assert.equal(result.stdout.trim(), '11.90 11.91');
|
|
}
|
|
}));
|
|
test('package version prevents reuse even without tags; minor 99 rolls over', () => fixture((run, dir) => {
|
|
for (const [version, expected] of [['11.90', '11.90 11.91'], ['11.99', '11.99 12.00']]) {
|
|
fs.writeFileSync(path.join(dir, 'package.json'), `{\n "version": "v${version}.0",\n "private": true\n}\n`);
|
|
const result = run();
|
|
assert.equal(result.status, 0, result.stderr);
|
|
assert.equal(result.stdout.trim(), expected);
|
|
}
|
|
}));
|
|
test('explicit versions must match the next unused version', () => fixture(run => {
|
|
for (const args of [['11.89', '11.90'], ['11.90'], ['11.90', '11.92'], ['x', 'y']]) {
|
|
const result = run({ LOCAL_TAGS: 'v11.90' }, args);
|
|
assert.notEqual(result.status, 0);
|
|
assert.match(result.stderr, /refusing stale or reused versions/);
|
|
}
|
|
assert.equal(run({ LOCAL_TAGS: 'v11.90' }, ['v11.90', 'v11.91']).status, 0);
|
|
}));
|
|
test('remote failure stops before editing notes; unrelated tags are ignored', () => fixture(run => {
|
|
assert.notEqual(run({ OFFLINE: '1' }).status, 0);
|
|
const result = run({ REMOTE_TAGS: 'abc\trefs/tags/v99.99-beta\nabc\trefs/tags/other' });
|
|
assert.equal(result.status, 0, result.stderr);
|
|
assert.equal(result.stdout.trim(), '11.89 11.90');
|
|
}));
|