From c5c6de3f89828bf6c8bcedebcaaf8ca95373df2c Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 14:49:15 +0200 Subject: [PATCH 01/13] Add flag to .env file to turn off auto-update --- .env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.example b/.env.example index ad4da5cf..ea127aaf 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ REPO_BRANCH=master IS_BFX_API_STAGING=0 IS_DEV_ENV=0 +IS_AUTO_UPDATE_DISABLED=0 EP_GH_IGNORE_TIME=true +GH_TOKEN= From 749962675b4f4b2a27546894baad2ee373318c74 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 14:50:54 +0200 Subject: [PATCH 02/13] Add option to electron-builder conf to turn off auto-update --- electron-builder-config.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/electron-builder-config.js b/electron-builder-config.js index 8d4f2cee..0e652b6e 100644 --- a/electron-builder-config.js +++ b/electron-builder-config.js @@ -54,6 +54,13 @@ const getNodeModulesSubSources = (mainSource) => { } module.exports = { + /* + * This setting is not part of the electron-builder, + * used to turn off the auto-update for the releases of the app + * via GitHub actions or .env setting + */ + isAutoUpdateDisabled: false, + generateUpdatesFilesForAllChannels: true, npmRebuild: false, extends: null, From aa7084d4c78e824777844b11b1d1547edb4a459f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 14:53:52 +0200 Subject: [PATCH 03/13] Add option to github action workflow to turn off auto-update --- .github/workflows/build-electron-app.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/build-electron-app.yml b/.github/workflows/build-electron-app.yml index 5aa8c1eb..2dfb8176 100644 --- a/.github/workflows/build-electron-app.yml +++ b/.github/workflows/build-electron-app.yml @@ -13,6 +13,9 @@ on: version: description: 'Release version' required: false + isAutoUpdateDisabled: + description: 'Is auto-update disabled (true / 1)?' + required: false env: DOCKER_BUILDKIT: 1 @@ -38,6 +41,12 @@ jobs: sed -i -e \ "s/\"version\": \".*\"/\"version\": \"${{ github.event.inputs.version }}\"/g" \ "./package.json" + - if: contains(fromJson('["true", "1", true, 1]'), github.event.inputs.isAutoUpdateDisabled) + name: Turn off auto-update + run: | + sed -i -e \ + "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ + "./electron-builder-config.js" - name: Cache Docker images uses: ScribeMD/docker-cache@0.1.4 env: @@ -92,6 +101,12 @@ jobs: sed -i -e \ "s/\"version\": \".*\"/\"version\": \"${{ github.event.inputs.version }}\"/g" \ "./package.json" + - if: contains(fromJson('["true", "1", true, 1]'), github.event.inputs.isAutoUpdateDisabled) + name: Turn off auto-update + run: | + sed -i -e \ + "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ + "./electron-builder-config.js" - uses: actions/setup-node@v3 with: node-version: 14.16.0 From 111dbf7baabfb015f67c4c5573c413d81870924e Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 14:56:24 +0200 Subject: [PATCH 04/13] Add env var to docker-compose file to turn off auto-update --- docker-compose.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 35f88545..d77f06bf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,6 +26,7 @@ services: COMMON_DIST_FOLDER: /dist IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_AUTO_UPDATE_DISABLED: ${IS_AUTO_UPDATE_DISABLED:-0} IS_PUBLISHED: ${IS_PUBLISHED:-0} GH_TOKEN: ${GH_TOKEN:-} GITHUB_TOKEN: ${GITHUB_TOKEN:-} @@ -49,6 +50,7 @@ services: COMMON_DIST_FOLDER: /dist IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_AUTO_UPDATE_DISABLED: ${IS_AUTO_UPDATE_DISABLED:-0} IS_PUBLISHED: ${IS_PUBLISHED:-0} GH_TOKEN: ${GH_TOKEN:-} GITHUB_TOKEN: ${GITHUB_TOKEN:-} @@ -72,6 +74,7 @@ services: COMMON_DIST_FOLDER: /dist IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_AUTO_UPDATE_DISABLED: ${IS_AUTO_UPDATE_DISABLED:-0} IS_PUBLISHED: ${IS_PUBLISHED:-0} GH_TOKEN: ${GH_TOKEN:-} GITHUB_TOKEN: ${GITHUB_TOKEN:-} From f874a0d54a9ba166c96ac38b654ee211e30719ac Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 14:58:23 +0200 Subject: [PATCH 05/13] Add option to bash scripts to turn off auto-update --- scripts/build-release.sh | 10 ++++++++++ scripts/launch.sh | 6 ++++++ scripts/setup.sh | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 913fb7b1..5560c046 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -56,6 +56,7 @@ buildWin=0 buildMac=0 isBfxApiStaging=${IS_BFX_API_STAGING:-0} isDevEnv=${IS_DEV_ENV:-0} +isAutoUpdateDisabled=${IS_AUTO_UPDATE_DISABLED:-0} isPublished=${IS_PUBLISHED:-0} function usage { @@ -67,6 +68,7 @@ function usage { -m Build Mac release -s Use staging BFX API -d Set development environment + -u Turn off auto-update -p Publish artifacts -h Display help\ ${COLOR_NORMAL}" 1>&2 @@ -85,6 +87,7 @@ while getopts "lwmsdph" opt; do m) buildMac=1;; s) isBfxApiStaging=1;; d) isDevEnv=1;; + u) isAutoUpdateDisabled=1;; p) isPublished=1;; h) usage @@ -139,6 +142,13 @@ if [ $isDevEnv == 1 ]; then else rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" fi +if [ $isAutoUpdateDisabled == 1 ]; then + echo -e "\n${COLOR_YELLOW}Auto-update is turned off!${COLOR_NORMAL}" + + sed -i -e \ + "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ + "$ELECTRON_BUILDER_CONFIG_FILE_PATH" +fi changeDirOwnershipToCurrUser "$ELECTRON_CACHE" "$(id -u):$(id -g)" changeDirOwnershipToCurrUser "$ELECTRON_BUILDER_CACHE" "$(id -u):$(id -g)" diff --git a/scripts/launch.sh b/scripts/launch.sh index 832b3b90..7ad72e67 100755 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -28,6 +28,7 @@ syncRepo=0 syncSubModules=0 isBfxApiStaging=${IS_BFX_API_STAGING:-0} isDevEnv=${IS_DEV_ENV:-0} +isAutoUpdateDisabled=${IS_AUTO_UPDATE_DISABLED:-0} isPublished=${IS_PUBLISHED:-0} function usage { @@ -42,6 +43,7 @@ function usage { -o Sync only sub-modules -s Use staging BFX API -d Set development environment + -u Turn off auto-update -p Publish artifacts -h Display help\ ${COLOR_NORMAL}" 1>&2 @@ -67,6 +69,7 @@ while getopts "alwmrosdph" opt; do o) syncSubModules=1;; s) isBfxApiStaging=1;; d) isDevEnv=1;; + u) isAutoUpdateDisabled=1;; p) isPublished=1;; h) usage @@ -94,6 +97,9 @@ fi if [ $isDevEnv == 1 ]; then export IS_DEV_ENV=1 fi +if [ $isAutoUpdateDisabled == 1 ]; then + export IS_AUTO_UPDATE_DISABLED=1 +fi if [ $isPublished == 1 ]; then export IS_PUBLISHED=1 fi diff --git a/scripts/setup.sh b/scripts/setup.sh index ae39a923..01b26b33 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -20,6 +20,7 @@ COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} BFX_API_URL="https://api-pub.bitfinex.com" STAGING_BFX_API_URL="https://api.staging.bitfinex.com" +ELECTRON_BUILDER_CONFIG_FILE_NAME="electron-builder-config.js" LAST_COMMIT_FILE_NAME="lastCommit.json" ELECTRON_ENV_FILE_NAME="electronEnv.json" @@ -40,6 +41,7 @@ syncRepo=0 syncSubModules=0 isBfxApiStaging=${IS_BFX_API_STAGING:-0} isDevEnv=${IS_DEV_ENV:-0} +isAutoUpdateDisabled=${IS_AUTO_UPDATE_DISABLED:-0} function usage { echo -e "\ @@ -49,6 +51,7 @@ function usage { -o Sync only sub-modules -s Use staging BFX API -d Set development environment + -u Turn off auto-update -h Display help\ ${COLOR_NORMAL}" 1>&2 } @@ -59,6 +62,7 @@ while getopts "rosdh" opt; do o) syncSubModules=1;; s) isBfxApiStaging=1;; d) isDevEnv=1;; + u) isAutoUpdateDisabled=1;; h) usage exit 0 @@ -81,6 +85,13 @@ if [ $isDevEnv == 1 ]; then else rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" fi +if [ $isAutoUpdateDisabled == 1 ]; then + echo -e "\n${COLOR_YELLOW}Auto-update is turned off!${COLOR_NORMAL}" + + sed -i -e \ + "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ + "$ROOT/$ELECTRON_BUILDER_CONFIG_FILE_NAME" +fi if [ $syncRepo == 1 ]; then echo -e "\n${COLOR_BLUE}Syncing all repositories...${COLOR_NORMAL}" From 15bdc9bdbe20d37af36676d2c8fa4aadf1664578 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 15:01:01 +0200 Subject: [PATCH 06/13] Add helper to detect that auto-update is disabled --- src/helpers/is-auto-update-disabled.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/helpers/is-auto-update-disabled.js diff --git a/src/helpers/is-auto-update-disabled.js b/src/helpers/is-auto-update-disabled.js new file mode 100644 index 00000000..476c21e9 --- /dev/null +++ b/src/helpers/is-auto-update-disabled.js @@ -0,0 +1,15 @@ +'use strict' + +const path = require('path') +const { rootPath: appDir } = require('electron-root-path') + +let electronBuilderConfig = {} + +try { + electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) +} catch (err) {} + +const isAutoUpdateDisabled = electronBuilderConfig + ?.isAutoUpdateDisabled ?? false + +module.exports = !!isAutoUpdateDisabled From 2f12b1aef57cc14f1aa1b72f09bd901c22bb144f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 15:02:29 +0200 Subject: [PATCH 07/13] Add ability to turn off auto-update --- src/auto-updater/index.js | 43 +++++++++++++++++++++++++++++++---- src/create-menu.js | 2 ++ src/helpers/get-debug-info.js | 14 +----------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/auto-updater/index.js b/src/auto-updater/index.js index 00d937f4..5bb353bc 100644 --- a/src/auto-updater/index.js +++ b/src/auto-updater/index.js @@ -1,6 +1,7 @@ 'use strict' const { app, ipcMain, Menu } = require('electron') +const { rootPath: appDir } = require('electron-root-path') const fs = require('fs') const path = require('path') const { @@ -21,6 +22,7 @@ const { const { closeAlert } = require('../modal-dialog-src/utils') +const isAutoUpdateDisabled = require('../helpers/is-auto-update-disabled') const fontsStyle = fs.readFileSync(path.join( __dirname, '../../bfx-report-ui/build/fonts/roboto.css' @@ -37,6 +39,11 @@ let autoUpdater let uCheckInterval let isIntervalUpdate = false let isProgressToastEnabled = false +let electronBuilderConfig = {} + +try { + electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) +} catch (err) {} const fonts = `` const style = `` @@ -451,6 +458,12 @@ const _autoUpdaterFactory = () => { const checkForUpdates = () => { return async () => { try { + if (isAutoUpdateDisabled) { + console.debug('Auto-update is disabled') + + return + } + isIntervalUpdate = false _switchMenuItem({ isCheckMenuItemDisabled: true @@ -468,6 +481,12 @@ const checkForUpdates = () => { const checkForUpdatesAndNotify = async (opts) => { try { + if (isAutoUpdateDisabled) { + console.debug('Auto-update is disabled') + + return + } + const { isIntervalUpdate: isIntUp = false } = { ...opts } @@ -488,17 +507,33 @@ const checkForUpdatesAndNotify = async (opts) => { const quitAndInstall = () => { return () => { + if (isAutoUpdateDisabled) { + return + } + return _autoUpdaterFactory() .quitAndInstall(false, true) } } const getAppUpdateConfigSync = () => { - const appUpdateConfigPath = _autoUpdaterFactory() - .app.appUpdateConfigPath - const fileContent = fs.readFileSync(appUpdateConfigPath, 'utf8') + try { + if (isAutoUpdateDisabled) { + return electronBuilderConfig + ?.publish ?? {} + } - return yaml.load(fileContent) + const appUpdateConfigPath = _autoUpdaterFactory() + .app.appUpdateConfigPath + const fileContent = fs.readFileSync(appUpdateConfigPath, 'utf8') + + return yaml.load(fileContent) + } catch (err) { + console.debug(err) + + return electronBuilderConfig + ?.publish ?? {} + } } module.exports = { diff --git a/src/create-menu.js b/src/create-menu.js index 62b55a2e..60d4325c 100644 --- a/src/create-menu.js +++ b/src/create-menu.js @@ -21,6 +21,7 @@ const { const { manageNewGithubIssue } = require('./error-manager') const showDocs = require('./show-docs') const { showChangelog } = require('./changelog-manager') +const isAutoUpdateDisabled = require('./helpers/is-auto-update-disabled') module.exports = ({ pathToUserData, @@ -140,6 +141,7 @@ module.exports = ({ { type: 'separator' }, { label: 'Check for updates', + enabled: !isAutoUpdateDisabled, id: 'CHECK_UPDATE_MENU_ITEM', click: checkForUpdates() }, diff --git a/src/helpers/get-debug-info.js b/src/helpers/get-debug-info.js index 1612d637..8ae5e7f6 100644 --- a/src/helpers/get-debug-info.js +++ b/src/helpers/get-debug-info.js @@ -9,23 +9,11 @@ const { getAppUpdateConfigSync } = require('../auto-updater') const packageJson = require(path.join(appDir, 'package.json')) const productName = require('./product-name') -let electronBuilderConfig = {} - -try { - electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) -} catch (err) {} let lastCommit = { hash: '-', date: '-' } -let appUpdateConfig = {} -try { - appUpdateConfig = getAppUpdateConfigSync() -} catch (err) { - console.debug(err) +const appUpdateConfig = getAppUpdateConfigSync() - appUpdateConfig = electronBuilderConfig - ?.publish ?? {} -} try { lastCommit = require(path.join(appDir, 'lastCommit.json')) } catch (err) { From 7779bd3e1061cb74d00a8b11664bfb8d5f12cd9e Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 23 Nov 2022 15:04:44 +0200 Subject: [PATCH 08/13] Add option to readme file about turn off auto-update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1a01f481..bb197f0b 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Options: -o Sync only sub-modules -s Use staging BFX API -d Set development environment + -u Turn off auto-update -h Display help ``` @@ -137,6 +138,7 @@ Options: -o Sync only sub-modules -s Use staging BFX API -d Set development environment + -u Turn off auto-update -p Publish artifacts -h Display help ``` From 48b4271c5341c778dc3a305e789f3698ffa40839 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 24 Nov 2022 14:23:37 +0200 Subject: [PATCH 09/13] Change auto-update management via env var --- electron-builder-config.js | 9 +-------- index.js | 13 +++++++------ src/auto-updater/index.js | 2 +- src/create-menu.js | 2 +- src/helpers/is-auto-update-disabled.js | 15 --------------- 5 files changed, 10 insertions(+), 31 deletions(-) delete mode 100644 src/helpers/is-auto-update-disabled.js diff --git a/electron-builder-config.js b/electron-builder-config.js index 0e652b6e..ec860d83 100644 --- a/electron-builder-config.js +++ b/electron-builder-config.js @@ -54,13 +54,6 @@ const getNodeModulesSubSources = (mainSource) => { } module.exports = { - /* - * This setting is not part of the electron-builder, - * used to turn off the auto-update for the releases of the app - * via GitHub actions or .env setting - */ - isAutoUpdateDisabled: false, - generateUpdatesFilesForAllChannels: true, npmRebuild: false, extends: null, @@ -71,7 +64,7 @@ module.exports = { publish: { provider: 'github', repo: 'bfx-report-electron', - owner: 'bitfinexcom', + owner: 'ZIMkaRU', vPrefixedTagName: true, channel: 'latest', diff --git a/index.js b/index.js index c49aad35..98810008 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,14 @@ 'use strict' try { - const { NODE_ENV } = require('./electronEnv.json') + const envVars = require('./electronEnv.json') - if ( - !process.env.NODE_ENV && - NODE_ENV - ) { - process.env.NODE_ENV = NODE_ENV + for (const [key, val] of Object.entries(envVars)) { + if (typeof process.env[key] !== 'undefined') { + continue + } + + process.env[key] = val } } catch (err) {} diff --git a/src/auto-updater/index.js b/src/auto-updater/index.js index 5bb353bc..8a2b229f 100644 --- a/src/auto-updater/index.js +++ b/src/auto-updater/index.js @@ -22,7 +22,7 @@ const { const { closeAlert } = require('../modal-dialog-src/utils') -const isAutoUpdateDisabled = require('../helpers/is-auto-update-disabled') +const isAutoUpdateDisabled = !!process.env.IS_AUTO_UPDATE_DISABLED const fontsStyle = fs.readFileSync(path.join( __dirname, '../../bfx-report-ui/build/fonts/roboto.css' diff --git a/src/create-menu.js b/src/create-menu.js index 60d4325c..0670bb05 100644 --- a/src/create-menu.js +++ b/src/create-menu.js @@ -21,7 +21,7 @@ const { const { manageNewGithubIssue } = require('./error-manager') const showDocs = require('./show-docs') const { showChangelog } = require('./changelog-manager') -const isAutoUpdateDisabled = require('./helpers/is-auto-update-disabled') +const isAutoUpdateDisabled = !!process.env.IS_AUTO_UPDATE_DISABLED module.exports = ({ pathToUserData, diff --git a/src/helpers/is-auto-update-disabled.js b/src/helpers/is-auto-update-disabled.js deleted file mode 100644 index 476c21e9..00000000 --- a/src/helpers/is-auto-update-disabled.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict' - -const path = require('path') -const { rootPath: appDir } = require('electron-root-path') - -let electronBuilderConfig = {} - -try { - electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) -} catch (err) {} - -const isAutoUpdateDisabled = electronBuilderConfig - ?.isAutoUpdateDisabled ?? false - -module.exports = !!isAutoUpdateDisabled From e272bcfd0639f4500e43a06708a3a6934ae99b93 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 24 Nov 2022 14:24:22 +0200 Subject: [PATCH 10/13] Add electronEnv.json.example file --- electronEnv.json.example | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 electronEnv.json.example diff --git a/electronEnv.json.example b/electronEnv.json.example new file mode 100644 index 00000000..60128780 --- /dev/null +++ b/electronEnv.json.example @@ -0,0 +1,4 @@ +{ + "NODE_ENV": "production", + "IS_AUTO_UPDATE_DISABLED": false +} From edd2d37a6f606b46373ee23301562297b253f315 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 24 Nov 2022 14:25:49 +0200 Subject: [PATCH 11/13] Add electronEnv.json file to dockerignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index cd8f131d..437cb0ee 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,7 @@ *Dockerfile* *docker-compose* lastCommit.json +electronEnv.json dev-app-update.yml dist bfx-reports-framework/db/*.db From b0c9e676673658f243e5b8eadce818b0c82e5204 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 24 Nov 2022 14:27:43 +0200 Subject: [PATCH 12/13] Change bash scripts to manage auto-update via env var --- scripts/build-release.sh | 19 +++++++++++++++---- scripts/setup.sh | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 5560c046..45d6ad22 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -132,22 +132,33 @@ if [ $buildMac == 1 ]; then targetPlatform="mac" fi +cp "$ROOT/$ELECTRON_ENV_FILE_NAME.example" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" + if [ $isBfxApiStaging == 1 ]; then bfxApiUrl="$STAGING_BFX_API_URL" fi if [ $isDevEnv == 1 ]; then echo -e "\n${COLOR_YELLOW}Developer environment is turned on!${COLOR_NORMAL}" - echo "{\"NODE_ENV\":\"development\"}" > "$ROOT/$ELECTRON_ENV_FILE_NAME" + sed -i -e \ + "s/\"NODE_ENV\": \".*\"/\"NODE_ENV\": \"development\"/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" else - rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" + sed -i -e \ + "s/\"NODE_ENV\": \".*\"/\"NODE_ENV\": \"production\"/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" fi if [ $isAutoUpdateDisabled == 1 ]; then echo -e "\n${COLOR_YELLOW}Auto-update is turned off!${COLOR_NORMAL}" sed -i -e \ - "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ - "$ELECTRON_BUILDER_CONFIG_FILE_PATH" + "s/\"IS_AUTO_UPDATE_DISABLED\": .*/\"IS_AUTO_UPDATE_DISABLED\": true/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" +else + sed -i -e \ + "s/\"IS_AUTO_UPDATE_DISABLED\": .*/\"IS_AUTO_UPDATE_DISABLED\": false/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" fi changeDirOwnershipToCurrUser "$ELECTRON_CACHE" "$(id -u):$(id -g)" diff --git a/scripts/setup.sh b/scripts/setup.sh index 01b26b33..7ffd8697 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -20,7 +20,6 @@ COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} BFX_API_URL="https://api-pub.bitfinex.com" STAGING_BFX_API_URL="https://api.staging.bitfinex.com" -ELECTRON_BUILDER_CONFIG_FILE_NAME="electron-builder-config.js" LAST_COMMIT_FILE_NAME="lastCommit.json" ELECTRON_ENV_FILE_NAME="electronEnv.json" @@ -75,22 +74,33 @@ while getopts "rosdh" opt; do esac done +cp "$ROOT/$ELECTRON_ENV_FILE_NAME.example" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" + if [ $isBfxApiStaging == 1 ]; then bfxApiUrl="$STAGING_BFX_API_URL" fi if [ $isDevEnv == 1 ]; then echo -e "\n${COLOR_YELLOW}Developer environment is turned on!${COLOR_NORMAL}" - echo "{\"NODE_ENV\":\"development\"}" > "$ROOT/$ELECTRON_ENV_FILE_NAME" + sed -i -e \ + "s/\"NODE_ENV\": \".*\"/\"NODE_ENV\": \"development\"/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" else - rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" + sed -i -e \ + "s/\"NODE_ENV\": \".*\"/\"NODE_ENV\": \"production\"/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" fi if [ $isAutoUpdateDisabled == 1 ]; then echo -e "\n${COLOR_YELLOW}Auto-update is turned off!${COLOR_NORMAL}" sed -i -e \ - "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ - "$ROOT/$ELECTRON_BUILDER_CONFIG_FILE_NAME" + "s/\"IS_AUTO_UPDATE_DISABLED\": .*/\"IS_AUTO_UPDATE_DISABLED\": true/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" +else + sed -i -e \ + "s/\"IS_AUTO_UPDATE_DISABLED\": .*/\"IS_AUTO_UPDATE_DISABLED\": false/g" \ + "$ROOT/$ELECTRON_ENV_FILE_NAME" fi if [ $syncRepo == 1 ]; then From f36c164128cb815ab1def806fc25ebaa05ae422e Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 24 Nov 2022 14:28:36 +0200 Subject: [PATCH 13/13] Change gh actions workflow to manage auto-update via env var --- .github/workflows/build-electron-app.yml | 8 ++------ electron-builder-config.js | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-electron-app.yml b/.github/workflows/build-electron-app.yml index 2dfb8176..847e2bda 100644 --- a/.github/workflows/build-electron-app.yml +++ b/.github/workflows/build-electron-app.yml @@ -44,9 +44,7 @@ jobs: - if: contains(fromJson('["true", "1", true, 1]'), github.event.inputs.isAutoUpdateDisabled) name: Turn off auto-update run: | - sed -i -e \ - "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ - "./electron-builder-config.js" + echo "IS_AUTO_UPDATE_DISABLED=1" >> $GITHUB_ENV - name: Cache Docker images uses: ScribeMD/docker-cache@0.1.4 env: @@ -104,9 +102,7 @@ jobs: - if: contains(fromJson('["true", "1", true, 1]'), github.event.inputs.isAutoUpdateDisabled) name: Turn off auto-update run: | - sed -i -e \ - "s/isAutoUpdateDisabled: '.*'/isAutoUpdateDisabled: true/g" \ - "./electron-builder-config.js" + echo "IS_AUTO_UPDATE_DISABLED=1" >> $GITHUB_ENV - uses: actions/setup-node@v3 with: node-version: 14.16.0 diff --git a/electron-builder-config.js b/electron-builder-config.js index ec860d83..8d4f2cee 100644 --- a/electron-builder-config.js +++ b/electron-builder-config.js @@ -64,7 +64,7 @@ module.exports = { publish: { provider: 'github', repo: 'bfx-report-electron', - owner: 'ZIMkaRU', + owner: 'bitfinexcom', vPrefixedTagName: true, channel: 'latest',