diff --git a/.circleci/config.yml b/.circleci/config.yml index fad8b1a..22f64c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,21 @@ jobs: - run: name: test command: npm test + - run: + name: compatibility test setup + command: bash tools/nodejs_compatibility_checker/test_compatibility_setup.sh --quick + - restore_cache: + key: compatibility-test-cache-{{ checksum "nodes_available.log" }} + - run: + name: compatibility test environment cache generation + command: bash tools/nodejs_compatibility_checker/test_compatibility_cache.sh + - save_cache: + key: compatibility-test-cache-{{ checksum "nodes_available.log" }} + paths: + - ~/.envirius/envs/ + - run: + name: compatibility test + command: bash tools/nodejs_compatibility_checker/test_compatibility.sh - run: name: package for debug command: npm pack diff --git a/CHANGELOG.md b/CHANGELOG.md index 3021c56..e6427d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Versioning](http://semver.org/spec/v2.0.0.html). ### Changed - Merge PR #124, adding the `--verbose` flag and returning exit code `1` on a fatal exception or parsing error +### Added +- Merge PR #128, implement NodeJS compatibility test in CI/CD + ## [1.5.1] - 2018-03-12 ### Added - Merge PR #113, adding a Spanish translation for README.md diff --git a/tools/nodejs_compatibility_checker/test_compatibility.sh b/tools/nodejs_compatibility_checker/test_compatibility.sh new file mode 100755 index 0000000..a680d1f --- /dev/null +++ b/tools/nodejs_compatibility_checker/test_compatibility.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +[ ! -e ~/.envirius/nv ] && echo 'Error: envirius is not installed!' && exit 1 +[ ! -e nodes_available.log ] && echo 'Error: no environments available!' && exit 1 + +export TERM="dumb" +source ~/.envirius/nv +node_versions=$(cat nodes_available.log) + +# Run the tests on all available versions +for version in ${node_versions}; do + echo "Testing node-${version}!"; + nv activate --same-shell "node-${version}" + npm test >"test_node_${version}.log" 2>&1 + if [ $? -eq 0 ]; then + echo "PASSED" + echo ${version} >> nodes_passed.log + else + echo "FAILED" + fi + nv deactivate +done + +# Determine failed versions and display the test-run +failed=$(comm -23 <(sort nodes_available.log) <(sort nodes_passed.log)) +if [ -z "${failed}" ]; then + echo "Build is compatible with all major node versions!" + exit 0 +fi + +echo "Build is incompatible with the following node versions:" +echo "${failed}" +for version in ${failed}; do + echo "***Started test-run for ${version}***"; + cat "test_node_${version}.log"; + echo "***Finished test-run for ${version}***"; +done +exit 1 diff --git a/tools/nodejs_compatibility_checker/test_compatibility_cache.sh b/tools/nodejs_compatibility_checker/test_compatibility_cache.sh new file mode 100644 index 0000000..20f1ba8 --- /dev/null +++ b/tools/nodejs_compatibility_checker/test_compatibility_cache.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +[ ! -e ~/.envirius/nv ] && echo 'Error: envirius is not installed!' && exit 1 +[ ! -e nodes_available.log ] && echo 'Error: no environments available!' && exit 1 + +export TERM="dumb" +source ~/.envirius/nv +node_versions=$(cat nodes_available.log) + +# Cache NodeJS environments +for version in ${node_versions}; do + echo "Adding NodeJS ${version} into environment cache!" && \ + nv mk "node-${version}" --node-prebuilt=${version} +done diff --git a/tools/nodejs_compatibility_checker/test_compatibility_setup.sh b/tools/nodejs_compatibility_checker/test_compatibility_setup.sh new file mode 100644 index 0000000..3a722e6 --- /dev/null +++ b/tools/nodejs_compatibility_checker/test_compatibility_setup.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +export TERM="dumb" + +# Install envirius +git clone --depth 1 https://github.com/ekalinin/envirius.git && \ +cd envirius && \ +make install && \ +cd .. && \ +source ~/.envirius/nv + +if [ $? -ne 0 ]; then + echo "Unable to install envirius!" + exit 1 +fi + +# Determine available node versions +node_versions=$(nv ls-versions --node-prebuilt | sed 's/\s/\n/g' | grep -E '^[1-9]') +if [ -z "${node_versions}" ]; then + echo "Unable to determine node versions!" + exit 1 +fi + +# Quick check +if [ "$1" == "--quick" ]; then + lts_versions=$( + for lts in 4 6 8 9; do + echo "${node_versions}" | grep -E "^${lts}" | tail -1 + done + ) + node_versions=${lts_versions} +fi + +# Dump available versions to file +for version in ${node_versions}; do + echo ${version} >> nodes_available.log +done