From af2f4d5239f0e94b1db36b1a81978146c747eea8 Mon Sep 17 00:00:00 2001 From: fallwith Date: Tue, 10 Oct 2023 17:11:02 -0700 Subject: [PATCH] CI: do not test Rails Edge for CI workflows - set an env var for CI workflows to denote CI workflow presence - use a common Envfile helper to unshift Rails Edge onto the list of gem versions to test against - update `active_record_pg`, `rails`, and `rails_prepend` to use the helper - do not touch `active_record` at this time --- .github/workflows/ci.yml | 5 ++++ test/multiverse/lib/multiverse/envfile.rb | 28 +++++++++++++++++++ .../suites/active_record_pg/Envfile | 3 +- test/multiverse/suites/rails/Envfile | 3 +- test/multiverse/suites/rails_prepend/Envfile | 2 ++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a473673b3c..a6279c7313 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: image: mysql:5.7 env: MYSQL_ALLOW_EMPTY_PASSWORD: yes + CI_FOR_PR: true options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 ports: - "3306:3306" @@ -83,6 +84,7 @@ jobs: env: RUBY_VERSION: ${{ matrix.ruby-version }} RAILS_VERSION: ${{ env.rails }} + CI_FOR_PR: true - name: Run Unit Tests uses: nick-fields/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd # tag v2.8.3 @@ -94,6 +96,7 @@ jobs: DB_PORT: ${{ job.services.mysql.ports[3306] }} VERBOSE_TEST_OUTPUT: true COVERAGE: true + CI_FOR_PR: true - name: Save coverage results uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # tag v3.1.2 @@ -253,6 +256,7 @@ jobs: POSTGRES_PASSWORD: password SERIALIZE: 1 COVERAGE: true + CI_FOR_PR: true - name: Annotate errors if: ${{ failure() }} @@ -306,6 +310,7 @@ jobs: VERBOSE_TEST_OUTPUT: true SERIALIZE: 1 COVERAGE: true + CI_FOR_PR: true - name: Annotate errors if: ${{ failure() }} diff --git a/test/multiverse/lib/multiverse/envfile.rb b/test/multiverse/lib/multiverse/envfile.rb index 1cec6d1e12..5a67bee74a 100644 --- a/test/multiverse/lib/multiverse/envfile.rb +++ b/test/multiverse/lib/multiverse/envfile.rb @@ -133,6 +133,34 @@ def serialize? @serialize end + # add Rails Edge to the array of gem versions for testing, + # unless we're operating in a PR workflow context + def prepend_rails_edge(gem_version_array = []) + return if ci_for_pr? + + # Unshift Rails Edge (representing the latest GitHub primary branch + # commit for https://github.com/rails/rails) onto the front of the + # gem version array. This produces the following line in the generated + # Gemfile file: + # + # gem 'rails', github: 'rails' + # + # NOTE: Individually distributed Rails gems such as Active Record are each + # contained within the same 'rails' GitHub repo. For now we are not + # too concerned with cloning the entire Rails repo despite only + # wanting to test one gem. + # + # NOTE: The Rails Edge version is not tested unless the Ruby version in + # play is greater than or equal to (>=) the version number at the + # end of the unshifted inner array + array.unshift(["github: 'rails'", 3.0]) + end + + # are we running in a CI context intended for PR approvals? + def ci_for_pr? + ENV.key?('CI_FOR_PR') + end + private def last_supported_ruby_version?(last_supported_ruby_version) diff --git a/test/multiverse/suites/active_record_pg/Envfile b/test/multiverse/suites/active_record_pg/Envfile index 5fb5a38937..979eb6896c 100644 --- a/test/multiverse/suites/active_record_pg/Envfile +++ b/test/multiverse/suites/active_record_pg/Envfile @@ -12,7 +12,6 @@ end serialize! ACTIVERECORD_VERSIONS = [ - ["github: 'rails'", 3.0], # Rails Edge [nil, 2.7], ['7.0.0', 2.7], ['6.1.0', 2.5], @@ -22,6 +21,8 @@ ACTIVERECORD_VERSIONS = [ ['5.0.0', 2.4, 2.7] ] +prepend_rails_edge(ACTIVERECORD_VERSIONS) + def gem_list(activerecord_version = nil) <<~RB gem 'activerecord'#{activerecord_version} diff --git a/test/multiverse/suites/rails/Envfile b/test/multiverse/suites/rails/Envfile index 59c8a30b56..17e2e41483 100644 --- a/test/multiverse/suites/rails/Envfile +++ b/test/multiverse/suites/rails/Envfile @@ -3,7 +3,6 @@ # frozen_string_literal: true RAILS_VERSIONS = [ - ["github: 'rails'", 3.0], # Rails Edge [nil, 2.7], ['7.0.4', 2.7], ['6.1.7', 2.5], @@ -14,6 +13,8 @@ RAILS_VERSIONS = [ ['4.2.11', 2.4, 2.4] ] +prepend_rails_edge(RAILS_VERSIONS) + def haml_rails(rails_version = nil) if rails_version && ( rails_version.include?('4.0.13') || diff --git a/test/multiverse/suites/rails_prepend/Envfile b/test/multiverse/suites/rails_prepend/Envfile index 9d8e2ad105..8cba530127 100644 --- a/test/multiverse/suites/rails_prepend/Envfile +++ b/test/multiverse/suites/rails_prepend/Envfile @@ -13,6 +13,8 @@ RAILS_VERSIONS = [ ['4.2.0', 2.4, 2.4] ] +prepend_rails_edge(RAILS_VERSIONS) + def gem_list(rails_version = nil) # earlier thor errors, uncertain if they persist thor = "gem 'thor', '< 0.20.1'" if RUBY_PLATFORM == 'java' && rails_version && rails_version.include?('4')