Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #389 from Shopify/version-stuff
Declare `required_ruby_version` 2.7 and run CI against Ruby 2.7 - 3.1, and minimum Rubocop version
- Loading branch information
Showing
6 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ _site | |
node_modules | ||
css/ | ||
pkg/ | ||
|
||
gemfiles/*.gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
eval_gemfile "../Gemfile" | ||
|
||
# This naively extracts the minimum rubocop version from our gemspec, | ||
# allowing us to ensure that it remains compatible. | ||
minimum_rubocop_version = File.read("rubocop-shopify.gemspec")[/(?<=add_dependency\("rubocop", "~> ).*(?="\)$)/] | ||
raise "Failed to extract minimum rubocop version from gemspec" if minimum_rubocop_version.nil? | ||
|
||
gem "rubocop", minimum_rubocop_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "pry" | ||
require "yaml" | ||
|
||
class RubyVersionsTest < Minitest::Test | ||
def test_ci_matrix_includes_minimum_ruby_version | ||
minimum_ruby_version = normalize(extract_minimum_ruby_version_from_gemspec) | ||
ruby_versions = extract_ruby_versions_from_ci_matrix.map { |version| normalize(version) } | ||
|
||
assert_includes( | ||
ruby_versions, | ||
minimum_ruby_version, | ||
"CI must be configured to test as far back as gem's required_ruby_version", | ||
) | ||
end | ||
|
||
private | ||
|
||
def extract_minimum_ruby_version_from_gemspec | ||
# This naively extracts the minimum Ruby version compatible with out gemspec | ||
# allowing us to ensure that it is included in the CI matrix. | ||
minimum_ruby_version = File.read("rubocop-shopify.gemspec")[/(?<=required_ruby_version = ">= ).*(?="$)/] | ||
|
||
return minimum_ruby_version unless minimum_ruby_version.nil? | ||
|
||
flunk("Failed to extract required_ruby_version from gemspec") | ||
end | ||
|
||
def extract_ruby_versions_from_ci_matrix | ||
YAML | ||
.load_file(".github/workflows/ruby.yml") | ||
.fetch("jobs") | ||
.fetch("build") | ||
.fetch("strategy") | ||
.fetch("matrix") | ||
.fetch("ruby") | ||
end | ||
|
||
# Remove the trailing .0 for versions of the form X.Y.0 | ||
# Otherwise, return the version unchanged | ||
def normalize(version) | ||
if version.match?(/^\d+\.\d+\.0$/) | ||
version.chomp(".0") | ||
else | ||
version | ||
end | ||
end | ||
end |