From 783a899be9a0c39d6331fc0a84e1203c7c75d9de Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik <48479610+alwa-nordic@users.noreply.github.com> Date: Mon, 1 Jul 2019 15:25:48 +0200 Subject: [PATCH] Release/v2.6 (#227) * Bump version to 2.6.0 * Make Azure publish artifacts once after all building on a platform The Github publishing action in Azure frequently fails. This reduces the number of failure points, increasing the chance of completion. * The system test now completes all tests before reporting failure * Accommodate Connectivity version info struct location change * Add build.js for forwarding node-gyp config to cmake-js * Update README on npm_config_runtime --- README.md | 5 +- .../firmwareRegistry-test.js.snap | 6 +++ api/firmwareRegistry.js | 5 +- azure-node.yml | 20 ++------ azure-pipelines.yml | 13 +++++ build.js | 51 +++++++++++++++++++ package.json | 4 +- scripts/system-tests.sh | 13 ++++- 8 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 build.js diff --git a/README.md b/README.md index 1692bb76..1548e588 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,12 @@ The install script will try to download precompiled binaries for your platform/r ### Installing in Electron apps -If you want to use pc-ble-driver-js with the electron runtime, you must set the runtime to Electron in .npmrc in the root of your project. Then install pc-ble-driver-js again. Example .npmrc file content: +To use this project with Electron, the environment variables `npm_config_runtime` and `npm_config_target` must be set for `npm install`. The variables should be "`Electron`" and the Electron version, respectivly. + +These variables can be set in `.npmrc` file in the root of your Electron based project. Example .npmrc file content: runtime = Electron target = 1.16.6 - disturl = https://atom.io/download/atom-shell ## Building diff --git a/api/__tests__/__snapshots__/firmwareRegistry-test.js.snap b/api/__tests__/__snapshots__/firmwareRegistry-test.js.snap index 78647211..171082e7 100644 --- a/api/__tests__/__snapshots__/firmwareRegistry-test.js.snap +++ b/api/__tests__/__snapshots__/firmwareRegistry-test.js.snap @@ -6,6 +6,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s130_2.0.1.hex", "sdBleApiVersion": 2, "version": "4.1.1", + "versionInfoStart": 233472, } `; @@ -15,6 +16,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s130_2.0.1.hex", "sdBleApiVersion": 2, "version": "4.1.1", + "versionInfoStart": 233472, } `; @@ -24,6 +26,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s130_2.0.1.hex", "sdBleApiVersion": 2, "version": "4.1.1", + "versionInfoStart": 233472, } `; @@ -33,6 +36,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s132_3.1.0.hex", "sdBleApiVersion": 3, "version": "4.1.1", + "versionInfoStart": 327680, } `; @@ -42,6 +46,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s132_3.1.0.hex", "sdBleApiVersion": 3, "version": "4.1.1", + "versionInfoStart": 327680, } `; @@ -51,6 +56,7 @@ Object { "file": "/build/Release/pc-ble-driver/hex/connectivity_4.1.1_1m_with_s132_3.1.0.hex", "sdBleApiVersion": 3, "version": "4.1.1", + "versionInfoStart": 327680, } `; diff --git a/api/firmwareRegistry.js b/api/firmwareRegistry.js index 14053588..7ffbffe8 100644 --- a/api/firmwareRegistry.js +++ b/api/firmwareRegistry.js @@ -44,7 +44,6 @@ const currentDir = require.resolve('./firmwareRegistry'); const hexDir = path.join(currentDir, '..', '..', 'build', 'Release', 'pc-ble-driver', 'hex'); const VERSION_INFO_MAGIC = 0x46D8A517; -const VERSION_INFO_START = 0x20000; const VERSION_INFO_LENGTH = 24; const connectivityVersion = '4.1.1'; @@ -67,12 +66,14 @@ function getFirmwareMap(platform) { version: connectivityVersion, baudRate: connectivityBaudRate, sdBleApiVersion: 2, + versionInfoStart: 0x39000, }, nrf52: { file: path.join(hexDir, `connectivity_${connectivityVersion}_1m_with_s132_3.1.0.hex`), version: connectivityVersion, baudRate: connectivityBaudRate, sdBleApiVersion: 3, + versionInfoStart: 0x50000, }, }, nordicUsb: { @@ -181,7 +182,7 @@ class FirmwareRegistry { parsedData.baudRate === deviceConfig.baudRate; }, }, - fwIdAddress: VERSION_INFO_START, + fwIdAddress: deviceConfig.versionInfoStart, }, }); }); diff --git a/azure-node.yml b/azure-node.yml index 3474ac67..b39b1168 100644 --- a/azure-node.yml +++ b/azure-node.yml @@ -29,9 +29,7 @@ steps: displayName: 'Setup Node.js on Windows 32-bit' - bash: | - npm c set cmake_js_runtime "${{ parameters.npmConfigRuntime }}" - npm c set cmake_js_runtime-version "${{ parameters.npmConfigTarget }}" - npm i --build-from-source + npm install --build-from-source npm run package-prebuilt --verbose env: { npm_config_runtime: '${{ parameters.npmConfigRuntime }}', @@ -43,17 +41,7 @@ steps: npm test displayName: 'Integration test' + # Stage artefacts for release draft. - bash: | - cp build/stage/**/*.tar.gz "$(Build.ArtifactStagingDirectory)" - displayName: 'Copy artifacts' -- task: GitHubRelease@0 - inputs: - gitHubConnection: 'waylandCI' - repositoryName: 'NordicSemiconductor/pc-ble-driver-js' - action: 'edit' - tagSource: 'Git tag' - tag: '$(Build.SourceBranchName)' - assetUploadMode: 'replace' - isDraft: 'true' - addChangeLog: 'false' - condition: ne(variables['Build.Reason'], 'PullRequest') + cp -n build/stage/**/*.tar.gz "$(Build.ArtifactStagingDirectory)" + displayName: 'Stage artifacts' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b0f8ec8d..9ee8ab3a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -96,6 +96,19 @@ jobs: npmConfigRuntime: 'electron' npmConfigTarget: 4.1.4 + # Relese draft of artefacts in $(Build.ArtifactStagingDirectory). + - task: GitHubRelease@0 + inputs: + gitHubConnection: 'waylandCI' + repositoryName: 'NordicSemiconductor/pc-ble-driver-js' + action: 'edit' + tagSource: 'Git tag' + tag: '$(Build.SourceBranchName)' + assetUploadMode: 'replace' + isDraft: 'true' + addChangeLog: 'false' + condition: ne(variables['Build.Reason'], 'PullRequest') + - job: Test dependsOn: [ Build, diff --git a/build.js b/build.js new file mode 100644 index 00000000..fcc28971 --- /dev/null +++ b/build.js @@ -0,0 +1,51 @@ +/* Copyright (c) 2019, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Wrapper script for cmake-js. Translates and forwards npm config options +// understood by node-gyp. This script is needed because pc-nrfconnect-core +// supplies config for only node-gyp. +require('child_process').execFileSync(process.platform === 'win32' ? 'npx.cmd' : 'npx', [ + 'cmake-js', + // The CMake target install copies .node C++ Addons to location expected by node-pre-gyp. + '--target', 'install', + // Translate npm config options understood by node-gyp to cmake-js. + ...('npm_config_runtime' in process.env ? ['--runtime', process.env.npm_config_runtime] : []), + ...('npm_config_target' in process.env ? ['--runtime-version', process.env.npm_config_target] : []), + // Allow supplying options from command line. Note that cmake-js does not + // allow overriding previously provided arguments, but will instead join + // the values with a comma. + ...process.argv.slice(2), +], { stdio: 'inherit' }); diff --git a/package.json b/package.json index 7582f189..52a9a9b3 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "pc-ble-driver-js", - "version": "2.5.1", + "version": "2.6.0", "description": "Javascript bindings for pc-ble-driver", "main": "index.js", "scripts": { - "build": "cmake-js --target install", + "build": "node build.js", "lint": "jshint api/ test/ && jscs api/ test/", "deploy-docs": "gh-pages -d docs", "clean-prebuilt": "node-pre-gyp clean", diff --git a/scripts/system-tests.sh b/scripts/system-tests.sh index 4c5bad2b..66550480 100644 --- a/scripts/system-tests.sh +++ b/scripts/system-tests.sh @@ -12,6 +12,8 @@ export BLE_DRIVER_TEST_OPENCLOSE_ITERATIONS=5 export BLE_DRIVER_TEST_LOGLEVEL="trace" export DEBUG="ble-driver:*" +global_failure=0 + for pca in "${test_pcas[@]}"; do serial_numbers=($(npx nrf-device-lister -S "$pca")) export DEVICE_A_SERIAL_NUMBER="${serial_numbers[0]}" @@ -20,7 +22,11 @@ for pca in "${test_pcas[@]}"; do function run_test { echo "Running test using PCA: $pca, serial number" \ "A: $DEVICE_A_SERIAL_NUMBER B: $DEVICE_B_SERIAL_NUMBER" - npx jest --detectOpenHandles --forceExit "$@" + npx jest --detectOpenHandles --forceExit "$@" || { + echo "======== TEST FAILURE ======== (exit code: $?)" + global_failure=1 + # Don't exit on failure. Continue with next test. + } } # Run each tests in a new Jest instance. Sheduling more in @@ -38,3 +44,8 @@ for pca in "${test_pcas[@]}"; do run_test simpleSecurity.test.js -t LESCOOB run_test openClose.test.js done + +if [ "$global_failure" != 0 ]; then + echo "End of tests. One or more tests failed." + exit 1 +fi