Skip to content

Instantly share code, notes, and snippets.

@unional
Last active January 23, 2018 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unional/f3ba0ba96df85d7ca957b2df1318dfdf to your computer and use it in GitHub Desktop.
Save unional/f3ba0ba96df85d7ca957b2df1318dfdf to your computer and use it in GitHub Desktop.
#! /bin/bash
# Thanks to Night Train:
# https://stackoverflow.com/questions/48250235/how-to-setup-travis-to-skip-script-on-particular-nodejs-version
# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps
#
# To use this, create this file (e.g. under scripts folder: ./scripts/run-on-node-version.sh)
# and give it execution permission: chmod ugo+x scripts/run-on-node-version.sh
# Then you can use it in CI configurations, e.g. .travis.yml:
# - ./scripts/run-on-node-version.sh latest "npm install --no-save coveralls && npm run coveralls"
if [ $1 = 'latest' ]; then
target_version=$(npm info node version);
else
target_version=$1;
fi
node_version=$(node -v);
if [ ${node_version:1:1} = ${target_version:0:1} ]; then
echo "Detected ${node_version}, satisfying ${target_version}. Executing command";
eval $2;
else
echo "NodeJS ${node_version} instead of latest (${target_version:0:1}) is detected. Skipping command";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment