Skip to content

Commit

Permalink
Merge remote-tracking branch 'ArkEcosystem/core/develop' into blockid
Browse files Browse the repository at this point in the history
* ArkEcosystem/core/develop:
  chore: circleci restore caching + re-organize jobs for unit / integration tests (#2222)
  feat(core): add restart flags to update command (#2218)
  • Loading branch information
vasild committed Mar 11, 2019
2 parents fee99c3 + e731c8f commit db19ae1
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 291 deletions.
268 changes: 31 additions & 237 deletions .circleci/config.yml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions .circleci/configTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
"run": {
"name": "Install and build packages",
"command": "yarn setup"
"command": "yarn bootstrap && yarn build"
}
},
{
Expand All @@ -65,8 +65,8 @@
},
{
"run": {
"name": "Test",
"command": ""
"name": "Unit tests",
"command": "cd ~/core && yarn test:unit:coverage --coverageDirectory .coverage/unit/ --maxWorkers=2"
}
},
{
Expand Down Expand Up @@ -137,7 +137,7 @@
{
"run": {
"name": "Install and build packages",
"command": "yarn setup"
"command": "yarn bootstrap && yarn build"
}
},
{
Expand All @@ -154,8 +154,8 @@
},
{
"run": {
"name": "Test",
"command": ""
"name": "Unit tests",
"command": "cd ~/core && yarn test:unit:coverage --coverageDirectory .coverage/unit/ --maxWorkers=2"
}
},
{
Expand Down Expand Up @@ -183,7 +183,7 @@
"workflows": {
"version": 2,
"build_and_test": {
"jobs": []
"jobs": ["test-node10-0", "test-node11-0"]
}
}
}
68 changes: 42 additions & 26 deletions .circleci/generateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,28 @@ function jason(value) {

fs.readdir("./packages", (_, packages) => {
// test split
const packagesSplit = chunk(packages.sort(), 10);
const packagesChunks = splitPackages(packages);

const resetSqlCommand = "cd ~/core/.circleci && ./rebuild-db.sh"

for (const [name, job] of Object.entries(config.jobs)) {
for (const [name, unitJob] of Object.entries(config.jobs)) {
// save cache
const saveCacheStep = config.jobs[name].steps.find(step => typeof step === "object" && step.save_cache);
const saveCacheStep = unitJob.steps.find(step => typeof step === "object" && step.save_cache);
saveCacheStep.save_cache.paths = packages
.map(package => `./packages/${package}/node_modules`)
.concat("./node_modules");


// copy base unit jobs (unit tests) to adapt for integration tests
const jobs = [
config.jobs[name],
jason(config.jobs[name]),
jason(config.jobs[name]),
jason(unitJob),
jason(unitJob),
];

jobs.forEach((job, index) => {
const testStepIndex = job.steps.findIndex(
step => typeof step === "object" && step.run && step.run.name === "Test",
step => typeof step === "object" && step.run && step.run.name === "Unit tests",
);

const pkgs = packagesSplit[index].map(pkg => path.basename(pkg));

const steps = []
for (const testType of ["unit", "integration"]) {
steps.push(...pkgs
.filter(pkg => fs.existsSync(path.resolve(__dirname, `../__tests__/${testType}/${pkg}`)))
.map(pkg => ({
run: {
name: `${pkg} - ${testType}`,
command: `${resetSqlCommand} && cd ~/core && yarn test:coverage /${testType}/${pkg}/ --coverageDirectory .coverage/${testType}/${pkg}`,
},
})
)
);
}
const steps = getIntegrationSteps(packagesChunks[index]);

const stepLog = job.steps[9];
const stepLint = job.steps[10];
Expand All @@ -61,10 +46,41 @@ fs.readdir("./packages", (_, packages) => {
job.steps.push(stepLint);
job.steps.push(stepCoverage);

config.jobs[name.slice(0, -1) + index] = job;
config.workflows.build_and_test.jobs.push(name.slice(0, -1) + index);
config.jobs[name.slice(0, -1) + (index + 1)] = job;
config.workflows.build_and_test.jobs.push(name.slice(0, -1) + (index + 1));
});
}

fs.writeFileSync(".circleci/config.yml", yaml.safeDump(config));
});

function splitPackages(packageNames) {
// split packages in two for integration tests
const integrationPackages = packageNames.sort()
.map(pkg => path.basename(pkg))
.filter(pkg => fs.existsSync(path.resolve(__dirname, `../__tests__/integration/${pkg}`)))

var indexToSplit = Math.floor(integrationPackages.length / 2);
return [
integrationPackages.slice(0, indexToSplit),
integrationPackages.slice(indexToSplit + 1)
]
}

function getIntegrationSteps(packages) {
const resetSqlCommand = "cd ~/core/.circleci && ./rebuild-db.sh"

const steps = []
steps.push(...packages
.filter(pkg => fs.existsSync(path.resolve(__dirname, `../__tests__/integration/${pkg}`)))
.map(pkg => ({
run: {
name: `${pkg} - integration`,
command: `${resetSqlCommand} && cd ~/core && yarn test:coverage /integration/${pkg}/ --coverageDirectory .coverage/integration/${pkg}`,
},
})
)
);

return steps;
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@arkecosystem/core-p2p": "^2.2.0-rc.0",
"@arkecosystem/core-snapshots": "^2.2.0-rc.0",
"@arkecosystem/core-transaction-pool": "^2.2.0-rc.0",
"@arkecosystem/core-utils": "^2.2.0-rc.0",
"@arkecosystem/core-webhooks": "^2.2.0-rc.0",
"@arkecosystem/crypto": "^2.2.0-rc.0",
"@faustbrian/dato": "^0.1.0",
Expand Down
31 changes: 19 additions & 12 deletions packages/core/src/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,26 @@ export abstract class BaseCommand extends Command {
return this.getNetworks().map(network => ({ title: network, value: network }));
}

protected async restartProcess(processName: string) {
protected async restartRunningProcessPrompt(processName: string, showPrompt: boolean = true) {
if (processManager.isRunning(processName)) {
await confirm(`Would you like to restart the ${processName} process?`, () => {
try {
cli.action.start(`Restarting ${processName}`);

processManager.restart(processName);
} catch (error) {
this.error(error.message);
} finally {
cli.action.stop();
}
});
if (showPrompt) {
await confirm(`Would you like to restart the ${processName} process?`, () => {
this.restartProcess(processName);
});
} else {
this.restartProcess(processName);
}
}
}

protected restartProcess(processName: string): void {
try {
cli.action.start(`Restarting ${processName}`);
processManager.restart(processName);
} catch (error) {
this.error(error.message);
} finally {
cli.action.stop();
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/commands/config/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ $ ark config:cli --channel=mine

const { flags } = await this.parseWithNetwork(CommandLineInterfaceCommand);

await this.restartProcess(`${flags.token}-core`);
await this.restartProcess(`${flags.token}-relay`);
await this.restartProcess(`${flags.token}-forger`);
await this.restartRunningProcessPrompt(`${flags.token}-core`);
await this.restartRunningProcessPrompt(`${flags.token}-relay`);
await this.restartRunningProcessPrompt(`${flags.token}-forger`);
} catch (err) {
this.error(err.message);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/commands/reinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class ReinstallCommand extends BaseCommand {

this.warn(`Version ${this.config.version} has been installed.`);

await this.restartProcess(`${flags.token}-core`);
await this.restartProcess(`${flags.token}-relay`);
await this.restartProcess(`${flags.token}-forger`);
await this.restartRunningProcessPrompt(`${flags.token}-core`);
await this.restartRunningProcessPrompt(`${flags.token}-relay`);
await this.restartRunningProcessPrompt(`${flags.token}-forger`);
}
}
45 changes: 42 additions & 3 deletions packages/core/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { confirm } from "../helpers/prompts";
import { checkForUpdates, installFromChannel } from "../helpers/update";
import { CommandFlags } from "../types";
import { BaseCommand } from "./command";
import { hasSomeProperty } from "@arkecosystem/core-utils";

export class UpdateCommand extends BaseCommand {
public static description: string = "Update the core installation";
Expand All @@ -14,6 +15,20 @@ export class UpdateCommand extends BaseCommand {
force: flags.boolean({
description: "force an update",
}),
restart: flags.boolean({
description: "restart all running processes",
exclusive: ["restartCore", "restartRelay", "restartForger"],
allowNo: true,
}),
restartCore: flags.boolean({
description: "restart the core process",
}),
restartRelay: flags.boolean({
description: "restart the relay process",
}),
restartForger: flags.boolean({
description: "restart the forger process",
}),
};

public async run(): Promise<void> {
Expand Down Expand Up @@ -66,8 +81,32 @@ export class UpdateCommand extends BaseCommand {

this.warn(`Version ${state.newVersion} has been installed.`);

await this.restartProcess(`${flags.token}-core`);
await this.restartProcess(`${flags.token}-relay`);
await this.restartProcess(`${flags.token}-forger`);
if (this.hasRestartFlag(flags)) {
if (flags.restart) {
this.restartRunningProcessPrompt(`${flags.token}-core`, false);
this.restartRunningProcessPrompt(`${flags.token}-relay`, false);
this.restartRunningProcessPrompt(`${flags.token}-forger`, false);
} else {
if (flags.restartCore) {
this.restartRunningProcessPrompt(`${flags.token}-core`, false);
}

if (flags.restartRelay) {
this.restartRunningProcessPrompt(`${flags.token}-relay`, false);
}

if (flags.restartForger) {
this.restartRunningProcessPrompt(`${flags.token}-forger`, false);
}
}
} else {
await this.restartRunningProcessPrompt(`${flags.token}-core`);
await this.restartRunningProcessPrompt(`${flags.token}-relay`);
await this.restartRunningProcessPrompt(`${flags.token}-forger`);
}
}

private hasRestartFlag(flags: CommandFlags): boolean {
return hasSomeProperty(flags, ["restart", "restartCore", "restartRelay", "restartForger"]);
}
}

0 comments on commit db19ae1

Please sign in to comment.