Run tests in CI

This commit is contained in:
Radon Rosborough 2021-01-01 11:43:10 -08:00
parent a7e94b792e
commit e0e75d7dae
3 changed files with 85 additions and 50 deletions

View File

@ -43,7 +43,7 @@ script:
.PHONY: scripts .PHONY: scripts
scripts: scripts:
node tools/make-foreach.js script node tools/make-foreach.js --pkgs script
.PHONY: pkg .PHONY: pkg
pkg: pkg:
@ -91,6 +91,11 @@ install:
if [[ -z "$$(ls -A /var/lib/apt/lists)" ]]; then sudo apt update; fi if [[ -z "$$(ls -A /var/lib/apt/lists)" ]]; then sudo apt update; fi
sudo apt reinstall -y ./$(BUILD)/$(DEB) sudo apt reinstall -y ./$(BUILD)/$(DEB)
.PHONY: installs
installs:
@: $${L}
node tools/make-foreach.js --types install L=$(L)
### Build and run application code ### Build and run application code
.PHONY: frontend .PHONY: frontend

View File

@ -6,13 +6,26 @@ import { runCommand } from "./util.js";
// Parse command-line arguments, run main functionality, and exit. // Parse command-line arguments, run main functionality, and exit.
async function main() { async function main() {
const targets = process.argv.slice(2); const args = process.argv.slice(2);
if (targets.length === 0) { if (args.length < 2) {
console.error("usage: make-foreach.js TARGET..."); console.error("usage: make-foreach.js (--pkgs | --types) TARGET...");
process.exit(1); process.exit(1);
} }
for (const { lang, type } of await getPackages()) { const [selector, ...targets] = args;
await runCommand(`make ${targets} L=${lang} T=${type}`); switch (selector) {
case "--pkgs":
for (const { lang, type } of await getPackages()) {
await runCommand(`make ${targets.join(" ")} L=${lang} T=${type}`);
}
break;
case "--types":
for (const type of ["lang", "config"]) {
await runCommand(`make ${targets.join(" ")} T=${type}`);
}
break;
default:
console.error(`make-foreach.js: unknown selector: ${selector}`);
process.exit(1);
} }
process.exit(0); process.exit(0);
} }

View File

@ -50,6 +50,9 @@ async function planDockerImage(name, dependentHashes, opts) {
await runCommand(`make image I=${name}`); await runCommand(`make image I=${name}`);
}, },
upload: async () => { upload: async () => {
if (name === "composite") {
await runCommand(`make shell I=composite CMD="make test"`);
}
await runCommand(`make push I=${name}`); await runCommand(`make push I=${name}`);
}, },
}; };
@ -70,51 +73,63 @@ async function planDebianPackages(opts) {
return [remoteName, remoteHash]; return [remoteName, remoteHash];
}) })
); );
const packages = await getPackages();
const langUUIDs = Object.fromEntries(
packages
.filter(({ type }) => type === "lang")
.map(({ lang }) => ["lang", getUUID()])
);
return await Promise.all( return await Promise.all(
(await getPackages()).map( packages.map(async ({ lang, type, name, buildScriptPath, debPath }) => {
async ({ lang, type, name, buildScriptPath, debPath }) => { const desired = crypto
const desired = crypto .createHash("sha1")
.createHash("sha1") .update(await fs.readFile(buildScriptPath, "utf-8"))
.update(await fs.readFile(buildScriptPath, "utf-8")) .digest("hex");
.digest("hex"); let debExists = true;
let debExists = true; try {
try { await fs.access(debPath);
await fs.access(debPath); } catch (err) {
} catch (err) { debExists = false;
debExists = false;
}
let local = null;
if (debExists) {
local =
(
await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, {
getStdout: true,
})
).stdout.trim() || null;
}
const remote = remoteHashes[name] || null;
return {
id: getUUID(),
deps: deps || [],
artifact: "Debian package",
name,
desired,
local,
remote,
download: async () => {
await runCommand(`make download L=${lang} T=${type}`);
},
build: async () => {
await runCommand(
`make shell I=packaging CMD="make pkg L=${lang} T=${type}"`
);
},
upload: async () => {
await runCommand(`make upload L=${lang} T=${type}`);
},
};
} }
) let local = null;
if (debExists) {
local =
(
await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, {
getStdout: true,
})
).stdout.trim() || null;
}
const remote = remoteHashes[name] || null;
return {
id: getUUID(),
deps: [
...(deps || []),
type === "config" ? langUUIDs[lang] : getUUID(),
],
artifact: "Debian package",
name,
desired,
local,
remote,
download: async () => {
await runCommand(`make download L=${lang} T=${type}`);
},
build: async () => {
await runCommand(
`make shell I=packaging CMD="make pkg L=${lang} T=${type}"`
);
},
upload: async () => {
if (type === "config") {
await runCommand(
`make shell I=runtime CMD="make installs test L=${lang}"`
);
}
await runCommand(`make upload L=${lang} T=${type}`);
},
};
})
); );
} }
@ -124,7 +139,9 @@ async function computePlan() {
}; };
const packaging = await planDockerImage("packaging", dependentHashes); const packaging = await planDockerImage("packaging", dependentHashes);
const runtime = await planDockerImage("runtime", dependentHashes); const runtime = await planDockerImage("runtime", dependentHashes);
const packages = await planDebianPackages({ deps: [packaging.id] }); const packages = await planDebianPackages({
deps: [packaging.id, runtime.id],
});
const composite = await planDockerImage("composite", dependentHashes, { const composite = await planDockerImage("composite", dependentHashes, {
deps: [runtime.id, ...packages.map(({ id }) => id)], deps: [runtime.id, ...packages.map(({ id }) => id)],
hashOpts: { hashOpts: {