Skip to content

Feature/validate #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run setup commands
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 13, 2020
commit b7acb6702c461589a9486d079ae6969581309544
29 changes: 0 additions & 29 deletions src/utils/cherryPick.ts

This file was deleted.

43 changes: 43 additions & 0 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { exec as cpExec } from "child_process";
import { promisify } from "util";

const asyncExec = promisify(cpExec);

export function createExec(cwd: string) {
return function exec(
command: string
): Promise<{ stdout: string; stderr: string }> | never {
return asyncExec(command, { cwd });
};
}

export function createCherryPick(cwd: string) {
return async function cherryPick(commits: string[]): Promise<void> {
for (const commit of commits) {
try {
const { stdout } = await createExec(cwd)(
`git cherry-pick -X theirs ${commit}`
);
if (!stdout) {
console.warn(`No cherry-pick output for ${commit}`);
}
} catch (e) {
console.warn(`Cherry-pick failed for ${commit}`);
}
}
};
}

export function createCommandRunner(cwd: string) {
return async function runCommands(commands: string[]) {
for (const command of commands) {
try {
console.log(`> ${command}`);
await createExec(cwd)(command);
} catch (e) {
console.log(`Setup command failed: "${command}"`);
console.log(e.message);
}
}
};
}
17 changes: 10 additions & 7 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs-extra";
import * as yamlParser from "js-yaml";
import { getArg } from "./utils/args";
import gitP, { SimpleGit } from "simple-git/promise";
import { gitPCherryPick } from "./utils/cherryPick";
import { createCommandRunner, createCherryPick } from "./utils/exec";
import { getCommits, CommitLogObject } from "./utils/commits";

async function validate(args: string[]) {
Expand All @@ -23,8 +23,6 @@ async function validate(args: string[]) {
try {
skeleton = yamlParser.load(_yaml);

console.log("config", skeleton);
// TODO: validate yaml
if (!skeleton) {
throw new Error("Invalid yaml file contents");
}
Expand All @@ -37,7 +35,6 @@ async function validate(args: string[]) {

// validate commits
const commits: CommitLogObject = await getCommits({ localDir, codeBranch });
console.log("commits", commits);

// setup tmp dir
const tmpDir = path.join(localDir, ".tmp");
Expand All @@ -48,17 +45,23 @@ async function validate(args: string[]) {
}
const tempGit: SimpleGit = gitP(tmpDir);

console.log(Object.keys(gitP));

await tempGit.init();
await tempGit.addRemote("origin", skeleton.config.repo.uri);
await tempGit.fetch("origin", skeleton.config.repo.branch);
// no js cherry pick implementation
const cherryPick = gitPCherryPick(tmpDir);
const cherryPick = createCherryPick(tmpDir);
const runCommands = createCommandRunner(tmpDir);

// VALIDATE TUTORIAL TESTS
if (commits.INIT) {
// load commits
console.info("Loading setup commits...");
cherryPick(commits.INIT);

// run commands
if (skeleton.config?.testRunner?.setup?.commands) {
runCommands(skeleton.config?.testRunner?.setup?.commands);
}
}

// run test runner setup command(s)
Expand Down