-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from AntelopeIO/parallel_nonparallel
[3.2] run nonparallel tests in parallel via separate docker containers
- Loading branch information
Showing
5 changed files
with
110 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Parallel ctest' | ||
description: 'Runs a set of ctests in parallel via multiple docker containers' | ||
inputs: | ||
container: | ||
required: true | ||
error-log-paths: | ||
required: true | ||
log-tarball-prefix: | ||
required: true | ||
tests: | ||
required: true | ||
runs: | ||
using: 'node16' | ||
main: 'dist/index.mjs' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import child_process from 'node:child_process'; | ||
import process from 'node:process'; | ||
import stream from 'node:stream'; | ||
import fs from 'node:fs'; | ||
import zlib from 'node:zlib'; | ||
import tar from 'tar-stream'; | ||
import core from '@actions/core' | ||
|
||
const container = core.getInput('container', {required: true}); | ||
const error_log_paths = JSON.parse(core.getInput('error-log-paths', {required: true})); | ||
const log_tarball_prefix = core.getInput('log-tarball-prefix', {required: true}); | ||
const tests = JSON.parse(core.getInput('tests', {required: true})); | ||
|
||
try { | ||
if(child_process.spawnSync("docker", ["run", "--name", "base", "-v", `${process.cwd()}/build.tar.zst:/build.tar.zst`, "--workdir", "/__w/leap/leap", container, "tar", "--zstd", "-xf", "/build.tar.zst"], {stdio:"inherit"}).status) | ||
throw new Error("Failed to create base container"); | ||
if(child_process.spawnSync("docker", ["commit", "base", "baseimage"], {stdio:"inherit"}).status) | ||
throw new Error("Failed to create base image"); | ||
if(child_process.spawnSync("docker", ["rm", "base"], {stdio:"inherit"}).status) | ||
throw new Error("Failed to remove base container"); | ||
|
||
let subprocesses = []; | ||
tests.forEach(t => { | ||
subprocesses.push(new Promise(resolve => { | ||
child_process.spawn("docker", ["run", "--name", t, "--init", "baseimage", "bash", "-c", `cd build; ctest --output-on-failure -R '^${t}$'`], {stdio:"inherit"}).on('close', code => resolve(code)); | ||
})); | ||
}); | ||
|
||
const results = await Promise.all(subprocesses); | ||
|
||
for(let i = 0; i < results.length; ++i) { | ||
if(results[i] === 0) | ||
continue; | ||
|
||
//failing test | ||
core.setFailed("Some tests failed"); | ||
|
||
let extractor = tar.extract(); | ||
let packer = tar.pack(); | ||
|
||
extractor.on('entry', (header, stream, next) => { | ||
if(!header.name.startsWith(`__w/leap/leap/build`)) { | ||
stream.on('end', () => next()); | ||
stream.resume(); | ||
return; | ||
} | ||
|
||
header.name = header.name.substring(`__w/leap/leap/`.length); | ||
if(header.name !== "build/" && error_log_paths.filter(p => header.name.startsWith(p)).length === 0) { | ||
stream.on('end', () => next()); | ||
stream.resume(); | ||
return; | ||
} | ||
|
||
stream.pipe(packer.entry(header, next)); | ||
}).on('finish', () => {packer.finalize()}); | ||
|
||
child_process.spawn("docker", ["export", tests[i]]).stdout.pipe(extractor); | ||
stream.promises.pipeline(packer, zlib.createGzip(), fs.createWriteStream(`${log_tarball_prefix}-${tests[i]}-logs.tar.gz`)); | ||
} | ||
} catch(e) { | ||
core.setFailed(`Uncaught exception ${e.message}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"@actions/core": "^1.9.1", | ||
"tar-stream": "^2.2.0" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters