Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Feat/version check #2859

Merged
merged 52 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7e10c4a
feat: create version-check package
davidmurdoch Apr 6, 2022
5e7574d
attempt CI fix
davidmurdoch Apr 7, 2022
2d3c88a
fix
davidmurdoch Apr 7, 2022
366b1d5
Add some missing colors
davidmurdoch Apr 8, 2022
ec42c83
small refactor
davidmurdoch Apr 8, 2022
14d1867
chore(release): publish v7.0.4
TrufBot Apr 5, 2022
7e53ed2
perf: improve performance of the persistent cache used in forking (#2…
jeffsmale90 Apr 7, 2022
47d583d
chore: remove outdated warning about EIP-1193 fork providers (#2856)
gnidan Apr 8, 2022
81219d7
ci: automated release improvements (#2892)
MicaiahReid Apr 18, 2022
0fe323d
squashme - VersionChecker class plated
tenthirtyone Apr 20, 2022
2710629
squashme stub unit tests
tenthirtyone Apr 20, 2022
082fb00
feat: create version-check package
davidmurdoch Apr 6, 2022
8ad68af
attempt CI fix
davidmurdoch Apr 7, 2022
2df3a84
fix
davidmurdoch Apr 7, 2022
9bafbb9
Add some missing colors
davidmurdoch Apr 8, 2022
ce7bab5
small refactor
davidmurdoch Apr 8, 2022
688d51f
squashme unit test start
tenthirtyone Apr 21, 2022
7254472
Merge branch 'feat/version-check' of github.com:trufflesuite/ganache …
tenthirtyone Apr 21, 2022
b075cb7
squashme semver unit tests
tenthirtyone Apr 22, 2022
8486394
squashme fetch wired up
tenthirtyone Apr 22, 2022
eda5028
squashme cleaning up a bit
tenthirtyone Apr 22, 2022
cceae3c
comment out failing semvers
tenthirtyone Apr 22, 2022
72649fb
log unit tests
tenthirtyone Apr 22, 2022
067b6ef
test e2e, add semver package
tenthirtyone Apr 26, 2022
7d2b242
snipe errant branches
tenthirtyone Apr 26, 2022
9dd9100
replace init race condition test with sinon spy
tenthirtyone Apr 26, 2022
101cba1
fail silently if server unavailable
tenthirtyone Apr 26, 2022
b31fd98
final preflight before squash and PR
tenthirtyone Apr 26, 2022
4acdceb
add constructor and config types
tenthirtyone Apr 26, 2022
4eb0838
disable if in CI
tenthirtyone Apr 26, 2022
6677957
logVersionMessage for --version
tenthirtyone Apr 26, 2022
79005d9
Merge branch 'develop' into feat/version-check
tenthirtyone Apr 26, 2022
507801c
remove the disable in CI... because it actually disables in CI... for…
tenthirtyone Apr 26, 2022
42d1a33
add to ganache, fix versionMesage string for yargs
tenthirtyone Apr 26, 2022
d00426b
add version-check back to cli
tenthirtyone Apr 27, 2022
b1dd39d
handle invalid semver
tenthirtyone Apr 27, 2022
4708e1e
only setLatestSemver if valid semver
tenthirtyone Apr 27, 2022
c42334f
clean up my testing changes that were accidentally committed
tenthirtyone Apr 27, 2022
b708e00
Merge branch 'develop' into feat/version-check
tenthirtyone Apr 28, 2022
5cf6fd3
bump @ganache/colors, shrinkwrap
tenthirtyone Apr 28, 2022
ea2016e
add clean and validate function, reduce function checks
tenthirtyone May 2, 2022
acfac1d
disable if currentVersion is not valid semver
tenthirtyone May 2, 2022
6e65b34
validate and clean semver at entry
tenthirtyone May 2, 2022
72db2d5
sparse config test
tenthirtyone May 3, 2022
30ece90
alpha and beta, v strings
tenthirtyone May 3, 2022
33a05c6
Update src/packages/version-check/index.ts
tenthirtyone May 3, 2022
3b56123
move banner to end of CLI, before starting message
tenthirtyone May 3, 2022
e362f23
fix session being held open after stopping in vs code
tenthirtyone May 3, 2022
57682ae
remove scope from package.json
tenthirtyone May 3, 2022
63438e5
fix startGanache banner log location. Add to README
tenthirtyone May 3, 2022
46189b9
fix req.end holding a connection open that prevents starting multiple…
tenthirtyone May 3, 2022
f0aef85
Merge remote-tracking branch 'origin/develop' into feat/version-check
tenthirtyone May 3, 2022
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
1 change: 1 addition & 0 deletions src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@ganache/flavors": "0.2.0",
"@ganache/options": "0.2.0",
"@ganache/utils": "0.2.0",
"@ganache/version-check": "0.1.0",
"@types/node": "17.0.0",
"chalk": "4.1.0",
"ethereumjs-util": "7.1.4",
Expand Down
11 changes: 9 additions & 2 deletions src/packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import initializeEthereum from "./initialize/ethereum";
import initializeFilecoin from "./initialize/filecoin";
import type { Provider as FilecoinProvider } from "@ganache/filecoin";
import type { Provider as EthereumProvider } from "@ganache/ethereum";
import { VersionCheck } from "@ganache/version-check";

const logAndForceExit = (messages: any[], exitCode = 0) => {
// https://nodejs.org/api/process.html#process_process_exit_code
Expand All @@ -31,13 +32,18 @@ const logAndForceExit = (messages: any[], exitCode = 0) => {
const version = process.env.VERSION || "DEV";
const cliVersion = process.env.CLI_VERSION || "DEV";
const coreVersion = process.env.CORE_VERSION || "DEV";
const versionCheck = new VersionCheck(version);
const versionMessage = versionCheck.getVersionMessage();

const detailedVersion = `ganache v${version} (@ganache/cli: ${cliVersion}, @ganache/core: ${coreVersion})`;

const isDocker =
"DOCKER" in process.env && process.env.DOCKER.toLowerCase() === "true";

const argv = args(detailedVersion, isDocker);
const argsVersion = versionMessage
? `${detailedVersion}\n${versionMessage}`
: detailedVersion;

const argv = args(argsVersion, isDocker);

const flavor = argv.flavor;

Expand Down Expand Up @@ -141,6 +147,7 @@ async function startGanache(err: Error) {
break;
}
}
versionCheck.init().log();
}
console.log("Starting RPC server");
server.listen(cliSettings.port, cliSettings.host, startGanache);
4 changes: 4 additions & 0 deletions src/packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
{
"name": "@ganache/filecoin",
"path": "../../chains/filecoin/filecoin"
},
{
"name": "@ganache/version-check",
"path": "../version-check"
}
]
}
11 changes: 10 additions & 1 deletion src/packages/colors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ export const TruffleColors = {
/**
* Infura orange
*/
infura: "#ff6b4a"
infura: "#ff6b4a",

/**
* Drizzle pink
*/
drizzle: "#e911bd",

green: "#00D717",
yellow: "#F2E941",
watermelon: "#E86591"
};
8 changes: 8 additions & 0 deletions src/packages/version-check/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/index.ts
/tests
/.nyc_output
/coverage
/scripts
/src
/tsconfig.json
/typedoc.json
22 changes: 22 additions & 0 deletions src/packages/version-check/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Iuri Matias
Copyright (c) 2022 ConsenSys Software Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
168 changes: 168 additions & 0 deletions src/packages/version-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# `@ganache/version-check`

### Description

`version-check` (VC) alerts the user when it detects a newer version is available. It does so in two ways:

1. When the user starts `ganache` from the command line through a banner message.
2. When the `ganache --version` command switch is run as a single string.

VC does two things.

1. On startup, VC will report based on an existing `latestVersion` stored on disk, comparing it to the currently running software version (`currentVersion`).
2. It makes a request to a configured url and expects back a semver response representing the `latestVersion` that is then persisted to disk.

#### Requirements

VC does not block the currently running application when it makes a request to check on the `latestVersion`. It is specced to be eventually consistent, assuming users will start/stop the tool implementing VC frequently. At each startup, VC checks against the value of the previously fetched `latestVersion`.

VC tracks the version that has been reported to the user to reduce its chattiness to the user. Upon start, VC will persist a `latestVersionLogged` representing the semver of the last version it displayed to the user upon starting ganache. VC will not display the banner message more than once for a given version. When the `ganache --version` command is run, VC will always display the single string message (if a newer version is known).

On install, VC defaults the `latestVersion` and `latestVersionLogged` to `0.0.0`. This will always be below the first-run of the latest install.

VC is specced to fail silently. If a request fails, returns invalid semver or any combination of current/latest version is not valid semver it will quit without informing the user. It is self-healing if the API incorrectly reports a version and is later corrected it will inform the user of the latest, correct, version.

VC's relies on the same `conf` package as truffle to manage the data persistence across environments (Linux, Mac, Windows).

VC relies on the `semver` package to perform `diff` and validation of semver.

#### Usage

VC is flexible in how it may be implemented

```javascript
const vc = new VersionCheck(currentVersionSemVer, [config], [logger]);
```

The constructor requires a `currentVersionSemVer` and accepts an optional config and logger function.

```javascript
vc
.init();
.log();
```

`init` will send the request to fetch and set the `latestVersion` on disk.
`log` will perform the required notification checks and, if they pass, log the banner message to the user based on the current `latestVersion` on disk.

`init` will not await the fetch, it fires the request and does not concern itself with the outcome or results. If the desired behavior is to wait for a response before logging to the user (forgoing the eventual consistency spec), VC can be used as such:

```javascript
await vc.getLatestVersion();
vc.log();
```

This usage will perform the the same steps as using `init`, however the `latestVersion` stored on disk will be the version returned from the fetch. This could be desirable by applications that are not concerned with latency/server timeout/ or that have configured a low `ttl` value in the VC config.

```javascript
vc.getVersionMessage();
```

`getVersionMessage` returns a single string noting the `currentVersion` and `latestVersion` if a semver change is detected. This string is appended to the `detailedVersion` string in `@ganache/cli` for to support the `ganache --version` command switch.

#### Test

From a develop environment, start ganache using:

```bash
$ export VERSION="1.2.3"; npm run start
```

##### Expected Output

1.) No banner message is displayed (first run, assumes latest was installed)

```bash
~/proj/ganache (feat/version-check) » export VERSION="1.2.3"; npm run start hayek@rothbard

> root@ start /home/hayek/proj/ganache
> lerna exec --loglevel=silent --scope ganache -- npm run start --silent --

Debugger listening on ws://127.0.0.1:9229/b4dc2d61-8f90-4a2c-80ff-14db24160453
For help, see: https://nodejs.org/en/docs/inspector
ganache v1.2.3 (@ganache/cli: DEV, @ganache/core: DEV)
Starting RPC server
```

2.) A config file now exists for the user `less ~/.config/@ganache/version-check-nodejs/config.json` (on linux)

```
{
"config": {
"packageName": "ganache",
"enabled": true,
"url": "https://version.trufflesuite.com/",
"ttl": 300,
"latestVersion": "7.0.5",
"latestVersionLogged": "0.0.0"
}
}
```

Restart `ganache` (`export VERSION="1.2.3"; npm run start`)

##### Expected Output

1. Banner message displays, `latestVersion` > `latestVersionLogged`

```bash
export VERSION="1.2.3"; npm run start hayek@rothbard

> root@ start /home/hayek/proj/ganache
> lerna exec --loglevel=silent --scope ganache -- npm run start --silent --

Debugger listening on ws://127.0.0.1:9229/911542db-3daa-433c-a31f-2aa662a084e2
For help, see: https://nodejs.org/en/docs/inspector
ganache v1.2.3 (@ganache/cli: DEV, @ganache/core: DEV)
Starting RPC server

╔══════════════════════════════════════════════════════════════════════╗
║ ║
║ New major version of ganache available! 1.2.3 ⇢ 7.0.5 ║
║ Changelog: https://github.com/trufflesuite/ganache/releases/v7.0.5 ║
║ Run npm install -g [email protected] to update! ║
║ ║
╚══════════════════════════════════════════════════════════════════════╝
```

2. Config updates `latestVersionLogged`

```bash
{
"config": {
"packageName": "ganache",
"enabled": true,
"url": "https://version.trufflesuite.com/",
"ttl": 300,
"latestVersion": "7.0.5",
"latestVersionLogged": "7.0.5"
}
}
```

Restart `ganache` (`export VERSION="1.2.3"; npm run start`)

##### Expected Results

1.) Banner message does not display, user has already seen this version.

```bash
export VERSION="1.2.3"; npm run start 130 ↵ hayek@rothbard

> root@ start /home/hayek/proj/ganache
> lerna exec --loglevel=silent --scope ganache -- npm run start --silent --

Debugger listening on ws://127.0.0.1:9229/27f051e4-1c84-4bdf-a41d-95601466ba2b
For help, see: https://nodejs.org/en/docs/inspector
ganache v1.2.3 (@ganache/cli: DEV, @ganache/core: DEV)
Starting RPC server
```

Run `npm start -- --version`

##### Expected Result

```bash
ganache v1.2.3 (@ganache/cli: DEV, @ganache/core: DEV)
note: there is a new version available! 1.2.3 -> 7.0.5
```
8 changes: 8 additions & 0 deletions src/packages/version-check/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* @ganache/version-check
*
* @author David Murdoch
* @license MIT
*/

export * from "./src/";
Loading