1#!/bin/bash 2set +x 3 4test_type="$1" 5commit_hash="$2" 6change_target="origin/$3" 7 8if [ "$3" == "null" ]; then 9 against_master=1 10else 11 against_master=0 12 change_base=$(git merge-base $change_target $commit_hash) 13fi 14 15echo "shared/jenkins_test.sh recieved type: ${test_type} commit_hash: ${commit_hash} change_target: ${change_target} change_base: ${change_base}" 16 17check_rc() { 18 # exit if passed in value is not = 0 19 # $1 = check return code 20 # $2 = command / label 21 # $3 = exit code 22 if [ $1 -ne 0 ] 23 then 24 echo "$2: bailing" 25 exit $3 26 fi 27} 28 29has_js_files() { 30 if [ $against_master -eq 1 ]; then 31 echo 'Missing $change_target, forcing has_js_files to true' 32 return 33 fi 34 echo 'git fetch -q' 35 git fetch -q 36 check_rc $? 'echo git fetch problem' 1 37 echo 'git diff' 38 git diff --name-only "$change_base...$commit_hash" 39 # ignore test.sh for now 40 diff_files=`git diff --name-only "$change_base...$commit_hash" | grep '^shared/' | grep -v '^shared/jenkins_test\.sh'` 41 check_rc $? 'no files js cares about' 0 42 echo "continuing due to changes in $diff_files" 43} 44 45js_tests() { 46 echo 'js-tests' 47 node --version 48 npm i -g yarn 49 has_js_files 50 51 echo 'yarn install' 52 yarn install --network-concurrency 1 --prefer-offline --pure-lockfile --ignore-optional --ignore-engines 53 yarn modules --ignore-engines 54 check_rc $? 'yarn install fail' 1 55 56 echo 'checking no mutated yarn.lock file' 57 git diff --exit-code yarn.lock 58 check_rc $? 'unexpected yarn.lock changes, did you forget to commit it? Do you have an inexact semver?' 1 59 60 echo 'yarn build-actions' 61 yarn build-actions 62 check_rc $? 'yarn build-actions failed!' 1 63 git diff --exit-code actions 64 check_rc $? 'unexpected generated actions changes, did you forget to run yarn build-actions?' 1 65 66 yarn gobuild-emoji 67 check_rc $? 'yarn gobuild-emoji failed!' 1 68 git diff --exit-code ../go 69 check_rc $? 'unexpected generated emoji changes, did you forget to yarn gobuild-emoji?' 1 70 71 echo 'yarn tsc' 72 yarn tsc --project ./tsconfig.json 73 check_rc $? 'tsc failed!' 1 74 75 echo 'yarn lint' 76 yarn lint 77 check_rc $? 'yarn run lint fail' 1 78 79 echo 'yarn test' 80 yarn test 81 check_rc $? 'yarn test fail' 1 82 83 echo 'yarn prettier-check' 84 yarn prettier-check 85 check_rc $? 'yarn prettier-check fail' 1 86} 87 88js_tests 89