From b3c17acee173cce783f1d44cde864b99a55cbb6a Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 22 Jan 2024 20:45:39 +0000 Subject: [PATCH] Merge pull request #2726 from rspec/update-rspec-rails-build Cleanup rspec-rails build and fix rubygems issue --- .github/workflows/ci.yml | 6 - BUILD_DETAIL.md | 4 +- .../ci_retry_bundle_install.sh | 6 +- script/ci_functions.sh | 73 ---------- script/clone_all_rspec_repos | 20 ++- script/custom_build_functions.sh | 20 --- script/functions.sh | 132 +++++++----------- script/predicate_functions.sh | 107 -------------- script/run_build | 21 +-- script/run_rubocop | 12 +- script/update_rubygems_and_install_bundler | 31 ++-- 11 files changed, 91 insertions(+), 341 deletions(-) delete mode 100644 script/ci_functions.sh delete mode 100644 script/custom_build_functions.sh delete mode 100644 script/predicate_functions.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 119575574f..f54e46d7c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,12 +43,6 @@ jobs: - ruby: 3.1 env: RAILS_VERSION: 'main' - - ruby: '3.0' - env: - RAILS_VERSION: 'main' - - ruby: 2.7 - env: - RAILS_VERSION: 'main' # Rails 7.1 builds >= 2.7 - ruby: 3.2 diff --git a/BUILD_DETAIL.md b/BUILD_DETAIL.md index 50014d9bca..a6356b51c3 100644 --- a/BUILD_DETAIL.md +++ b/BUILD_DETAIL.md @@ -6,14 +6,14 @@ DO NOT modify it by hand as your changes will get lost the next time it is gener # The CI build, in detail The CI build runs many verification steps to prevent regressions and -ensure high-quality code. To run the Travis build locally, run: +ensure high-quality code. To run the build locally, run: ``` $ script/run_build ``` It can be useful to run the build steps individually -to repro a failing part of a Travis build. Let's break +to repro a failing part of a build. Let's break the build down into the individual steps. ## Specs diff --git a/example_app_generator/ci_retry_bundle_install.sh b/example_app_generator/ci_retry_bundle_install.sh index bcc4467919..459097d379 100755 --- a/example_app_generator/ci_retry_bundle_install.sh +++ b/example_app_generator/ci_retry_bundle_install.sh @@ -4,8 +4,4 @@ set -e source FUNCTIONS_SCRIPT_FILE echo "Starting bundle install using shared bundle path" -if is_mri; then - travis_retry eval "RUBYOPT=$RUBYOPT:' --enable rubygems' bundle install --gemfile ./Gemfile --path REPLACE_BUNDLE_PATH --retry=3 --jobs=3" -else - travis_retry eval "bundle install --gemfile ./Gemfile --path REPLACE_BUNDLE_PATH --retry=3 --jobs=3" -fi +ci_retry eval "RUBYOPT=$RUBYOPT:' --enable rubygems' bundle install --gemfile ./Gemfile --path REPLACE_BUNDLE_PATH --retry=3 --jobs=3" diff --git a/script/ci_functions.sh b/script/ci_functions.sh deleted file mode 100644 index 4a86428a6b..0000000000 --- a/script/ci_functions.sh +++ /dev/null @@ -1,73 +0,0 @@ -# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. - -# Taken from: -# https://github.com/travis-ci/travis-build/blob/e9314616e182a23e6a280199cd9070bfc7cae548/lib/travis/build/script/templates/header.sh#L34-L53 -travis_retry() { - local result=0 - local count=1 - while [ $count -le 3 ]; do - [ $result -ne 0 ] && { - echo -e "\n\033[33;1mThe command \"$@\" failed. Retrying, $count of 3.\033[0m\n" >&2 - } - "$@" - result=$? - [ $result -eq 0 ] && break - count=$(($count + 1)) - sleep 1 - done - - [ $count -eq 3 ] && { - echo "\n\033[33;1mThe command \"$@\" failed 3 times.\033[0m\n" >&2 - } - - return $result -} - -# Taken from https://github.com/vcr/vcr/commit/fa96819c92b783ec0c794f788183e170e4f684b2 -# and https://github.com/vcr/vcr/commit/040aaac5370c68cd13c847c076749cd547a6f9b1 -nano_cmd="$(type -p gdate date | head -1)" -nano_format="+%s%N" -[ "$(uname -s)" != "Darwin" ] || nano_format="${nano_format/%N/000000000}" - -travis_time_start() { - travis_timer_id=$(printf %08x $(( RANDOM * RANDOM ))) - travis_start_time=$($nano_cmd -u "$nano_format") - printf "travis_time:start:%s\r\e[0m" $travis_timer_id -} - -travis_time_finish() { - local travis_end_time=$($nano_cmd -u "$nano_format") - local duration=$(($travis_end_time-$travis_start_time)) - printf "travis_time:end:%s:start=%s,finish=%s,duration=%s\r\e[0m" \ - $travis_timer_id $travis_start_time $travis_end_time $duration -} - -fold() { - local name="$1" - local status=0 - shift 1 - if [ -n "$TRAVIS" ]; then - printf "travis_fold:start:%s\r\e[0m" "$name" - travis_time_start - else - echo "============= Starting $name ===============" - fi - - "$@" - status=$? - - [ -z "$TRAVIS" ] || travis_time_finish - - if [ "$status" -eq 0 ]; then - if [ -n "$TRAVIS" ]; then - printf "travis_fold:end:%s\r\e[0m" "$name" - else - echo "============= Ending $name ===============" - fi - else - STATUS="$status" - fi - - return $status -} diff --git a/script/clone_all_rspec_repos b/script/clone_all_rspec_repos index 324031cfaa..b9e292c2c9 100755 --- a/script/clone_all_rspec_repos +++ b/script/clone_all_rspec_repos @@ -5,17 +5,13 @@ set -e source script/functions.sh -if is_mri; then - pushd .. +pushd .. - clone_repo "rspec" - clone_repo "rspec-core" - clone_repo "rspec-expectations" - clone_repo "rspec-mocks" - clone_repo "rspec-rails" - clone_repo "rspec-support" +clone_repo "rspec" +clone_repo "rspec-core" +clone_repo "rspec-expectations" +clone_repo "rspec-mocks" +clone_repo "rspec-rails" +clone_repo "rspec-support" - popd -else - echo "Not cloning all repos since we are not on MRI and they are only needed for the MRI build" -fi +popd diff --git a/script/custom_build_functions.sh b/script/custom_build_functions.sh deleted file mode 100644 index 256211d5e7..0000000000 --- a/script/custom_build_functions.sh +++ /dev/null @@ -1,20 +0,0 @@ -function run_cukes { - if is_mri; then - bin/rake acceptance --trace - return $? - elif is_jruby; then - bin/rake smoke:app - return $? - else - return 0 - fi -} - -# rspec-rails depends on all of the other rspec repos. Conversely, none of the -# other repos have any dependencies with rspec-rails directly. If the other -# repos have issues, the rspec-rails suite and cukes would fail exposing them. -# Since we are already implicitly testing them we do not need to run their spec -# suites explicitly. -function run_all_spec_suites { - fold "one-by-one specs" run_specs_one_by_one -} diff --git a/script/functions.sh b/script/functions.sh index 702d785bf6..1c854e746e 100644 --- a/script/functions.sh +++ b/script/functions.sh @@ -1,67 +1,69 @@ -# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. - SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $SCRIPT_DIR/ci_functions.sh -source $SCRIPT_DIR/predicate_functions.sh - -# If JRUBY_OPTS isn't set, use these. -# see https://docs.travis-ci.com/user/ci-environment/ -export JRUBY_OPTS=${JRUBY_OPTS:-"--server -Xcompile.invokedynamic=false"} SPECS_HAVE_RUN_FILE=specs.out MAINTENANCE_BRANCH=`cat maintenance-branch` # Don't allow rubygems to pollute what's loaded. Also, things boot faster # without the extra load time of rubygems. Only works on MRI Ruby 1.9+ -if is_mri; then - export RUBYOPT="--disable=gem" -fi +export RUBYOPT="--disable=gem" + +ci_retry() { + local result=0 + local count=1 + while [ $count -le 3 ]; do + [ $result -ne 0 ] && { + echo -e "\n\033[33;1mThe command \"$@\" failed. Retrying, $count of 3.\033[0m\n" >&2 + } + "$@" + result=$? + [ $result -eq 0 ] && break + count=$(($count + 1)) + sleep 1 + done -function clone_repo { - if [ ! -d $1 ]; then # don't clone if the dir is already there - travis_retry eval "git clone https://github.com/rspec/$1 --depth 1 --branch $MAINTENANCE_BRANCH" - fi; + [ $count -eq 3 ] && { + echo "\n\033[33;1mThe command \"$@\" failed 3 times.\033[0m\n" >&2 + } + + return $result } -function run_specs_and_record_done { - local rspec_bin=bin/rspec +fold() { + local name="$1" + local status=0 + shift 1 + echo "============= Starting $name ===============" - # rspec-core needs to run with a special script that loads simplecov first, - # so that it can instrument rspec-core's code before rspec-core has been loaded. - if [ -f script/rspec_with_simplecov ] && is_mri; then - rspec_bin=script/rspec_with_simplecov - fi; + "$@" + status=$? - echo "${PWD}/bin/rspec" - $rspec_bin spec --backtrace --format progress --profile --format progress --out $SPECS_HAVE_RUN_FILE + if [ "$status" -eq 0 ]; then + echo "============= Ending $name ===============" + else + STATUS="$status" + fi + + return $status } -function run_cukes { - if [ -d features ]; then - # force jRuby to use client mode JVM or a compilation mode that's as close as possible, - # idea taken from https://github.com/jruby/jruby/wiki/Improving-startup-time - # - # Note that we delay setting this until we run the cukes because we've seen - # spec failures in our spec suite due to problems with this mode. - export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1' - - echo "${PWD}/bin/cucumber" - - if is_jruby; then - # For some reason JRuby doesn't like our improved bundler setup - RUBYOPT="-I${PWD}/../bundle -rbundler/setup" \ - PATH="${PWD}/bin:$PATH" \ - bin/cucumber --strict - else - # Prepare RUBYOPT for scenarios that are shelling out to ruby, - # and PATH for those that are using `rspec` or `rake`. - RUBYOPT="${RUBYOPT} -I${PWD}/../bundle -rbundler/setup" \ - PATH="${PWD}/bin:$PATH" \ - bin/cucumber --strict - fi +function documentation_enforced { + if [ -x ./bin/yard ]; then + return 0 + else + return 1 fi } +function clone_repo { + if [ ! -d $1 ]; then # don't clone if the dir is already there + ci_retry eval "git clone https://github.com/rspec/$1 --depth 1 --branch $MAINTENANCE_BRANCH" + fi; +} + +function run_specs_and_record_done { + echo "${PWD}/bin/rspec" + bin/rspec spec --backtrace --format progress --profile --format progress --out $SPECS_HAVE_RUN_FILE +} + function run_specs_one_by_one { echo "Running each spec file, one-by-one..." @@ -71,27 +73,6 @@ function run_specs_one_by_one { done } -function run_spec_suite_for { - if [ ! -f ../$1/$SPECS_HAVE_RUN_FILE ]; then # don't rerun specs that have already run - if [ -d ../$1 ]; then - echo "Running specs for $1" - pushd ../$1 - unset BUNDLE_GEMFILE - bundle_install_flags=`cat .travis.yml | grep bundler_args | tr -d '"' | grep -o " .*"` - travis_retry eval "(unset RUBYOPT; exec bundle install $bundle_install_flags)" - run_specs_and_record_done - popd - else - echo "" - echo "WARNING: The ../$1 directory does not exist. Usually the" - echo "travis build cds into that directory and run the specs to" - echo "ensure the specs still pass with your latest changes, but" - echo "we are going to skip that step." - echo "" - fi; - fi; -} - function check_binstubs { echo "Checking required binstubs" @@ -174,16 +155,3 @@ function check_documentation_coverage { end " } - -function check_style_and_lint { - echo "bin/rubocop" - eval "(unset RUBYOPT; rm -rf tmp/*; exec bin/rubocop)" -} - -function run_all_spec_suites { - fold "rspec-core specs" run_spec_suite_for "rspec-core" - fold "rspec-expectations specs" run_spec_suite_for "rspec-expectations" - fold "rspec-mocks specs" run_spec_suite_for "rspec-mocks" - fold "rspec-rails specs" run_spec_suite_for "rspec-rails" - fold "rspec-support specs" run_spec_suite_for "rspec-support" -} diff --git a/script/predicate_functions.sh b/script/predicate_functions.sh deleted file mode 100644 index 90067bb10b..0000000000 --- a/script/predicate_functions.sh +++ /dev/null @@ -1,107 +0,0 @@ -# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. - -function is_mri { - if ruby -e "exit(!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')"; then - # RUBY_ENGINE only returns 'ruby' on MRI. - # MRI 1.8.7 lacks the constant but all other rubies have it (including JRuby in 1.8 mode) - return 0 - else - return 1 - fi; -} - -function is_jruby { - if ruby -e "exit(defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java')"; then - # RUBY_ENGINE only returns 'ruby' on MRI. - # MRI 1.8.7 lacks the constant but all other rubies have it (including JRuby in 1.8 mode) - return 0 - else - return 1 - fi; -} - -function is_mri_192 { - if is_mri; then - if ruby -e "exit(RUBY_VERSION == '1.9.2')"; then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -function is_mri_192_plus { - if is_mri; then - if ruby -e "exit(RUBY_VERSION.to_f > 1.8)"; then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -function is_mri_2plus { - if is_mri; then - if ruby -e "exit(RUBY_VERSION.to_f > 2.0)"; then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -function is_ruby_26_plus { - if ruby -e "exit(RUBY_VERSION.to_f >= 2.6)"; then - return 0 - else - return 1 - fi -} - -function is_ruby_23_plus { - if ruby -e "exit(RUBY_VERSION.to_f >= 2.3)"; then - return 0 - else - return 1 - fi -} - -function rspec_rails_compatible { - if is_ruby_23_plus; then - return 0 - else - return 1 - fi -} - -function rspec_support_compatible { - if [ "$MAINTENANCE_BRANCH" != "2-99-maintenance" ] && [ "$MAINTENANCE_BRANCH" != "2-14-maintenance" ]; then - return 0 - else - return 1 - fi -} - -function additional_specs_available { - type run_additional_specs > /dev/null 2>&1 - return $? -} - -function documentation_enforced { - if [ -x ./bin/yard ]; then - if is_mri_2plus; then - return 0 - else - return 1 - fi - else - return 1 - fi -} diff --git a/script/run_build b/script/run_build index 2938f81c8a..f16a8f2bd8 100755 --- a/script/run_build +++ b/script/run_build @@ -1,24 +1,14 @@ #!/bin/bash -# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. +# This file is manually managed unlike the rest of core rspec gems because it is independant. set -e source script/functions.sh -# Allow repos to override the default functions and add their own -if [ -f script/custom_build_functions.sh ]; then - source script/custom_build_functions.sh -fi - fold "binstub check" check_binstubs fold "specs" run_specs_and_record_done -if additional_specs_available; then - fold "additional specs" run_additional_specs -fi - -fold "cukes" run_cukes +fold "acceptance" bin/rake acceptance --trace fold "snippets" script/run_snippets.sh @@ -26,9 +16,4 @@ if documentation_enforced; then fold "doc check" check_documentation_coverage fi -if is_mri; then - fold "one-by-one specs" run_specs_one_by_one - run_all_spec_suites -else - echo "Skipping the rest of the build on non-MRI rubies" -fi +fold "one-by-one specs" run_specs_one_by_one diff --git a/script/run_rubocop b/script/run_rubocop index c2d94dcca3..2662c517c0 100755 --- a/script/run_rubocop +++ b/script/run_rubocop @@ -1,14 +1,12 @@ #!/bin/bash -# This file was generated on 2022-01-10T22:24:10+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. +# This file is manually managed unlike the rest of core rspec gems because it is independant. set -e source script/functions.sh -# Allow repos to override the default functions and add their own -if [ -f script/custom_build_functions.sh ]; then - source script/custom_build_functions.sh -fi - +function check_style_and_lint { + echo "bin/rubocop" + eval "(unset RUBYOPT; rm -rf tmp/*; exec bin/rubocop)" +} fold "rubocop" check_style_and_lint diff --git a/script/update_rubygems_and_install_bundler b/script/update_rubygems_and_install_bundler index 4c386c945b..921a3b786e 100755 --- a/script/update_rubygems_and_install_bundler +++ b/script/update_rubygems_and_install_bundler @@ -1,19 +1,32 @@ #!/bin/bash -# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. +# This file is manually managed unlike the rest of core rspec gems because it is independant. set -e -source script/functions.sh -if is_ruby_26_plus; then +function is_ruby_3_plus { + if ruby -e "exit(RUBY_VERSION.to_f >= 3.0)"; then + return 0 + else + return 1 + fi +} + +function is_ruby_26_plus { + if ruby -e "exit(RUBY_VERSION.to_f >= 2.6)"; then + return 0 + else + return 1 + fi +} + +if is_ruby_3_plus; then gem update --no-document --system gem install --no-document bundler -elif is_ruby_23_plus; then +elif is_ruby_26_plus; then + gem update --no-document --system '3.4.22' + gem install --no-document bundler +else echo "Warning installing older versions of Rubygems / Bundler" gem update --system '3.3.26' gem install bundler -v '2.3.26' -else - echo "Warning installing older versions of Rubygems / Bundler" - gem update --system '2.7.10' - gem install bundler -v '1.17.3' fi