Skip to content
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

feat(core): support updates via git #2654

Merged
merged 27 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
26d0c02
feat(core): support updates via git
Jun 4, 2019
1a79468
Merge branch 'develop' into feat/git-update
faustbrian Jun 4, 2019
e453e2b
Merge branch 'develop' into feat/git-update
faustbrian Jun 4, 2019
4aae1df
refactor(core): new syntax
Jun 4, 2019
cbfbd93
refactor(core): check the stdout and stderr output
Jun 4, 2019
4147511
Merge branch 'develop' into feat/git-update
faustbrian Jun 4, 2019
7c123ef
Merge branch 'develop' into feat/git-update
spkjp Jun 4, 2019
60f2711
Merge branch 'develop' into feat/git-update
Jun 13, 2019
a09c783
Merge branch 'develop' into feat/git-update
faustbrian Jun 14, 2019
0574680
Merge branch 'develop' into feat/git-update
faustbrian Jun 15, 2019
08401a2
Update update.ts
faustbrian Jun 18, 2019
9f17952
Merge develop into feat/git-update
faustbrian Jun 18, 2019
32a4de2
Merge branch 'develop' into feat/git-update
faustbrian Jun 23, 2019
2e89d69
Merge branch 'develop' into feat/git-update
faustbrian Jul 2, 2019
9ad2331
Merge branch 'develop' into feat/git-update
faustbrian Jul 4, 2019
9f358b8
Merge branch 'develop' into feat/git-update
Jul 6, 2019
aa93371
Merge branch 'develop' into feat/git-update
faustbrian Jul 16, 2019
f1aef0b
fix(core): set update method if it isn't available
faustbrian Jul 16, 2019
bee8e20
fix(core): use new execa@2.0 functions
Jul 17, 2019
130d212
Merge branch 'develop' into feat/git-update
faustbrian Jul 17, 2019
1f15573
Merge branch 'develop' into feat/git-update
faustbrian Jul 17, 2019
71aeea9
fix(core): ensure that all configuration values are present
Jul 17, 2019
686af59
Merge branch 'develop' into feat/git-update
faustbrian Jul 24, 2019
91da5f4
Merge branch 'develop' into feat/git-update
faustbrian Jul 30, 2019
65295d7
refactor(core): check for updates via git or npm on boot
Aug 1, 2019
ec87f26
Merge branch 'develop' into feat/git-update
faustbrian Aug 6, 2019
32328ca
Merge branch 'develop' into feat/git-update
faustbrian Aug 9, 2019
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
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"@arkecosystem/core-container": "^2.4.0-next.9",
"@arkecosystem/core-database-postgres": "^2.4.0-next.9",
"@arkecosystem/core-event-emitter": "^2.4.0-next.9",
"@arkecosystem/core-forger": "^2.4.0-next.9",
"@arkecosystem/core-exchange-json-rpc": "^2.4.0-next.9",
"@arkecosystem/core-forger": "^2.4.0-next.9",
"@arkecosystem/core-logger-pino": "^2.4.0-next.9",
"@arkecosystem/core-p2p": "^2.4.0-next.9",
"@arkecosystem/core-snapshots": "^2.4.0-next.9",
Expand Down Expand Up @@ -90,6 +90,7 @@
"prompts": "^2.1.0",
"read-last-lines": "^1.7.1",
"semver": "^6.1.0",
"simple-git": "^1.113.0",
"wif": "^2.0.6"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/commands/config/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ $ ark config:cli --token=mine
`,
`Switch the npm registry channel
$ ark config:cli --channel=next
`,
`Switch the update method to git (bleeding-edge source)
$ ark config:cli --updateMethod=git
`,
];

Expand All @@ -25,6 +28,10 @@ $ ark config:cli --channel=next
description: "the name of the channel that should be used",
options: ["next", "latest"],
}),
updateMethod: flags.string({
description: "the update method that should be used",
options: ["npm", "git"],
}),
};

public async run(): Promise<void> {
Expand All @@ -34,6 +41,10 @@ $ ark config:cli --channel=next
configManager.set("token", flags.token as string);
}

if (flags.updateMethod) {
configManager.set("updateMethod", flags.updateMethod as string);
}

if (flags.channel) {
this.changeChannel(flags.channel);
}
Expand Down
45 changes: 38 additions & 7 deletions packages/core/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { hasSomeProperty } from "@arkecosystem/core-utils";
import { flags } from "@oclif/command";
import Chalk from "chalk";
import cli from "cli-ux";
import { shellSync } from "execa";
import { removeSync } from "fs-extra";
import git from "simple-git";
import { configManager } from "../helpers/config";
import { confirm } from "../helpers/prompts";
import { checkForUpdates, installFromChannel } from "../helpers/update";
import { CommandFlags } from "../types";
Expand Down Expand Up @@ -43,7 +46,9 @@ export class UpdateCommand extends BaseCommand {
const { flags } = await this.parseWithNetwork(UpdateCommand);

if (flags.force) {
return this.performUpdate(flags, state);
return configManager.get("updateMethod") === "npm"
? await this.performUpdateWithNpm(flags, state)
: await this.performUpdateWithGit(flags, state);
}

try {
Expand All @@ -55,7 +60,9 @@ export class UpdateCommand extends BaseCommand {

await confirm("Would you like to update?", async () => {
try {
await this.performUpdate(flags, state);
configManager.get("updateMethod") === "npm"
? await this.performUpdateWithNpm(flags, state)
: await this.performUpdateWithGit(flags, state);
} catch (err) {
this.error(err.message);
} finally {
Expand All @@ -67,7 +74,7 @@ export class UpdateCommand extends BaseCommand {
}
}

private async performUpdate(flags: CommandFlags, state: Record<string, any>): Promise<void> {
private async performUpdateWithNpm(flags: CommandFlags, state: Record<string, any>): Promise<void> {
cli.action.start(`Updating from ${state.currentVersion} to ${state.updateVersion}`);

await installFromChannel(state.name, state.updateVersion);
Expand All @@ -78,6 +85,34 @@ export class UpdateCommand extends BaseCommand {

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

await this.confirmRestart(flags);
}

private async performUpdateWithGit(flags: CommandFlags, state: Record<string, any>): Promise<void> {
git()
.exec(() => cli.action.start("Pulling latest changes"))
.pull((err, update) => {
if (err) {
this.error(err.message);

This comment was marked as resolved.

}

if (update && update.summary.changes) {
shellSync("cd ../../ && yarn setup");

This comment was marked as outdated.

} else {
this.warn("You already have the latest version.");
}
})
.exec(() => cli.action.stop())
.exec(() => removeSync(state.cache))
.exec(() => this.warn("The latest version has been installed."))
.exec(async () => await this.confirmRestart(flags));
vasild marked this conversation as resolved.
Show resolved Hide resolved
}

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

private async confirmRestart(flags: CommandFlags): Promise<void> {
if (this.hasRestartFlag(flags)) {
if (flags.restart) {
this.restartRunningProcessPrompt(`${flags.token}-core`, false);
Expand All @@ -102,8 +137,4 @@ export class UpdateCommand extends BaseCommand {
await this.restartRunningProcessPrompt(`${flags.token}-forger`);
}
}

private hasRestartFlag(flags: CommandFlags): boolean {
return hasSomeProperty(flags, ["restart", "restartCore", "restartRelay", "restartForger"]);
}
}
1 change: 1 addition & 0 deletions packages/core/src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ConfigManager {
this.write({
token: this.config.bin,
channel: getRegistryChannel(this.config),
updateMethod: "npm",
});
}
}
Expand Down
10 changes: 1 addition & 9 deletions packages/core/src/helpers/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IConfig } from "@oclif/config";
import cli from "cli-ux";
import { shell } from "execa";
import { closeSync, openSync, statSync } from "fs";
import { ensureDirSync, existsSync } from "fs-extra";
import { ensureDirSync } from "fs-extra";
import latestVersion from "latest-version";
import { join } from "path";
import semver from "semver";
Expand Down Expand Up @@ -73,14 +73,6 @@ export const checkForUpdates = async ({ config, error, warn }): Promise<any> =>
channel: configManager.get("channel"),
};

if (existsSync(join(__dirname, "../../../..", ".git"))) {
if (!process.env.CORE_DEVELOPER_MODE) {
warn(`You are using a git clone for developers. Please install core via yarn for auto-updates.`);
}

return state;
}

try {
const cacheFile = ensureCacheFile(config);

Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12116,6 +12116,13 @@ signale@^1.4.0:
figures "^2.0.0"
pkg-conf "^2.1.0"

simple-git@^1.113.0:
version "1.113.0"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.113.0.tgz#668989728a1e9cf4ec6c72b69ea2eecc93489bea"
integrity sha512-i9WVsrK2u0G/cASI9nh7voxOk9mhanWY9eGtWBDSYql6m49Yk5/Fan6uZsDr/xmzv8n+eQ8ahKCoEr8cvU3h+g==
dependencies:
debug "^4.0.1"

simple-git@^1.85.0:
version "1.110.0"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.110.0.tgz#54eb179089d055a7783d32399246cebc9d9933e9"
Expand Down