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 !
84 lines
5.1 KiB
JavaScript
84 lines
5.1 KiB
JavaScript
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 scratch = path.join(root, '.tools/tmp');
|
|
fs.mkdirSync(scratch, {recursive: true});
|
|
const mongo = (version, arches = ['x86_64', 'aarch64']) => ({version, downloads: arches.map(arch => ({archive: {
|
|
url: `https://fastdl.mongodb.org/linux/mongodb-linux-${arch}-ubuntu2204-${version}.tgz`,
|
|
}}))});
|
|
function fixture() {
|
|
const dir = fs.mkdtempSync(path.join(scratch, 'dependency-versions-'));
|
|
for (const file of ['Dockerfile', 'snapcraft.yaml', 'Stackerfile.yml', 'package.json', 'package-lock.json',
|
|
'sandstorm-pkgdef.capnp', '.meteor/release', 'docs/Platforms/Propietary/OS/Windows/Offline.md',
|
|
'releases/version.sh', 'releases/dependency-versions.py', 'releases/update-website-version-info.sh',
|
|
'releases/use-release-npm.sh', 'releases/tools-env.sh']) {
|
|
fs.mkdirSync(path.dirname(path.join(dir, file)), {recursive: true});
|
|
fs.copyFileSync(path.join(root, file), path.join(dir, file));
|
|
}
|
|
fs.writeFileSync(path.join(dir,'releases/example.sh'), 'NODE_TAR="node-v26.1.0-linux-${NODE_ARCH}.tar.xz"\nhttps://fastdl.mongodb.org/linux/mongodb-linux-${MONGO_ARCH}-ubuntu2204-7.0.1.tgz\n');
|
|
const metadata = {
|
|
node: [{version: 'v26.99.0', files: ['linux-x64', 'linux-arm64']},
|
|
{version: 'v26.100.0', files: ['linux-x64']}, {version: 'v27.0.0', files: ['linux-x64','linux-arm64']}],
|
|
mongo: {versions: [mongo('7.0.99'), mongo('7.0.100', ['x86_64']), mongo('7.3.4'), mongo('8.0.1'), mongo('7.0.101-rc0')]},
|
|
npm: {version: '12.99.0'},
|
|
};
|
|
for (const [name, data] of Object.entries(metadata)) fs.writeFileSync(path.join(dir, name + '.json'), JSON.stringify(data));
|
|
fs.mkdirSync(path.join(dir, 'bin'));
|
|
fs.writeFileSync(path.join(dir, 'bin/curl'), `#!/usr/bin/env python3
|
|
import os,sys
|
|
from pathlib import Path
|
|
if '--head' in sys.argv:
|
|
print('404' if os.environ.get('FAIL_HEAD') else '200'); sys.exit(0)
|
|
u=sys.argv[-1]
|
|
name={'https://nodejs.org/dist/index.json':'node','https://downloads.mongodb.org/full.json':'mongo','https://registry.npmjs.org/npm/latest':'npm'}[u]
|
|
print(Path(name+'.json').read_text())
|
|
`, {mode: 0o755});
|
|
return dir;
|
|
}
|
|
function run(dir, extra={}) {
|
|
return spawnSync('bash', ['releases/version.sh', '11.91', '11.99'], {cwd: dir, encoding:'utf8',
|
|
env: {...process.env, TMPDIR: scratch, PATH: path.join(dir,'bin')+':'+process.env.PATH,
|
|
RELEASE_SKIP_DEP_DOWNLOAD:'1', USE_LOCAL_DEP_VERSIONS:'0', ...extra}});
|
|
}
|
|
test('real version bump selects supported pairs and updates website manifest', () => {
|
|
const dir=fixture();
|
|
try {
|
|
const result=run(dir); assert.equal(result.status,0,result.stdout+result.stderr);
|
|
const docker=fs.readFileSync(path.join(dir,'Dockerfile'),'utf8');
|
|
assert.match(docker,/NODE_VERSION=v26\.99\.0/); assert.match(docker,/NPM_VERSION=12\.99\.0/);
|
|
const snap=fs.readFileSync(path.join(dir,'snapcraft.yaml'),'utf8');
|
|
assert.match(snap,/ubuntu2204-7\.0\.99\.tgz/);
|
|
const refs=fs.readFileSync(path.join(dir,'releases/example.sh'),'utf8');
|
|
assert.ok(refs.includes('node-v26.99.0-linux-${NODE_ARCH}.tar.xz'));
|
|
assert.ok(refs.includes('mongodb-linux-${MONGO_ARCH}-ubuntu2204-7.0.99.tgz'));
|
|
const web=path.join(dir,'website'); fs.mkdirSync(path.join(web,'install'),{recursive:true});
|
|
fs.writeFileSync(path.join(web,'install/index.html'),'<h2><span class="version-number">v0.0</span></h2>');
|
|
const manifest=spawnSync('bash',['releases/update-website-version-info.sh',web,dir,'11.99'],{
|
|
cwd:dir,encoding:'utf8',env:{...process.env,FERRETDB_VERSION:'v1.83.0'}});
|
|
assert.equal(manifest.status,0,manifest.stderr);
|
|
const content=fs.readFileSync(path.join(web,'version.txt'),'utf8');
|
|
assert.match(content,/WeKan 11\.99/); assert.match(content,/Node 26\.99\.0/); assert.match(content,/NPM 12\.99\.0/);
|
|
assert.ok(fs.readFileSync(path.join(web,'install/index.html'),'utf8').includes(content.trim()));
|
|
fs.writeFileSync(path.join(dir,'releases/npm-retry.sh'),'printf "%s\\n" "$@"\n');
|
|
const npm=spawnSync('bash',['releases/use-release-npm.sh'],{cwd:dir,encoding:'utf8'});
|
|
assert.equal(npm.status,0,npm.stderr); assert.match(npm.stdout,/npm@12\.99\.0/);
|
|
fs.writeFileSync(path.join(dir,'Dockerfile'),'NPM_VERSION=broken\n');
|
|
assert.notEqual(spawnSync('bash',['releases/use-release-npm.sh'],{cwd:dir}).status,0);
|
|
} finally {fs.rmSync(dir,{recursive:true,force:true});}
|
|
});
|
|
test('invalid metadata and unavailable artifacts stop before version edits', () => {
|
|
for (const fault of ['metadata','head']) {
|
|
const dir=fixture();
|
|
try {
|
|
const before=fs.readFileSync(path.join(dir,'Dockerfile'),'utf8');
|
|
if(fault==='metadata') fs.writeFileSync(path.join(dir,'mongo.json'),'{"versions":[]}');
|
|
const result=run(dir,fault==='head'?{FAIL_HEAD:'1'}:{});
|
|
assert.notEqual(result.status,0,result.stdout+result.stderr);
|
|
assert.equal(fs.readFileSync(path.join(dir,'Dockerfile'),'utf8'),before);
|
|
} finally {fs.rmSync(dir,{recursive:true,force:true});}
|
|
}
|
|
});
|