Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/on_chain_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoreira-valory committed Jun 14, 2024
2 parents 925aa30 + f9332cd commit d3f0f01
Show file tree
Hide file tree
Showing 16 changed files with 2,499 additions and 207 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FORK_URL=
NODE_ENV=
DEV_RPC=
STAKING_TEST_KEYS_PATH=
DEV_RPC=
IS_STAGING=
29 changes: 29 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Test Operate Installation E2E"
on:
push:
branches:
- develop
- main
pull_request:
jobs:
test:
continue-on-error: False
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-12, macos-14]
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20.11"
- name: Setup
run: |
npm install
# Uninstall brew
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
- name: Run Test
run: |
node electron/test.js
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
env:
NODE_ENV: production
DEV_RPC: https://rpc-gate.autonolas.tech/gnosis-rpc/
IS_STAGING: ${{ github.ref != 'refs/heads/main' && 'true' || 'false' }}
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
- run: rm -rf /dist
- name: "Build, notarize, publish"
Expand Down
3 changes: 2 additions & 1 deletion .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:406
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:454
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:455
91ec07457f69e9a29f63693ac8ef887e4b5f49f0:operate/services/manage.py:generic-api-key:454
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:45591ec07457f69e9a29f63693ac8ef887e4b5f49f0:operate/services/manage.py:generic-api-key:454
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:405
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:406
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:454
99c0f139b037da2587708212fcf6d0e20786d0ba:operate/services/manage.py:generic-api-key:455
91ec07457f69e9a29f63693ac8ef887e4b5f49f0:operate/services/manage.py:generic-api-key:454
8 changes: 4 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dotenv = require('dotenv');
const build = require('electron-builder').build;
const {publishOptions} = require('./electron/constants/publishOptions');
const { publishOptions } = require('./electron/constants/publishOptions');

dotenv.config();

Expand All @@ -24,7 +24,7 @@ const main = async () => {
target: [
{
target: 'default',
arch: ['x64','arm64'],
arch: ['x64', 'arm64'],
},
],
publish: publishOptions,
Expand All @@ -35,11 +35,11 @@ const main = async () => {
entitlements: 'electron/entitlements.mac.plist',
entitlementsInherit: 'electron/entitlements.mac.plist',
notarize: {
teamId: process.env.APPLETEAMID
teamId: process.env.APPLETEAMID,
},
},
},
});
};

main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e));
main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e));
138 changes: 91 additions & 47 deletions electron/install.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Installation helpers.

const https = require('https');
const path = require('path');
const nfs = require('node:fs')
const fs = require('fs');
const os = require('os');
const sudo = require('sudo-prompt');
Expand All @@ -10,8 +9,14 @@ const axios = require('axios');

const Docker = require('dockerode');
const { spawnSync } = require('child_process');

const Version = '0.1.0rc45';
const { BrewScript } = require("./scripts")

/**
* current version of the pearl release
* - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26"
* - use "alpha" for alpha release, for example "0.1.0rc26-alpha"
*/
const OlasMiddlewareVersion = '0.1.0rc45';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
Expand All @@ -22,6 +27,7 @@ const OperateCmd = `${os.homedir()}/.operate/venv/bin/operate`;
const Env = {
...process.env,
PATH: `${process.env.PATH}:/opt/homebrew/bin:/usr/local/bin`,
HOMEBREW_NO_AUTO_UPDATE: '1',
};
const SudoOptions = {
name: 'Pearl',
Expand Down Expand Up @@ -66,50 +72,50 @@ function appendLog(log) {
}

function runCmdUnix(command, options) {
fs.appendFileSync(
OperateInstallationLog,
`Runninng ${command} with options ${JSON.stringify(options)}`,
{ encoding: 'utf-8' },
console.log(
appendLog(`Running ${command} with options ${JSON.stringify(options)}`),
);
let bin = getBinPath(command);
if (!bin) {
throw new Error(`Command ${command} not found; Path : ${Env.PATH}`);
}
let output = spawnSync(bin, options);
if (output.stdout) {
appendLog(output.stdout.toString());
}
if (output.stderr) {
appendLog(output.stdout.toString());
}
if (output.error) {
throw new Error(
`Error running ${command} with options ${options};
Error: ${output.error}; Stdout: ${output.stdout}; Stderr: ${output.stderr}`,
);
}
return {
error: output.error,
stdout: output.stdout?.toString(),
stderr: output.stderr?.toString(),
};
console.log(appendLog(`Executed ${command} ${options} with`))
console.log(appendLog(`===== stdout ===== \n${output.stdout}`))
console.log(appendLog(`===== stderr ===== \n${output.stderr}`))
}

function runSudoUnix(command, options) {
let bin = getBinPath(command);
if (!bin) {
throw new Error(`Command ${command} not found`);
}
return new Promise(function (resolve, reject) {
return new Promise(function (resolve, _reject) {
sudo.exec(
`${bin} ${options}`,
SudoOptions,
function (error, stdout, stderr) {
resolve({
let output = {
error: error,
stdout: stdout,
stderr: stderr,
});
};
if (output.error) {
throw new Error(
`Error running ${command} with options ${options};
Error: ${output.error}; Stdout: ${output.stdout}; Stderr: ${output.stderr}`,
);
}
console.log(appendLog(`Executed ${command} ${options} with`))
console.log(appendLog(`===== stdout ===== \n${output.stdout}`))
console.log(appendLog(`===== stderr ===== \n${output.stderr}`))
resolve()
},
);
});
Expand All @@ -119,11 +125,38 @@ function isBrewInstalled() {
return Boolean(getBinPath(getBinPath('brew')));
}

function installBrew() {
return runCmdUnix('bash', [
'-c',
'$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)',
]);
async function installBrew() {
console.log(appendLog("Fetching homebrew source"))
let outdir = `${os.homedir()}/homebrew`
let outfile = `${os.homedir()}/homebrew.tar`

// Make temporary source dir
fs.mkdirSync(outdir)

// Fetch brew source
runCmdUnix("curl", ["-L", "https://github.com/Homebrew/brew/tarball/master", "--output", outfile])
runCmdUnix("tar", ["-xvf", outfile, "--strip-components", "1", "-C", outdir])

// Check for cache and uninstall leftovers
if (fs.existsSync("/opt/homebrew")) {
console.log(appendLog("Removing homebrew leftovers"))
if (!Env.CI) {
await runSudoUnix("rm", `-rf /opt/homebrew`)
} else {
fs.rmdirSync("/opt/homebrew")
}
}

console.log(appendLog("Installing homebrew"))
if (!Env.CI) {
await runSudoUnix("mv", `${outdir} /opt/homebrew`)
await runSudoUnix("chown", `-R ${os.userInfo().username} /opt/homebrew`)
} else {
runCmdUnix("mv", [outdir, "/opt/homebrew"])
runCmdUnix("chown", ["-R", os.userInfo().username, "/opt/homebrew"])
}
runCmdUnix("brew", ["doctor"])
fs.rmSync(outfile)
}

function isTendermintInstalledUnix() {
Expand Down Expand Up @@ -162,8 +195,15 @@ async function installTendermintUnix() {
await downloadFile(url, `${TempDir}/tendermint.tar.gz`);

console.log(appendLog(`Installing tendermint binary`));
await runCmdUnix('tar', ['-xvf', 'tendermint.tar.gz']);
await runSudoUnix('install', 'tendermint /usr/local/bin');
runCmdUnix('tar', ['-xvf', 'tendermint.tar.gz']);

// TOFIX: Install tendermint in .operate instead of globally
if (!Env.CI) {
if (!fs.existsSync("/usr/local/bin")) {
await runSudoUnix('mkdir', '/usr/local/bin')
}
await runSudoUnix('install', 'tendermint /usr/local/bin/tendermint');
}
process.chdir(cwd);
}

Expand All @@ -172,7 +212,7 @@ function isDockerInstalledDarwin() {
}

function installDockerDarwin() {
return runCmdUnix('brew', ['install', 'docker']);
runCmdUnix('brew', ['install', 'docker']);
}

function isDockerInstalledUbuntu() {
Expand All @@ -188,11 +228,11 @@ function isPythonInstalledDarwin() {
}

function installPythonDarwin() {
return runCmdUnix('brew', ['install', '[email protected]']);
runCmdUnix('brew', ['install', '[email protected]']);
}

function createVirtualEnvUnix(path) {
return runCmdUnix('python3.10', ['-m', 'venv', path]);
runCmdUnix('python3.10', ['-m', 'venv', path]);
}

function isPythonInstalledUbuntu() {
Expand All @@ -212,25 +252,25 @@ function installGitUbuntu() {
}

function createVirtualEnvUbuntu(path) {
return runCmdUnix('python3.10', ['-m', 'venv', path]);
runCmdUnix('python3.10', ['-m', 'venv', path]);
}

function installOperatePackageUnix(path) {
return runCmdUnix(`${path}/venv/bin/python3.10`, [
runCmdUnix(`${path}/venv/bin/python3.10`, [
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
]);
}

function reInstallOperatePackageUnix(path) {
console.log(appendLog('Reinstalling pearl CLI'));
return runCmdUnix(`${path}/venv/bin/python3.10`, [
runCmdUnix(`${path}/venv/bin/python3.10`, [
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
'--force-reinstall',
]);
}
Expand All @@ -240,11 +280,11 @@ function installOperateCli(path) {
if (fs.existsSync(installPath)) {
fs.rmSync(installPath);
}
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
fs.copyFile(
`${OperateDirectory}/venv/bin/operate`,
installPath,
function (error, stdout, stderr) {
function (error, _stdout, _stderr) {
resolve(!error);
},
);
Expand All @@ -255,23 +295,23 @@ function createDirectory(path) {
if (fs.existsSync(path)) {
return;
}
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
fs.mkdir(path, { recursive: true }, (error) => {
resolve(!error);
});
});
}

function writeVersion() {
fs.writeFileSync(VersionFile, Version);
fs.writeFileSync(VersionFile, OlasMiddlewareVersion);
}

function versionBumpRequired() {
if (!fs.existsSync(VersionFile)) {
return true;
}
const version = fs.readFileSync(VersionFile).toString();
return version != Version;
const olasMiddlewareVersionInFile = fs.readFileSync(VersionFile).toString();
return olasMiddlewareVersionInFile != OlasMiddlewareVersion;
}

function removeLogFile() {
Expand All @@ -296,7 +336,7 @@ async function setupDarwin(ipcChannel) {
if (!isBrewInstalled()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing brew'));
installBrew();
await installBrew();
}

console.log(appendLog('Checking python installation'));
Expand Down Expand Up @@ -328,7 +368,9 @@ async function setupDarwin(ipcChannel) {

console.log(appendLog('Checking if upgrade is required'));
if (versionBumpRequired()) {
console.log(appendLog(`Upgrading pearl daemon to ${Version}`));
console.log(
appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`),
);
reInstallOperatePackageUnix(OperateDirectory);
writeVersion();
removeLogFile();
Expand Down Expand Up @@ -382,7 +424,9 @@ async function setupUbuntu(ipcChannel) {

console.log(appendLog('Checking if upgrade is required'));
if (versionBumpRequired()) {
console.log(appendLog(`Upgrading pearl daemon to ${Version}`));
console.log(
appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`),
);
reInstallOperatePackageUnix(OperateDirectory);
writeVersion();
removeLogFile();
Expand Down Expand Up @@ -435,4 +479,4 @@ module.exports = {
LogFile,
OperateInstallationLog,
},
};
};
5 changes: 4 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ const createMainWindow = () => {
mainWindow.hide();
});

setupStoreIpc(ipcMain, mainWindow);
const storeInitialValues = {
environmentName: process.env.IS_STAGING ? 'staging' : '',
};
setupStoreIpc(ipcMain, mainWindow, storeInitialValues);

if (isDev) {
mainWindow.webContents.openDevTools();
Expand Down
Loading

0 comments on commit d3f0f01

Please sign in to comment.