Allow to test for multiple rails versions in CI

Before we only tested with the latest rails version and without rails,
that made it possible to accidentally break with older rails versions
without noticing it.

The old way of keeping separate Gemfiles (and lockfiles) was too
complicated to keep up to date, especially with many supported rails
versions. This allows now to run with different rails version with just
the same Gemfile using an env-var.

For CI the Gemfile.lock is only used for the latest rails version (7.0
at the moment), as it obviously doesn't fit for other versions. I think
that's fine, as if we are not compatible with a too new version of
something, we need to add a maximum version there anyway.

The `ruby/setup-ruby@v1` step automatically uses the deployment mode
when a Gemfile.lock is present, so the `BUNDLE_FROZEN` env-var is not
required, even if a Gemfile.lock is used.
This commit is contained in:
Benjamin Neff 2023-06-11 18:09:41 +02:00
parent 114d26d732
commit 3dbf0488dd
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
7 changed files with 30 additions and 180 deletions

View file

@ -9,6 +9,7 @@ on:
jobs:
test:
name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}'
runs-on: ubuntu-latest
strategy:
fail-fast: false
@ -17,17 +18,27 @@ jobs:
- "3.1"
- "3.0"
- "2.7"
gemfile:
- Gemfile
- test/gemfiles/no-rails.Gemfile
rails:
- "7.0"
- "6.1"
- "6.0"
- "5.2"
- "none"
exclude:
- ruby: "3.1"
rails: "5.2"
- ruby: "3.0"
rails: "5.2"
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
RAILS_VERSION: ${{ matrix.rails }}
BUNDLE_WITHOUT: development
BUNDLE_FROZEN: true
BUNDLE_DISABLE_SHARED_GEMS: true
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
steps:
- uses: actions/checkout@v2
- name: Delete Gemfile.lock
run: rm Gemfile.lock
if: matrix.rails != '7.0' # Gemfile.lock is only generated for latest rails version
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

14
Gemfile
View file

@ -9,7 +9,9 @@ gemspec name: "diaspora_federation"
Dir["diaspora_federation-*.gemspec"].each do |gemspec|
plugin = gemspec.scan(/diaspora_federation-(.*)\.gemspec/).flatten.first
gemspec(name: "diaspora_federation-#{plugin}", development_group: plugin)
unless ENV["RAILS_VERSION"] == "none" && plugin == "rails"
gemspec(name: "diaspora_federation-#{plugin}", development_group: plugin)
end
end
# Declare any dependencies that are still in development here instead of in
@ -57,5 +59,13 @@ group :development, :test do
# unit tests
gem "rspec", "~> 3.12.0"
gem "rspec-rails", "~> 5.1.2"
unless ENV["RAILS_VERSION"] == "none"
gem "rspec-rails", "~> 5.1.2"
# The default rails version needs to be kept up to date also in:
# - test/dummy/config/application.rb (config.load_defaults)
# - .github/workflows/ci.yml ('Delete Gemfile.lock' step)
gem "actionpack", "~> #{ENV['RAILS_VERSION'] || '7.0'}.0"
end
end

View file

@ -221,6 +221,7 @@ PLATFORMS
ruby
DEPENDENCIES
actionpack (~> 7.0.0)
diaspora_federation!
diaspora_federation-json_schema!
diaspora_federation-rails!

View file

@ -1,24 +0,0 @@
# frozen_string_literal: true
namespace :gemfiles do
desc "Generates no-rails.Gemfile"
task :generate do
FileUtils.mkdir_p("test/gemfiles")
FileUtils.rm(Dir["test/gemfiles/*.Gemfile.lock"])
original_gemfile = File.read("Gemfile")
original_gemfile.sub!(/(gemspec name:.*)/) { "#{Regexp.last_match[1]}, path: \"../../\"" }
original_gemfile.sub!(/(gemspec\(name:.*)\)/) { "#{Regexp.last_match[1]}, path: \"../../\")" }
original_gemfile.sub!(/^group :development do$.*?^end$\n\n/m, "")
no_rails_gemfile = original_gemfile.dup
no_rails_gemfile.sub!(/(gemspec\(name:.*)/) { "#{Regexp.last_match[1]} unless plugin == \"rails\"" }
no_rails_gemfile.sub!(/^.*rspec-rails.*$\n/, "")
no_rails_path = "test/gemfiles/no-rails.Gemfile"
File.write(no_rails_path, no_rails_gemfile)
Bundler.with_unbundled_env do
system("BUNDLE_GEMFILE=#{no_rails_path} bundle install")
end
end
end

View file

@ -24,7 +24,7 @@ require "diaspora_federation/rails"
module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
config.load_defaults(ENV["RAILS_VERSION"] || "7.0")
# Configuration for the application, engines, and railties goes here.
#

View file

@ -1,41 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
# Declare your gem's dependencies in diaspora_federation.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec name: "diaspora_federation", path: "../../"
Dir["diaspora_federation-*.gemspec"].each do |gemspec|
plugin = gemspec.scan(/diaspora_federation-(.*)\.gemspec/).flatten.first
gemspec(name: "diaspora_federation-#{plugin}", development_group: plugin, path: "../../") unless plugin == "rails"
end
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
group :test do
# rspec formatter
gem "fuubar", "2.5.1", require: false
gem "nyan-cat-formatter", require: false
# test coverage
gem "simplecov", "0.21.2", require: false
gem "simplecov-rcov", "0.3.1", require: false
# test helpers
gem "json-schema", "~> 3.0"
gem "rspec-collection_matchers", "~> 1.2.0"
gem "rspec-json_expectations", "~> 2.1"
gem "webmock", "~> 3.0"
end
group :development, :test do
gem "rake"
# unit tests
gem "rspec", "~> 3.11.0"
end

View file

@ -1,107 +0,0 @@
PATH
remote: ../..
specs:
diaspora_federation (1.0.1)
faraday (>= 1.0, < 3)
faraday-follow_redirects (~> 0.3)
nokogiri (~> 1.6, >= 1.6.8)
typhoeus (~> 1.0)
valid (~> 1.0)
diaspora_federation-json_schema (1.0.1)
diaspora_federation-test (1.0.1)
diaspora_federation (= 1.0.1)
fabrication (~> 2.29)
uuid (~> 2.3, >= 2.3.8)
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
docile (1.4.0)
ethon (0.15.0)
ffi (>= 1.15.0)
fabrication (2.29.0)
faraday (2.3.0)
faraday-net_http (~> 2.0)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (2.0.3)
ffi (1.15.5)
fuubar (2.5.1)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
hashdiff (1.0.1)
json-schema (3.0.0)
addressable (>= 2.8)
macaddr (1.7.2)
systemu (~> 2.6.5)
nokogiri (1.13.8-x86_64-linux)
racc (~> 1.4)
nyan-cat-formatter (0.12.0)
rspec (>= 2.99, >= 2.14.2, < 4)
public_suffix (4.0.7)
racc (1.6.0)
rake (13.0.6)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-collection_matchers (1.2.0)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-json_expectations (2.2.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-rcov (0.3.1)
simplecov (>= 0.4.1)
simplecov_json_formatter (0.1.4)
systemu (2.6.5)
typhoeus (1.4.0)
ethon (>= 0.9.0)
uuid (2.3.9)
macaddr (~> 1.0)
valid (1.2.0)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
PLATFORMS
x86_64-linux
DEPENDENCIES
diaspora_federation!
diaspora_federation-json_schema!
diaspora_federation-test!
fuubar (= 2.5.1)
json-schema (~> 3.0)
nyan-cat-formatter
rake
rspec (~> 3.11.0)
rspec-collection_matchers (~> 1.2.0)
rspec-json_expectations (~> 2.1)
simplecov (= 0.21.2)
simplecov-rcov (= 0.3.1)
webmock (~> 3.0)
BUNDLED WITH
2.3.7