1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#!/usr/bin/env bash
# shellcheck disable=SC2059
BCyan='\033[1;36m'
BRed='\033[1;31m'
BGreen='\033[1;32m'
BBlue='\033[1;34m'
Color_Off='\033[0m'
set -o errexit
set -o pipefail
trap onexit_err ERR
# Exit handling
function onexit_err() {
local exit_status=${1:-$?}
printf "\n❌❌❌ ${BRed}Remote Development smoke test failed!${Color_Off} ❌❌❌\n"
if [ "${REVEAL_RUBOCOP_TODO}" -ne 0 ]; then
printf "\n${BRed}- If the failure was due to rubocop, try setting REVEAL_RUBOCOP_TODO=0 to ignore TODOs${Color_Off}\n"
fi
printf "\n${BRed}- If the failure was in a feature spec, those sometimes are flaky, try running it focused${Color_Off}\n"
exit "${exit_status}"
}
function print_start_message {
trap onexit_err ERR
printf "${BCyan}\nStarting Remote Development smoke test...${Color_Off}\n\n"
}
function run_rubocop {
trap onexit_err ERR
printf "${BBlue}Running RuboCop${Color_Off}\n\n"
files_for_rubocop=()
while IFS='' read -r file; do
files_for_rubocop+=("$file")
done < <(git ls-files -- '**/remote_development/*.rb' '**/gitlab/fp/*.rb' '*_rop_*.rb' '*railway_oriented_programming*.rb' '*_result_matchers*.rb')
REVEAL_RUBOCOP_TODO=${REVEAL_RUBOCOP_TODO:-1} bundle exec rubocop --parallel --force-exclusion --no-server "${files_for_rubocop[@]}"
}
function run_fp {
trap onexit_err ERR
printf "\n\n${BBlue}Running backend RSpec FP specs${Color_Off}\n\n"
files_for_fp=()
while IFS='' read -r file; do
files_for_fp+=("$file")
done < <(git ls-files -- '**/gitlab/fp/*_spec.rb')
bin/rspec "${files_for_fp[@]}"
}
function run_rspec_fast {
trap onexit_err ERR
printf "\n\n${BBlue}Running backend RSpec fast specs${Color_Off}\n\n"
files_for_fast=()
while IFS='' read -r file; do
files_for_fast+=("$file")
done < <(git grep -l -E '^require .fast_spec_helper' -- '**/remote_development/*_spec.rb')
bin/rspec "${files_for_fast[@]}"
}
function run_jest {
trap onexit_err ERR
printf "\n\n${BBlue}Running Remote Development frontend Jest specs${Color_Off}\n\n"
yarn jest ee/spec/frontend/workspaces
}
function run_rspec_rails_non_fast {
trap onexit_err ERR
printf "\n\n${BBlue}Running backend RSpec non-fast specs${Color_Off}\n\n"
files_for_rails=()
while IFS='' read -r file; do
files_for_rails+=("$file")
done < <(git grep -L -E '^require .fast_spec_helper' -- '**/remote_development/*_spec.rb' | grep -v 'qa/qa' | grep -v '/features/')
files_for_rails+=(
"ee/spec/graphql/resolvers/clusters/agents_resolver_spec.rb"
"ee/spec/graphql/types/query_type_spec.rb"
"ee/spec/graphql/types/subscription_type_spec.rb"
"ee/spec/models/ee/clusters/agent_spec.rb"
"ee/spec/requests/api/internal/kubernetes_spec.rb"
"spec/graphql/types/subscription_type_spec.rb"
"spec/support_specs/matchers/result_matchers_spec.rb"
)
bin/rspec --format documentation "${files_for_rails[@]}"
}
function run_rspec_feature {
trap onexit_err ERR
printf "\n\n${BBlue}Running backend RSpec feature specs (NOTE: These sometimes are flaky (see https://gitlab.com/gitlab-org/gitlab/-/issues/478601)! If one fails, try running it focused, or just ignore it and let CI run it)...${Color_Off}\n\n"
files_for_feature=()
while IFS='' read -r file; do
files_for_feature+=("$file")
done < <(git ls-files -- '**/remote_development/*_spec.rb' | grep -v 'qa/qa' | grep '/features/')
bin/rspec -r spec_helper "${files_for_feature[@]}"
}
function print_success_message {
printf "\n✅✅✅ ${BGreen}All executed linters/specs passed successfully!${Color_Off} ✅✅✅\n"
}
function main {
trap onexit_err ERR
# cd to gitlab root directory
cd "$(dirname "${BASH_SOURCE[0]}")"/../..
print_start_message
# Run linting before tests
[ -z "${SKIP_RUBOCOP}" ] && run_rubocop
# Test sections are sorted roughly in increasing order of execution time.
[ -z "${SKIP_FP}" ] && run_fp
[ -z "${SKIP_FAST}" ] && run_rspec_fast
[ -z "${SKIP_JEST}" ] && run_jest
[ -z "${SKIP_RAILS}" ] && run_rspec_rails_non_fast
[ -z "${SKIP_FEATURE}" ] && run_rspec_feature
print_success_message
}
main "$@"
|