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

(WIP) feat: staging release setup #156

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
974d8d4
chore: Refactor electron/update.js for better readability
mohandast52 May 29, 2024
af77fba
chore: Update package.json with new ordering
mohandast52 May 29, 2024
b8a978e
chore: Update .env.example and build.js for IS_STAGING variables
mohandast52 May 29, 2024
b582f3f
Merge pull request #152 from valory-xyz/mohan/staging-setup
mohandast52 May 29, 2024
a7e6f48
Merge pull request #155 from valory-xyz/staging
mohandast52 May 29, 2024
a052cca
feat: Add IS_STAGING variable to production environment configuration
mohandast52 May 29, 2024
657a7c3
chore: Fix typo in electron/install.js and add a comment for 'Version'
mohandast52 May 29, 2024
38cbeb6
feat: Add appVersion to electron store and display it in TopBar
mohandast52 May 29, 2024
0660815
feat: Update electron updater to automatically update to all channels
mohandast52 May 29, 2024
c6897f8
chore: Update electron/install.js and TopBar.tsx for app version disp…
mohandast52 May 30, 2024
92e4046
chore: Update releaseType in publishOptions and store schema
mohandast52 May 30, 2024
afe5407
chore: Update releaseType in publishOptions and store schema
mohandast52 May 30, 2024
b2f8808
chore: Update IS_STAGING variable in production environment configura…
mohandast52 May 31, 2024
3d3b70e
chore: Update IS_STAGING variable in production environment configura…
mohandast52 May 31, 2024
9f7aaf2
chore: Update publishOptions releaseType to 'draft' in electron/const…
mohandast52 Jun 3, 2024
b9cbf28
chore: Update environmentName in store schema and TopBar component
mohandast52 Jun 3, 2024
b12aed4
Merge pull request #159 from valory-xyz/mohan/rename-app-name-on-stag…
mohandast52 Jun 3, 2024
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 .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=
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: ${{ contains(github.ref, 'staging') }}
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
- run: rm -rf /dist
- name: "Build, notarize, publish"
Expand Down
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));
2 changes: 1 addition & 1 deletion electron/constants/publishOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const publishOptions = {
provider: 'github',
owner: 'valory-xyz',
repo: 'olas-operate-app',
releaseType: 'release',
token: process.env.GH_TOKEN,
private: false,
publishAutoUpdate: true,
releaseType: 'draft',
};

module.exports = { publishOptions };
35 changes: 22 additions & 13 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const process = require('process');
const { spawnSync } = require('child_process');
const Docker = require('dockerode');

const Version = '0.1.0rc26';
/**
* 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.0rc26';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const VersionFile = `${OperateDirectory}/version.txt`;
Expand Down Expand Up @@ -46,7 +51,7 @@ function appendLog(log) {
function runCmdUnix(command, options) {
fs.appendFileSync(
OperateInstallationLog,
`Runninng ${command} with options ${JSON.stringify(options)}`,
`Running ${command} with options ${JSON.stringify(options)}`,
{ encoding: 'utf-8' },
);
let bin = getBinPath(command);
Expand Down Expand Up @@ -78,7 +83,7 @@ function runSudoUnix(command, options) {
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,
Expand Down Expand Up @@ -157,7 +162,7 @@ function installOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
]);
}

Expand All @@ -167,7 +172,7 @@ function reInstallOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
'--force-reinstall',
]);
}
Expand All @@ -177,11 +182,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 @@ -192,23 +197,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 Down Expand Up @@ -265,7 +270,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 @@ -322,7 +329,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
5 changes: 4 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,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
32 changes: 15 additions & 17 deletions electron/store.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// set schema to validate store data
const schema = {
isInitialFunded: {
type: 'boolean',
default: false,
},
firstStakingRewardAchieved: {
type: 'boolean',
default: false,
},
firstRewardNotificationShown: {
type: 'boolean',
default: false,
},
const defaultSchema = {
environmentName: { type: 'string', default: '' },
isInitialFunded: { type: 'boolean', default: false },
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
};

const setupStoreIpc = async (ipcChannel, mainWindow) => {
const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => {
const Store = (await import('electron-store')).default;

/** @type import Store from 'electron-store' */
const store = new Store({
schema,
// set default values for store
const schema = Object.assign({}, defaultSchema);
Object.keys(schema).forEach((key) => {
if (storeInitialValues[key] !== undefined) {
schema[key].default = storeInitialValues[key];
}
});

/** @type import Store from 'electron-store' */
const store = new Store({ schema });

store.onDidAnyChange((data) => {
if (mainWindow?.webContents)
mainWindow.webContents.send('store-changed', data);
Expand Down
6 changes: 2 additions & 4 deletions electron/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ const electronLogger = require('electron-log');

const macUpdater = new electronUpdater.MacUpdater({
...publishOptions,
private: false,
channels: ['latest', 'beta', 'alpha'], // automatically update to all channels
});

macUpdater.logger = electronLogger;

macUpdater.setFeedURL({
...publishOptions,
});
macUpdater.setFeedURL({ ...publishOptions });

macUpdater.autoDownload = true;
macUpdater.autoInstallOnAppQuit = true;
Expand Down
6 changes: 5 additions & 1 deletion frontend/components/Layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';

import { COLOR } from '@/constants';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useStore } from '@/hooks/useStore';

const { Text } = Typography;

Expand Down Expand Up @@ -48,6 +49,9 @@ const TopBarContainer = styled.div`

export const TopBar = () => {
const electronApi = useElectronApi();
const store = useStore();
const envName = store?.storeState?.environmentName;

return (
<TopBarContainer>
<TrafficLights>
Expand All @@ -56,7 +60,7 @@ export const TopBar = () => {
<DisabledLight />
</TrafficLights>

<Text>Pearl (alpha)</Text>
<Text>{`Pearl (alpha) ${envName ? `(${envName})` : ''}`.trim()}</Text>
</TopBarContainer>
);
};
1 change: 1 addition & 0 deletions frontend/types/ElectronApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type ElectronStore = {
environmentName?: string;
isInitialFunded?: boolean;
firstStakingRewardAchieved?: boolean;
firstRewardNotificationShown?: boolean;
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"author": "Valory AG",
"main": "electron/main.js",
"name": "olas-operate-app",
"productName": "Pearl",
"private": true,
"version": "0.1.0-rc26",
"dependencies": {
"@ant-design/cssinjs": "^1.18.4",
"@ant-design/icons": "^5.3.0",
Expand Down Expand Up @@ -36,10 +41,6 @@
"net": "^1.0.2",
"prettier": "^3.2.5"
},
"main": "electron/main.js",
"name": "olas-operate-app",
"productName": "Pearl",
"private": true,
"scripts": {
"build:frontend": "cd frontend && yarn build && rm -rf ../electron/.next && cp -r .next ../electron/.next && rm -rf ../electron/public && cp -r public ../electron/public",
"dev:backend": "poetry run python operate/cli.py",
Expand All @@ -53,6 +54,5 @@
"test:frontend": "cd frontend && yarn test",
"start": "electron .",
"build": "rm -rf dist/ && electron-builder build"
},
"version": "0.1.0-rc26"
}
}
Loading