From 5a56bde76bf6b74d4b93c0d07a486345dd757cb5 Mon Sep 17 00:00:00 2001 From: burgerni10 Date: Thu, 1 Dec 2022 14:35:55 +0100 Subject: [PATCH] fix(ci): do not copy useless file in win/bin and fix config path --- .github/actions/setup_environment/action.yml | 2 +- .github/workflows/ci.yml | 4 +-- .github/workflows/release.yml | 8 ++--- build/deps/linux/oibus-setup.sh | 6 ++-- .../OPC REDISTRIBUTABLES Agreement of Use.md | 0 build/deps/win/favicon.ico | Bin 19102 -> 0 bytes build/deps/win/setup.iss | 15 ++++---- package.json | 5 ++- src/engine/history-query-engine.spec.js | 10 +++--- src/engine/oibus-engine.spec.js | 8 ++--- src/frontend/favicon.ico | Bin 96942 -> 19102 bytes src/service/configuration.service.js | 34 +++++++++--------- src/service/configuration.service.spec.js | 23 ++++-------- tsconfig.json | 1 + 14 files changed, 54 insertions(+), 62 deletions(-) rename build/deps/win/{ => HdaAgent}/OPC REDISTRIBUTABLES Agreement of Use.md (100%) delete mode 100644 build/deps/win/favicon.ico diff --git a/.github/actions/setup_environment/action.yml b/.github/actions/setup_environment/action.yml index 469ac72b99..2d3148f11d 100644 --- a/.github/actions/setup_environment/action.yml +++ b/.github/actions/setup_environment/action.yml @@ -16,7 +16,7 @@ runs: - name: Get current date shell: bash id: date - run: echo "::set-output name=date::$(date +'calendar-week-%W')" + run: echo "date=$(date +'calendar-week-%W')" >> $GITHUB_OUTPUT - name: Write cache version shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d077964991..01886efcfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,10 @@ on: workflow_call: push: branches: [ "main", "release" ] - paths-ignore: [ "docs/**", "deps/**", "**.md" ] + paths-ignore: [ "documentation/**", "deps/**", "**.md" ] pull_request: types: [ opened, synchronize, ready_for_review ] - paths-ignore: [ "docs/**", "deps/**", "**.md" ] + paths-ignore: [ "documentation/**", "deps/**", "**.md" ] concurrency: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81fe2646d6..1d15e6245a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,9 +50,9 @@ jobs: npx standard-version -i ./CHANGELOG.md $VERSION_ARGS git status git push --follow-tags origin HEAD - echo ::set-output name=version-tag::$(git describe --tags $(git rev-list --tags --max-count=1)) - echo ::set-output name=prerelease::$PRERELEASE - echo ::set-output name=branch-release::$BRANCH_RELEASE + echo "version-tag=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_OUTPUT + echo "prerelease=$PRERELEASE" >> $GITHUB_OUTPUT + echo "branch-release=$BRANCH_RELEASE" >> $GITHUB_OUTPUT - name: Upload artifact CHANGELOG.md uses: actions/upload-artifact@v3 @@ -86,7 +86,7 @@ jobs: run: | npm run build:${{ matrix.config['platform'] }} cd build/bin/${{ matrix.config['platform'] }} - ./oibus --config ../../../data-folder/oibus.json --check true + ./oibus --config ../../../data-folder --check true ${{ matrix.config['zip'] }} ../${{ matrix.config['archiveName'] }} . - name: Upload artifact ${{ matrix.config['archiveName'] }} diff --git a/build/deps/linux/oibus-setup.sh b/build/deps/linux/oibus-setup.sh index 845ab02a2e..47bd941985 100755 --- a/build/deps/linux/oibus-setup.sh +++ b/build/deps/linux/oibus-setup.sh @@ -122,9 +122,9 @@ if ! sudo mv oibus.service /etc/systemd/system/; then exit 1 fi -conf_path=$(readlink -m "$conf_file") +conf_path=$(readlink -m "$my_data_directory") touch oibus-env -printf "ARG1=--config\nARG2=%s" "$conf_path" >>oibus-env +printf "ARG1=--config\nARG2=%s" "$conf_path" >> oibus-env if ! sudo mv oibus-env $install_dir; then printf "ERROR: Could not create OIBus service file. Terminating installation process." @@ -162,7 +162,7 @@ fi printf '#!/bin/bash\n\n' printf "echo 'Stopping OIBus service...'\n" printf 'sudo systemctl stop oibus\n' - printf "%s/oibus --config '%s/oibus.json'" "$dir" "$data_directory" + printf "%s/oibus --config '%s'" "$dir" "$data_directory" } >> "$dir"/go.sh # Updating uninstall script diff --git a/build/deps/win/OPC REDISTRIBUTABLES Agreement of Use.md b/build/deps/win/HdaAgent/OPC REDISTRIBUTABLES Agreement of Use.md similarity index 100% rename from build/deps/win/OPC REDISTRIBUTABLES Agreement of Use.md rename to build/deps/win/HdaAgent/OPC REDISTRIBUTABLES Agreement of Use.md diff --git a/build/deps/win/favicon.ico b/build/deps/win/favicon.ico deleted file mode 100644 index 21fb7031672083d0462ad5d127af4e3868d96dca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19102 zcmeI4F^E=25XWC2jYS}7QdkK#Vjx-wrVx^#B3KznDIt*3#!|4ci(ru=Wr{$`fCN%n zn8L!sA}K6v2WhNIn%kF~=EJ6GPAusBf^IK}cFO5XO>_L?J!%^kzmh3`y-exbt(}%WeYBkp zE1@I0LVacH#culg@lH$4y;te55;~$Ql{G4z+t3R&5v8pX?;4g#KQ3z2ADelb|8p{dbL5U9k`nsXc>%hsR9s%lL@mBlC_e zzyG^;4%XVJrhROo@07Ue=M_)s?(3;oAPX`L=>T8$gfaU9bE+@naz%KI!Nku~5)0wr zdFY+JliUIFm`{0Ud=77Y8^S|!sjgTEiL&v6J+7~iR}HPx6x(1fXozQSPA_W-yO7=c zxp`L}kdtZdH}Q!0E6zkbeE*6?he!!5h>6jef*2O9$Ew=!Lti9YPrm$OKVImW8uI${e){2d zO9zR?n0+LYRc*Q0sl5SAWD}~vKzWPivNd^6l=~3tZNCUBZ#%Ys?!L2P(fvD8ggt&^ zv9!;uCH@c5?(IVPBQ~LNJX_n4P3U`6v;NV3?{lA$b`hONI0xACh?Ujm3B*5(g>;tQ zb{yZ-Hy0~4Mt2roSK^5JQ2T;^EbAi`i_S;DmU{tTh$BAVr7vr$_)i?Pdxh+QcKMK9 z!?DlN-4gO)D}D|y_Z+)m?ufVUwXhq{U-2JIv@fW(vBZxX^A5l0t`VJmtYAK0=3>E| zeg4UvSDy~vM&{UpctrV5Ze1!Covp3{i@q~5ymYUkwTo(d4-1pcdM+R<-Jk=>2eS9gJ`hcK*IbTMEVEVM4zhSqn?x-Q#C`!@W*sh!U;&a%T=9^R7 z`FTDlyBLxg{S?n_T}tnWzvaU-ymI_X+eIYPy0ld+Ru?bU#Reidt6jWl7o24yoHnTq z4EX!hipAc&E?CsR;qLy1+vXutbN+SqBXouQ*+Ds3#iGkr@t2`{!F9F;$&QZb3e^%L Qp#L|g))j$@z%T-@0crPvjsO4v diff --git a/build/deps/win/setup.iss b/build/deps/win/setup.iss index c7cce65279..74dfc26bc8 100644 --- a/build/deps/win/setup.iss +++ b/build/deps/win/setup.iss @@ -29,7 +29,7 @@ PrivilegesRequired=admin SolidCompression=yes UsePreviousAppDir=no UserInfoPage=no -SetupIconFile=favicon.ico +SetupIconFile=..\..\..\src\frontend\favicon.ico WizardImageFile=installer_oibus.bmp WizardSmallImageFile=installer_small.bmp WizardStyle=modern @@ -43,10 +43,9 @@ Name: "en"; MessagesFile: "compiler:Default.isl" [Files] Source: "..\..\bin\win\oibus.exe"; DestDir: "{app}"; Flags: ignoreversion -Source: "HdaAgent\*"; DestDir: "{app}\HdaAgent"; Flags: ignoreversion recursesubdirs createallsubdirs -Source: "nssm.exe"; DestDir: "{app}"; Flags: ignoreversion -Source: "OPC REDISTRIBUTABLES Agreement of Use.md"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\..\..\LICENSE"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\..\bin\win\HdaAgent\*"; DestDir: "{app}\HdaAgent"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "..\..\bin\win\nssm.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\..\bin\win\LICENSE"; DestDir: "{app}"; Flags: ignoreversion Source: "..\..\..\src\config\default-config.json"; DestDir: "{app}"; Flags: ignoreversion @@ -191,9 +190,9 @@ begin Result := False else if not ExecCmd('nssm.exe', 'stop OIBus >nul 2>&1', ExpandConstant('{app}')) then Result := False - else if not SaveStringToFile(LogPath, 'nssm.exe install OIBus "' + ExpandConstant('{app}') + '\oibus.exe" "--config ""' + OIBus_DataDirPage.Values[0] + '\oibus.json"""' + #13#10, True) then + else if not SaveStringToFile(LogPath, 'nssm.exe install OIBus "' + ExpandConstant('{app}') + '\oibus.exe" "--config ""' + OIBus_DataDirPage.Values[0] + '"""' + #13#10, True) then Result := False - else if not ExecCmd('nssm.exe', 'install OIBus "' + ExpandConstant('{app}') + '\oibus.exe" "--config ""' + OIBus_DataDirPage.Values[0] + '\oibus.json"""', ExpandConstant('{app}')) then + else if not ExecCmd('nssm.exe', 'install OIBus "' + ExpandConstant('{app}') + '\oibus.exe" "--config ""' + OIBus_DataDirPage.Values[0] + '"""', ExpandConstant('{app}')) then Result := False else if not SaveStringToFile(LogPath, 'nssm.exe set OIBus AppDirectory "' + ExpandConstant('{app}') + '"' + #13#10, True) then Result := False @@ -229,7 +228,7 @@ var FileContent: ansistring; ConfigFilePath: string; begin; - ConfigFilePath := OIBus_DataDirPage.Values[0] + '\oibus.json'; + ConfigFilePath := OIBus_DataDirPage.Values[0]; FileContent := 'echo Stopping OIBus service...' + #13#10 + 'nssm.exe stop OIBus' + #13#10 + '@echo Starting OIBus in the console...' + #13#10 diff --git a/package.json b/package.json index 971f95d3be..a760403284 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint": "eslint src --ext .jsx --ext .js", "lint:fix": "eslint src --ext .jsx --ext .js --fix", "build:all": "npm ci && npm run build:win && npm run build:macos && npm run build:linux", - "build:win": "npm run internal:build:web-client && npm run internal:build:backend && npm run internal:build:lib-win && rimraf ./build/bin/win && pkg ./build/backend/index.js --public --compress GZip --config package.json --output ./build/bin/win/oibus --target node16-win-x64 && ncp ./build/deps/win ./build/bin/win", + "build:win": "npm run internal:build:web-client && npm run internal:build:backend && npm run internal:build:lib-win && rimraf ./build/bin/win && pkg ./build/backend/index.js --public --compress GZip --config package.json --output ./build/bin/win/oibus --target node16-win-x64 && ncp ./build/deps/win/HdaAgent ./build/bin/win/HdaAgent && ncp ./build/deps/win/nssm.exe ./build/bin/win/nssm.exe && ncp ./LICENSE ./build/bin/win/LICENSE", "build:macos": "npm run internal:build:web-client && npm run internal:build:backend && npm run internal:build:lib-macos && rimraf ./build/bin/macos && pkg ./build/backend/index.js --public --compress GZip --config package.json --output ./build/bin/macos/oibus --target node16-macos-x64", "build:linux": "npm run internal:build:web-client && npm run internal:build:backend && npm run internal:build:lib-linux && rimraf ./build/bin/linux && pkg ./build/backend/index.js --public --compress GZip --config package.json --output ./build/bin/linux/oibus --target node16-linux-x64 && ncp ./build/deps/linux ./build/bin/linux && ncp ./src/config/default-config.json ./build/bin/linux/default-config.json", "build:win-setup": "rimraf ./build/bin/win/win-setup-release && C:\\\"Program Files (x86)\"\\\"Inno Setup 6\"\\iscc.exe \"./build/deps/win/setup.iss\" \"/DMyAppVersion=\"%npm_package_version% \"/DMyCertFile=\"%PFX_PATH% \"/DMyCertPassword=\"%PFX_PASSWORD% \"/ssigntool=./build/deps/signtool/signtool.exe sign /debug $p\"", @@ -155,8 +155,7 @@ "build/backend/service/logger/loki-transport.js", "node_modules/sqlite3/**/*.node", "node_modules/oracledb/**/*.node", - "node_modules/better-sqlite3/build/Release/better_sqlite3.node", - "src/config/default-config.json" + "node_modules/better-sqlite3/build/Release/better_sqlite3.node" ] } } diff --git a/src/engine/history-query-engine.spec.js b/src/engine/history-query-engine.spec.js index 667d8c47a3..bf690ed462 100644 --- a/src/engine/history-query-engine.spec.js +++ b/src/engine/history-query-engine.spec.js @@ -1,5 +1,5 @@ import HistoryQueryEngine from './history-query-engine.js' -import config from '../config/default-config.json' +import { testConfig } from '../../tests/test-config.js' import ConfigurationService from '../service/configuration.service.js' // Mock fs @@ -30,8 +30,8 @@ describe('HistoryQueryEngine', () => { const mockConfigService = { getConfig: jest.fn() } mockConfigService.getConfig.mockReturnValue({ - engineConfig: config.engine, - southConfig: config.south, + engineConfig: testConfig.engine, + southConfig: testConfig.south, }) ConfigurationService.mockImplementation(() => mockConfigService) @@ -41,12 +41,12 @@ describe('HistoryQueryEngine', () => { }) it('should be properly initialized', async () => { - await engine.initEngineServices(config.engine) + await engine.initEngineServices(testConfig.engine) expect(engine.historyOnGoing).toBeFalsy() }) it('should add values', async () => { - await engine.initEngineServices(config.engine) + await engine.initEngineServices(testConfig.engine) const sampleValues = [ { diff --git a/src/engine/oibus-engine.spec.js b/src/engine/oibus-engine.spec.js index 9c27715cd1..709f96ecaa 100644 --- a/src/engine/oibus-engine.spec.js +++ b/src/engine/oibus-engine.spec.js @@ -1,6 +1,6 @@ import OIBusEngine from './oibus-engine.js' import EncryptionService from '../service/encryption.service.js' -import config from '../config/default-config.json' +import { testConfig } from '../../tests/test-config.js' import ConfigurationService from '../service/configuration.service.js' // Mock EncryptionService @@ -32,15 +32,15 @@ describe('OIBusEngine', () => { const mockConfigService = { getConfig: jest.fn() } mockConfigService.getConfig.mockReturnValue({ - engineConfig: config.engine, - southConfig: config.south, + engineConfig: testConfig.engine, + southConfig: testConfig.south, }) ConfigurationService.mockImplementation(() => mockConfigService) const mockLoggerService = { createChildLogger: jest.fn(() => logger) } engine = new OIBusEngine(mockConfigService, {}, mockLoggerService) - await engine.initEngineServices(config.engine) + await engine.initEngineServices(testConfig.engine) }) it('should be properly initialized', () => { diff --git a/src/frontend/favicon.ico b/src/frontend/favicon.ico index 5ca26dec11fc065845134c9d22a805b60b34ce7e..21fb7031672083d0462ad5d127af4e3868d96dca 100644 GIT binary patch literal 19102 zcmeI4F^E=25XWC2jYS}7QdkK#Vjx-wrVx^#B3KznDIt*3#!|4ci(ru=Wr{$`fCN%n zn8L!sA}K6v2WhNIn%kF~=EJ6GPAusBf^IK}cFO5XO>_L?J!%^kzmh3`y-exbt(}%WeYBkp zE1@I0LVacH#culg@lH$4y;te55;~$Ql{G4z+t3R&5v8pX?;4g#KQ3z2ADelb|8p{dbL5U9k`nsXc>%hsR9s%lL@mBlC_e zzyG^;4%XVJrhROo@07Ue=M_)s?(3;oAPX`L=>T8$gfaU9bE+@naz%KI!Nku~5)0wr zd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W8<7zJnf0V=9o;o zJ{LKkTS2$NEd0O`c`Dc?9)T_Vz^>y9k6!%_-^JI}b@g29oNRO|FN|GmSk7^%rAnYm bph}=hph}=hph}=hph}=hph}=hAV}bUtgq} - The result promise */ async init() { - let tempConfig - try { - tempConfig = await fs.readFile(this.configFilePath, 'utf8') - } catch (err) { - tempConfig = await fs.readFile(`${__dirname}/../config/default-config.json`, 'utf8') + let config + if (await filesExists(this.configFilePath)) { + config = JSON.parse(await fs.readFile(this.configFilePath, { encoding: 'utf8' })) + } else { + config = defaultConfig } + const previousConfig = JSON.stringify(config) // When a specific config is used with unencrypted secrets, it allows to encrypt credentials and update the config. // In this case, no backup is used to avoid plain text secrets // This can happen after a fresh installation with a config file edited by the user or an installation script - await this.updateConfig(JSON.parse(tempConfig)) + await this.updateConfig(config) - if (JSON.stringify(this.modifiedConfig) !== tempConfig) { + if (JSON.stringify(this.modifiedConfig) !== previousConfig) { await this.activateConfiguration(false) } else { this.config = this.modifiedConfig @@ -77,19 +79,19 @@ export default class ConfigurationService { /** * Update configuration and encrypt password and secrets - * @param {Object} config - The updated configuration + * @param {Object} newConfig - The updated configuration * @returns {Promise} - The result promise */ - async updateConfig(config) { - await this.encryptionService.encryptSecrets(config.engine) + async updateConfig(newConfig) { + await this.encryptionService.encryptSecrets(newConfig.engine) - await config.north.reduce((promise, north) => promise.then( + await newConfig.north.reduce((promise, north) => promise.then( async () => this.encryptionService.encryptSecrets(north), ), Promise.resolve()) - await config.south.reduce((promise, south) => promise.then( + await newConfig.south.reduce((promise, south) => promise.then( async () => this.encryptionService.encryptSecrets(south), ), Promise.resolve()) - this.modifiedConfig = config + this.modifiedConfig = newConfig } /** @@ -110,9 +112,9 @@ export default class ConfigurationService { this.config = JSON.parse(JSON.stringify(this.modifiedConfig)) } - async removeOrphanCacheFolders(config) { - const northIdList = config.north.map((north) => north.id) - const southIdList = config.south.map((south) => south.id) + async removeOrphanCacheFolders(newConfig) { + const northIdList = newConfig.north.map((north) => north.id) + const southIdList = newConfig.south.map((south) => south.id) const idList = [...northIdList, ...southIdList] const dataStreamFolderPath = path.resolve(this.cacheFolder, 'data-stream') diff --git a/src/service/configuration.service.spec.js b/src/service/configuration.service.spec.js index 2601233d2b..c3cbbfbf17 100644 --- a/src/service/configuration.service.spec.js +++ b/src/service/configuration.service.spec.js @@ -1,5 +1,6 @@ import fs from 'node:fs/promises' import path from 'node:path' +import defaultConfig from '../config/default-config.json' import * as utils from './utils.js' @@ -26,28 +27,19 @@ describe('Configuration service', () => { }) it('should properly initialized service with default conf', async () => { - const mockConf = { - engine: 'myEngineConfig', - north: [{ id: 'myNorthConfig' }], - south: [{ id: 'mySouthConfig' }], - } - fs.readFile.mockImplementationOnce(() => { - throw new Error('file does not exist') - }).mockImplementationOnce(() => (JSON.stringify(mockConf))) + utils.filesExists.mockImplementation(() => false) service.activateConfiguration = jest.fn() await service.init() - expect(fs.readFile).toHaveBeenCalledTimes(2) - expect(fs.readFile).toHaveBeenCalledWith(path.resolve(configFilePath), 'utf8') - expect(fs.readFile).toHaveBeenCalledWith(`${__dirname}/../config/default-config.json`, 'utf8') - expect(fs.copyFile).not.toHaveBeenCalled() + expect(fs.readFile).not.toHaveBeenCalled() expect(service.activateConfiguration).not.toHaveBeenCalled() - expect(service.config).toEqual(mockConf) - expect(service.modifiedConfig).toEqual(mockConf) + expect(service.config).toEqual(defaultConfig) + expect(service.modifiedConfig).toEqual(defaultConfig) }) it('should properly initialized service with config file', async () => { + utils.filesExists.mockImplementation(() => true) const mockConf = { engine: { name: 'myEngineConfig' }, north: [{ id: 'myNorthConfig' }], @@ -62,8 +54,7 @@ describe('Configuration service', () => { await service.init() expect(fs.readFile).toHaveBeenCalledTimes(1) - expect(fs.readFile).toHaveBeenCalledWith(path.resolve(configFilePath), 'utf8') - expect(fs.copyFile).not.toHaveBeenCalled() + expect(fs.readFile).toHaveBeenCalledWith(path.resolve(configFilePath), { encoding: 'utf8' }) expect(service.activateConfiguration).toHaveBeenCalledTimes(1) expect(service.modifiedConfig).toEqual({ engine: { name: 'myEngineConfig', encryptedPassword: 'encryptedPassword' }, diff --git a/tsconfig.json b/tsconfig.json index d832721638..174fc94552 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, + "resolveJsonModule": true, "target": "es5", "outDir": "./build/backend" },