Skip to content

Commit

Permalink
upgrade dependencies, drop Node.js 12 (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Aug 28, 2022
1 parent 9f1f8dc commit 1860356
Show file tree
Hide file tree
Showing 17 changed files with 474 additions and 648 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ indent_size = 4
[*.{yml,md}]
indent_style = space
indent_size = 4

[.github/workflows/*.yml]
indent_style = space
indent_size = 2
209 changes: 109 additions & 100 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,114 @@ name: Test and Release
# Run this job on all pushes and pull requests
# as well as tags with a semantic version
on:
push:
branches:
- "*"
tags:
# normal versions
- "v[0-9]+.[0-9]+.[0-9]+"
# pre-releases
- "v[0-9]+.[0-9]+.[0-9]+-**"
pull_request: {}
push:
branches:
- "*"
tags:
# normal versions
- "v[0-9]+.[0-9]+.[0-9]+"
# pre-releases
- "v[0-9]+.[0-9]+.[0-9]+-**"
pull_request: {}

jobs:
# Performs quick checks before the expensive test runs
check-and-lint:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Perform a type check
run: npm run check
env:
CI: true

- name: Lint TypeScript code
run: npm run lint

# ===================

# Runs unit tests on all supported node versions and OSes
unit-tests:
if: contains(github.event.head_commit.message, '[skip ci]') == false

needs: [check-and-lint]

runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Run component tests
run: npm run test
env:
CI: true

# ===================

# Deploys the final package to NPM
deploy:
# Trigger this step only when a commit on master is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
needs: [unit-tests]

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Create a clean build
run: npm run build

- name: Publish package to npm
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm whoami
npm publish
# Performs quick checks before the expensive test runs
check-and-lint:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x] # This should be LTS

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Perform a type check
run: npm run check
env:
CI: true

- name: Lint TypeScript code
run: npm run lint

# ===================

# Runs unit tests on all supported node versions and OSes
unit-tests:
if: contains(github.event.head_commit.message, '[skip ci]') == false

needs: [check-and-lint]

runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run component tests
run: npm run test
env:
CI: true

# ===================

# Deploys the final package to NPM
deploy:
# Trigger this step only when a commit on master is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
needs: [unit-tests]

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x] # This should be LTS

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Create a clean build
run: npm run build

- name: Publish package to npm
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm whoami
npm publish
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ module.exports = {
useTabs: true,
tabWidth: 4,
endOfLine: "lf",

overrides: [
{
files: ".github/workflows/*.yml",
options: {
useTabs: false,
tabWidth: 2,
},
},
],
};
4 changes: 2 additions & 2 deletions build/lib/executeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function executeCommand(command, argsOrOptions, options) {
let bufferedStderr;
const cmd = (0, child_process_1.spawn)(command, args, spawnOptions).on("close", (code, signal) => {
resolve({
exitCode: code !== null && code !== void 0 ? code : undefined,
signal: signal !== null && signal !== void 0 ? signal : undefined,
exitCode: code ?? undefined,
signal: signal ?? undefined,
stdout: bufferedStdout,
stderr: bufferedStderr,
});
Expand Down
11 changes: 4 additions & 7 deletions build/tests/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function testAdapter(adapterDir, options = {}) {
console.log(`Running tests in ${testDir}`);
console.log();
async function prepareTests() {
var _a;
// Installation may take a while - especially if rsa-compat needs to be installed
const oneMinute = 60000;
this.timeout(30 * oneMinute);
Expand All @@ -63,7 +62,7 @@ function testAdapter(adapterDir, options = {}) {
// Only then we can install the adapter, because some (including VIS) try to access
// the databases if JS Controller is installed
await adapterSetup.installAdapterInTestDir();
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug"));
await dbConnection.start();
controllerSetup.setupSystemConfig(dbConnection);
await controllerSetup.disableAdminInstances(dbConnection);
Expand All @@ -82,9 +81,8 @@ function testAdapter(adapterDir, options = {}) {
harness.removeAllListeners();
}
async function resetDbAndStartHarness() {
var _a, _b;
this.timeout(30000);
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)(options.loglevel ?? "debug"));
// Clean up before every single test
await Promise.all([
controllerSetup.clearDBDir(),
Expand All @@ -98,7 +96,7 @@ function testAdapter(adapterDir, options = {}) {
await harness.changeAdapterConfig(adapterName, {
common: {
enabled: true,
loglevel: (_b = options.loglevel) !== null && _b !== void 0 ? _b : "debug",
loglevel: options.loglevel ?? "debug",
},
});
// And enable the sendTo emulation
Expand All @@ -110,9 +108,8 @@ function testAdapter(adapterDir, options = {}) {
beforeEach(resetDbAndStartHarness);
afterEach(shutdownTests);
it("The adapter starts", function () {
var _a;
this.timeout(60000);
const allowedExitCodes = new Set((_a = options.allowedExitCodes) !== null && _a !== void 0 ? _a : []);
const allowedExitCodes = new Set(options.allowedExitCodes ?? []);
// Adapters with these modes are allowed to "immediately" exit with code 0
switch (harness.getAdapterExecutionMode()) {
case "schedule":
Expand Down
2 changes: 2 additions & 0 deletions build/tests/integration/lib/dbConnection.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="iobroker" />
/// <reference types="iobroker" />
/// <reference types="node" />
/// <reference types="node" />
import EventEmitter from "events";
export declare type ObjectsDB = Record<string, ioBroker.Object>;
Expand Down
19 changes: 8 additions & 11 deletions build/tests/integration/lib/dbConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,16 @@ class DBConnection extends events_1.default {
debug("DB instances started");
}
async stop() {
var _a, _b, _c, _d;
if (!this._isRunning) {
debug("No DB instance is running, nothing to stop...");
return;
}
debug("Stopping DB instances...");
// Stop clients before servers
await ((_a = this._objectsClient) === null || _a === void 0 ? void 0 : _a.destroy());
await ((_b = this._objectsServer) === null || _b === void 0 ? void 0 : _b.destroy());
await ((_c = this._statesClient) === null || _c === void 0 ? void 0 : _c.destroy());
await ((_d = this._statesServer) === null || _d === void 0 ? void 0 : _d.destroy());
await this._objectsClient?.destroy();
await this._objectsServer?.destroy();
await this._statesClient?.destroy();
await this._statesServer?.destroy();
this._objectsClient = null;
this._objectsServer = null;
this._statesClient = null;
Expand Down Expand Up @@ -279,20 +278,18 @@ class DBConnection extends events_1.default {
this._statesClient.pushMessage(instanceId, msg, callback);
}
async getStateIDs(pattern = "*") {
var _a, _b, _c, _d;
if (!this._statesClient) {
throw new Error("States DB is not running");
}
return (((_b = (_a = this._statesClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) ||
((_d = (_c = this._statesClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern)));
return (this._statesClient.getKeysAsync?.(pattern) ||
this._statesClient.getKeys?.(pattern));
}
async getObjectIDs(pattern = "*") {
var _a, _b, _c, _d;
if (!this._objectsClient) {
throw new Error("Objects DB is not running");
}
return (((_b = (_a = this._objectsClient).getKeysAsync) === null || _b === void 0 ? void 0 : _b.call(_a, pattern)) ||
((_d = (_c = this._objectsClient).getKeys) === null || _d === void 0 ? void 0 : _d.call(_c, pattern)));
return (this._objectsClient.getKeysAsync?.(pattern) ||
this._objectsClient.getKeys?.(pattern));
}
}
exports.DBConnection = DBConnection;
3 changes: 3 additions & 0 deletions build/tests/integration/lib/harness.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// <reference types="iobroker" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="iobroker" />
/// <reference types="node" />
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import type { DBConnection } from "./dbConnection";
Expand Down
3 changes: 1 addition & 2 deletions build/tests/integration/lib/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class TestHarness extends events_1.EventEmitter {
if (!this.isAdapterRunning())
return;
return new Promise(async (resolve) => {
var _a;
const onClose = (code, signal) => {
if (!this._adapterProcess)
return;
Expand All @@ -214,7 +213,7 @@ class TestHarness extends events_1.EventEmitter {
}
catch {
// DB connection may be closed already, kill the process
(_a = this._adapterProcess) === null || _a === void 0 ? void 0 : _a.kill("SIGTERM");
this._adapterProcess?.kill("SIGTERM");
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions build/tests/integration/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ var LoglevelOrder;
LoglevelOrder[LoglevelOrder["silly"] = 4] = "silly";
})(LoglevelOrder || (LoglevelOrder = {}));
function createLogger(loglevel) {
var _a;
const loglevelNumeric = (_a = LoglevelOrder[loglevel !== null && loglevel !== void 0 ? loglevel : "debug"]) !== null && _a !== void 0 ? _a : LoglevelOrder.debug;
const loglevelNumeric = LoglevelOrder[loglevel ?? "debug"] ?? LoglevelOrder.debug;
// eslint-disable-next-line @typescript-eslint/no-empty-function
const ignore = () => { };
return {
Expand Down
Loading

0 comments on commit 1860356

Please sign in to comment.