Skip to content

Commit

Permalink
Migrate to npm workspaces (#1394)
Browse files Browse the repository at this point in the history
* Migrate to npm workspaces

Signed-off-by: CaptainIRS <36656347+CaptainIRS@users.noreply.github.com>

* Address review comments

* Fix npm version in GitHub Actions

Signed-off-by: CaptainIRS <36656347+CaptainIRS@users.noreply.github.com>

* Address review comments

* Define NPM version once in workflow
* Add script for checking prerequisites

Signed-off-by: CaptainIRS <36656347+CaptainIRS@users.noreply.github.com>
  • Loading branch information
CaptainIRS committed Jul 22, 2022
1 parent dd5c85c commit c29fc0f
Show file tree
Hide file tree
Showing 14 changed files with 62,094 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .build/benchmark-integration-test-direct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -e
set -o pipefail

# Bootstrap the project again
npm i && npm run repoclean -- --yes && npm run bootstrap
npm ci

# Get the root directory of the caliper source
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
Expand Down
58 changes: 58 additions & 0 deletions .build/check-prerequisites.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .build/checks-and-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ set -o pipefail
./scripts/check-package-names.sh

# Bootstrap the project again
npm i && npm run repoclean -- --yes && npm run bootstrap
npm ci

pushd ./packages/caliper-publish/
./publish.js version check
popd

# Run linting, license check and unit tests
npm test
npm run test --workspaces
2 changes: 1 addition & 1 deletion .build/publish-caliper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ cp ./README.md ./packages/caliper-fabric/README.md
cp ./README.md ./packages/caliper-fisco-bcos/README.md

cd ./packages/caliper-publish/
npm i
npm ci
./publish.js npm
./publish.js docker --publish
13 changes: 13 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Integration Tests
on:
workflow_call:

env:
NPM_VERSION: 8.15.0

jobs:
fabric-integration-tests:
name: Fabric Integration Tests
Expand All @@ -16,6 +19,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
run: npm install -g npm@${{ env.NPM_VERSION }}
- name: Fabric Integration Test
run: .build/benchmark-integration-test-direct.sh
env:
Expand All @@ -33,6 +38,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
run: npm install -g npm@${{ env.NPM_VERSION }}
- name: Ethereum Integration Test
run: .build/benchmark-integration-test-direct.sh
env:
Expand All @@ -50,6 +57,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
run: npm install -g npm@${{ env.NPM_VERSION }}
- name: Besu Integration Test
run: .build/benchmark-integration-test-direct.sh
env:
Expand All @@ -67,6 +76,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
run: npm install -g npm@${{ env.NPM_VERSION }}
- name: FISCO BCOS Integration Test
run: .build/benchmark-integration-test-direct.sh
env:
Expand All @@ -84,6 +95,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
run: npm install -g npm@${{ env.NPM_VERSION }}
- name: Generator Integration Test
run: .build/benchmark-integration-test-direct.sh
env:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Unit Tests
on:
workflow_call:

env:
NPM_VERSION: 8.15.0

jobs:
unit-tests:
name: Unit Tests
Expand All @@ -16,13 +19,13 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install higher version of NPM
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
run: npm install
- name: Bootstrap lerna
run: npm run bootstrap
run: npm ci
- name: Check the version consistency of subpackages
run: ./packages/caliper-publish/publish.js version check
- name: Run unit tests
run: npm test
run: npm test --workspaces
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ architecture.pptx
output.log
lerna-debug.log

**/package-lock.json

.idea/
**/node_modules/
**/log/
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ You can find the following main component types at the root of the repository:
* [.build/](.build/)
* [scripts/](scripts/)
* [azure-pipelines.yml](azure-pipelines.yml)
* [lerna.json](lerna.json)
* [package.json](package.json)
* Main code-based components of Caliper in the [packages/](packages/) directory

Expand Down
21 changes: 0 additions & 21 deletions lerna.json

This file was deleted.

0 comments on commit c29fc0f

Please sign in to comment.