Skip to content

Commit

Permalink
chore(mojaloop/#3504): nodejs upgrade (#46)
Browse files Browse the repository at this point in the history
chore(mojaloop/#3504): nodejs upgrade (#46) - mojaloop/project#3504
- Upgraded NodeJS from v16 to v18 LTS
- Updated CI config to use NodeJS latest LTS version
- Updated CI config to display runtime versions for each job
- Upgraded NPM dependencies
- Upgraded circleci orbs
- Removed SonarQube
- Replaced audit resolver with `audit-ci`
- Migrated from `master` branch to `main` branch
  • Loading branch information
kleyow authored Sep 4, 2023
1 parent 64766a2 commit b4bb05b
Show file tree
Hide file tree
Showing 7 changed files with 6,547 additions and 4,562 deletions.
173 changes: 124 additions & 49 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@ version: 2.1
# Orbs used in this pipeline
##
orbs:
slack: circleci/slack@4.9.3 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
slack: circleci/slack@4.12.5 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
pr-tools: mojaloop/[email protected] # Ref: https://github.com/mojaloop/ci-config/
gh: circleci/github-cli@2.1.0
gh: circleci/github-cli@2.2.0

##
# defaults
#
# YAML defaults templates, in alphabetical order
##
defaults_Dependencies: &defaults_Dependencies |
defaults_docker_Dependencies: &defaults_docker_Dependencies |
apk --no-cache add bash
apk --no-cache add git
apk --no-cache add ca-certificates
apk --no-cache add curl
apk --no-cache add openssh-client
apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake jq
apk add --no-cache -t openssl ncurses coreutils libgcc linux-headers grep util-linux binutils findutils
npm config set unsafe-perm true
npm install -g node-gyp

defaults_awsCliDependencies: &defaults_awsCliDependencies |
apk --no-cache add aws-cli
Expand All @@ -51,7 +49,7 @@ defaults_npm_publish_release: &defaults_npm_publish_release
defaults_export_version_from_package: &defaults_export_version_from_package
name: Format the changelog into the github release body and get release tag
command: |
git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
git diff --no-indent-heuristic main~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV
Expand All @@ -64,14 +62,66 @@ defaults_configure_git: &defaults_configure_git
defaults_configure_nvm: &defaults_configure_nvm
name: Configure NVM
command: |
touch $HOME/.profile
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "Installing Node version: $(cat .nvmrc)"
nvm install $(cat .nvmrc)
nvm alias default $(cat .nvmrc)
nvm use $(cat .nvmrc)
cd $HOME
export ENV_DOT_PROFILE=$HOME/.profile
touch $ENV_DOT_PROFILE
echo "1. Check/Set NVM_DIR env variable"
if [ -z "$NVM_DIR" ]; then
export NVM_DIR="$HOME/.nvm"
echo "==> NVM_DIR has been exported - $NVM_DIR"
else
echo "==> NVM_DIR already exists - $NVM_DIR"
fi
echo "2. Check/Set NVMRC_VERSION env variable"
if [ -z "$NVMRC_VERSION" ]; then
echo "==> Configuring NVMRC_VERSION!"
export NVMRC_VERSION=$(cat $CIRCLE_WORKING_DIRECTORY/.nvmrc)
echo "export NVMRC_VERSION=$NVMRC_VERSION" >> $ENV_DOT_PROFILE
fi
echo "3. Configure NVM"
## Lets check if an existing NVM_DIR exists, if it does lets skil
if [ -e "$NVM_DIR" ]; then
echo "==> $NVM_DIR exists. Skipping steps 3!"
# echo "5. Executing $NVM_DIR/nvm.sh"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
else
echo "==> $NVM_DIR does not exists. Executing steps 4-5!"
echo "4. Installing NVM"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
echo "5. Executing $NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
## Ref: https://github.com/nvm-sh/nvm/issues/1102#issuecomment-550572252
if [ ! -z "$NVM_ARCH_UNOFFICIAL_OVERRIDE" ]; then
echo "==> Handle NVM_ARCH_UNOFFICIAL_OVERRIDE=$NVM_ARCH_UNOFFICIAL_OVERRIDE!"
echo "nvm_get_arch() { nvm_echo \"${NVM_ARCH_UNOFFICIAL_OVERRIDE}\"; }" >> $ENV_DOT_PROFILE
echo "export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release" >> $ENV_DOT_PROFILE
source $ENV_DOT_PROFILE
fi
echo "6. Setup Node version"
if [ -n "$NVMRC_VERSION" ]; then
echo "==> Installing Node version: $NVMRC_VERSION"
nvm install $NVMRC_VERSION
nvm alias default $NVMRC_VERSION
nvm use $NVMRC_VERSION
cd $CIRCLE_WORKING_DIRECTORY
else
echo "==> ERROR - NVMRC_VERSION has not been set! - NVMRC_VERSION: $NVMRC_VERSION"
exit 1
fi
defaults_display_versions: &defaults_display_versions
name: Display Versions
command: |
echo "What is the active version of Nodejs?"
echo "node: $(node --version)"
echo "yarn: $(yarn --version)"
echo "npm: $(npm --version)"
echo "nvm: $(nvm --version)"
defaults_environment: &defaults_environment
## env var for nx to set main branch
MAIN_BRANCH_NAME: main


##
Expand All @@ -82,24 +132,33 @@ defaults_configure_nvm: &defaults_configure_nvm
executors:
default-docker:
working_directory: &WORKING_DIR /home/circleci/project
shell: "/bin/sh -leo pipefail" ## Ref: https://circleci.com/docs/env-vars/#alpine-linux
environment:
BASH_ENV: /etc/profile ## Ref: https://circleci.com/docs/env-vars/#alpine-linux
NVM_ARCH_UNOFFICIAL_OVERRIDE: x64-musl ## Ref: https://github.com/nvm-sh/nvm/issues/1102#issuecomment-550572252
docker:
- image: node:16.15.0-alpine # Ref: https://hub.docker.com/_/node?tab=tags&page=1&name=alpine
- image: node:lts-alpine # Ref: https://hub.docker.com/_/node?tab=tags&page=1&name=alpine

default-machine:
working_directory: *WORKING_DIR
shell: "/bin/bash -leo pipefail"
machine:
image: ubuntu-2004:current # Ref: https://circleci.com/developer/machine/image/ubuntu-2004
image: ubuntu-2204:2023.04.2 # Ref: https://circleci.com/developer/machine/image/ubuntu-2204

jobs:
setup:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- run:
name: Update NPM install
command: npm ci
Expand All @@ -110,13 +169,17 @@ jobs:

test-dependencies:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
Expand All @@ -125,13 +188,17 @@ jobs:

test-lint:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
Expand All @@ -140,19 +207,19 @@ jobs:

test-unit:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
# This is needed for legacy core tests. Remove this once 'tape' is fully deprecated.
name: Install tape, tapes and tap-xunit
command: npm install tape tapes tap-xunit
- run:
name: Create dir for test results
command: mkdir -p ./test/results
Expand All @@ -161,70 +228,70 @@ jobs:
command: npm -s run test:xunit
- store_artifacts:
path: ./test/results
prefix: test
destination: test
- store_test_results:
path: ./test/results

test-coverage:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- run:
name: Install AWS CLI dependencies
command: *defaults_awsCliDependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Execute code coverage check
command: npm -s run test:coverage-check
- store_artifacts:
path: coverage
prefix: test
destination: test
- store_test_results:
path: coverage
- run:
name: Copy code coverage to SonarQube
command: |
if [ "${CIRCLE_BRANCH}" == "master" ];
then
echo "Sending lcov.info to SonarQube..."
aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/${CIRCLE_PROJECT_REPONAME}/lcov.info
else
echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
fi

vulnerability-check:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Create dir for test results
command: mkdir -p ./audit/results
- run:
name: Check for new npm vulnerabilities
command: npm run audit:check --silent -- --json > ./audit/results/auditResults.json
command: npm run audit:check -- -o json > ./audit/results/auditResults.json
- store_artifacts:
path: ./audit/results
prefix: audit
destination: audit

audit-licenses:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- run:
<<: *defaults_license_scanner
- checkout
Expand All @@ -235,14 +302,16 @@ jobs:
command: cd /tmp/license-scanner && pathToRepo=$CIRCLE_WORKING_DIRECTORY make run
- store_artifacts:
path: /tmp/license-scanner/results
prefix: licenses
destination: licenses

release:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
Expand Down Expand Up @@ -271,6 +340,9 @@ jobs:

github-release:
executor: default-machine
shell: "/bin/bash -eo pipefail"
environment:
<<: *defaults_environment
steps:
- run:
name: Install git
Expand Down Expand Up @@ -313,10 +385,12 @@ jobs:

publish:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
Expand Down Expand Up @@ -351,10 +425,12 @@ jobs:

publish-snapshot:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
command: *defaults_docker_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
Expand Down Expand Up @@ -391,7 +467,6 @@ jobs:
template: SLACK_TEMP_RELEASE_FAILURE

workflows:
version: 2
build_and_test:
jobs:
- pr-tools/pr-title-check:
Expand Down Expand Up @@ -471,7 +546,7 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
# New commits to master release automatically
# New commits to main release automatically
- release:
context: org-global
requires:
Expand All @@ -485,7 +560,7 @@ workflows:
filters:
branches:
only:
- master
- main
- /release\/v.*/
- github-release:
context: org-global
Expand All @@ -494,7 +569,7 @@ workflows:
filters:
branches:
only:
- master
- main
- /release\/v.*/
- publish:
context: org-global
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
18.17.1
Loading

0 comments on commit b4bb05b

Please sign in to comment.