Skip to content

Commit

Permalink
fix(ci): do not copy useless file in win/bin and fix config path
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 authored and Nicolas Burger committed Dec 14, 2022
1 parent 0ee300d commit 5a56bde
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup_environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'] }}
Expand Down
6 changes: 3 additions & 3 deletions build/deps/linux/oibus-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
Binary file removed build/deps/win/favicon.ico
Binary file not shown.
15 changes: 7 additions & 8 deletions build/deps/win/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down Expand Up @@ -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"
]
}
}
10 changes: 5 additions & 5 deletions src/engine/history-query-engine.spec.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 = [
{
Expand Down
8 changes: 4 additions & 4 deletions src/engine/oibus-engine.spec.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down
Binary file modified src/frontend/favicon.ico
Binary file not shown.
34 changes: 18 additions & 16 deletions src/service/configuration.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'node:fs/promises'

import EncryptionService from './encryption.service.js'
import { filesExists } from './utils.js'
import defaultConfig from '../config/default-config.json'

const KEYS_FOLDER = './keys'
const CERTS_FOLDER = './certs'
Expand Down Expand Up @@ -36,19 +37,20 @@ export default class ConfigurationService {
* @returns {Promise<void>} - 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
Expand Down Expand Up @@ -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<void>} - 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
}

/**
Expand All @@ -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')
Expand Down
23 changes: 7 additions & 16 deletions src/service/configuration.service.spec.js
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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' }],
Expand All @@ -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' },
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"target": "es5",
"outDir": "./build/backend"
},
Expand Down

0 comments on commit 5a56bde

Please sign in to comment.