From d53a25e7ca8473fb5a6a84582535615b791a2b0d Mon Sep 17 00:00:00 2001 From: CaptainIRS <36656347+CaptainIRS@users.noreply.github.com> Date: Fri, 22 Jul 2022 15:35:55 +0530 Subject: [PATCH] Address review comments * Define NPM version once in workflow * Add script for checking prerequisites Signed-off-by: CaptainIRS <36656347+CaptainIRS@users.noreply.github.com> --- .build/check-prerequisites.sh | 58 +++++++++++++++++++++++++ .github/workflows/integration-tests.yml | 13 +++--- .github/workflows/unit-tests.yml | 5 ++- 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100755 .build/check-prerequisites.sh diff --git a/.build/check-prerequisites.sh b/.build/check-prerequisites.sh new file mode 100755 index 000000000..95dcf9e47 --- /dev/null +++ b/.build/check-prerequisites.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Exit on first error, print all commands. +set -e +set -o pipefail + +CLEAR="$(tput sgr0)" +RED="$(tput setaf 1)" +GREEN="$(tput setaf 2)" + +check_npm_version() { + required_version="7.24.2" + installed_version=$(npm --version) + versions="$required_version\n$installed_version" + if echo -e $versions | sort -rV | head -n 1 | grep -q "$installed_version"; then + echo "$GREEN npm version $installed_version is >= $required_version $CLEAR" + return 0 + else + echo "$RED npm version $installed_version < $required_version $CLEAR" + echo "$RED Please update npm to the latest version: https://docs.npmjs.com/try-the-latest-stable-version-of-npm $CLEAR" + return 1 + fi +} + +check_node_version() { + required_version="14.19.0" + installed_version=$(node --version | cut -c2-) + versions="$required_version\n$installed_version" + if echo -e $versions | sort -rV | head -n 1 | grep -q "$installed_version"; then + echo "$GREEN node version $installed_version is >= $required_version $CLEAR" + return 0 + else + echo "$RED node version $installed_version < $required_version $CLEAR" + echo "$RED Please update node to the latest version: https://nodejs.org/en/download/ $CLEAR" + return 1 + fi +} + +check_node_version +rc=$? +check_npm_version +rc=$?||$rc +if [ $rc -ne 0 ]; then + exit $rc +fi diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 6f40d8b13..0eed54981 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -3,6 +3,9 @@ name: Integration Tests on: workflow_call: +env: + NPM_VERSION: 8.15.0 + jobs: fabric-integration-tests: name: Fabric Integration Tests @@ -17,7 +20,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: Fabric Integration Test run: .build/benchmark-integration-test-direct.sh env: @@ -36,7 +39,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: Ethereum Integration Test run: .build/benchmark-integration-test-direct.sh env: @@ -55,7 +58,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: Besu Integration Test run: .build/benchmark-integration-test-direct.sh env: @@ -74,7 +77,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: FISCO BCOS Integration Test run: .build/benchmark-integration-test-direct.sh env: @@ -93,7 +96,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: Generator Integration Test run: .build/benchmark-integration-test-direct.sh env: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index cc75f2237..3d3f76655 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -3,6 +3,9 @@ name: Unit Tests on: workflow_call: +env: + NPM_VERSION: 8.15.0 + jobs: unit-tests: name: Unit Tests @@ -17,7 +20,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: Install higher version of NPM - run: npm install -g npm@8.15.0 + run: npm install -g npm@${{ env.NPM_VERSION }} - name: Check correct usage of Caliper package names run: ./scripts/check-package-names.sh - name: Install project dependencies