appraisal-matrix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a15e1a8f3f0f52235bc85e749b73a4fcf753393281f59ef10ce53033caa3a83b
4
+ data.tar.gz: 0b097af634a61f3bad05e7513a28902fba3516ed17c23fbb3add3bb35135bf5c
5
+ SHA512:
6
+ metadata.gz: 4a1d81416bbc19307d92feaf5df8f24d232863ad1325793fb15097a4021c458eb619bb5e997043df9e5ec2eab42392440a0ba79cbf36e8f8bad927f0ae94dfb7
7
+ data.tar.gz: 81e255ddd188a08b97a81b6f5d4fefb558c20c884df44b10540cd6b4240717ad28519210b0dc24e9ee9347eb4e70b99f9e39c989a983d2c50b511acf8b281138
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ # This rubocop config file inherits from our centralized style-guide repository.
2
+ # If you are looking to update the ruby style guide, be sure to both update the rubocop config
3
+ # as well as the README.md
4
+ # https://github.com/Invoca/style-guide/tree/master/ruby
5
+ inherit_from: https://raw.githubusercontent.com/Invoca/style-guide/master/ruby/.rubocop.yml
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.1
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "appraisal/matrix"
4
+
5
+ appraisal_matrix(appraisal: "2.2")
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ All notable changes to this project will be documented in this file.
2
+
3
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [0.1.0] - Unreleased
7
+ ### Added
8
+ - Add an extension to the Appraisal gem that provides an interface for generating a matrix of appraisals.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Drew Caddell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Appraisal::Matrix
2
+
3
+ Sometimes our gems are using dependencies which have consistent major/minor versions released with breaking changes, and we want to ensure compatibility by explicitly testing against the array of versions.
4
+
5
+ Appraisal::Matrix provides an interface for testing against that entire array without repetition in the Appraisals file.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ ### Single gem usage
22
+
23
+ The most common use-case is wanting to test compatibility with all supported versions of Rails.
24
+
25
+ ```ruby
26
+ # Appraisals
27
+ # frozen_string_literal: true
28
+
29
+ require "appraisal/matrix"
30
+
31
+ appraisal_matrix(activesupport: "6.1")
32
+ ```
33
+
34
+ Then run
35
+
36
+ $ bundle exec appraisal install
37
+
38
+ A gemfile like the one below will be created for each major/minor version of activesupport starting with 6.1.
39
+ ```ruby
40
+ # activesupport_6_1.gemfile
41
+ # This file was generated by Appraisal
42
+
43
+ gem "activesupport", "~> 6.1.0"
44
+ ```
45
+
46
+ ### Passing blocks to Appraisal
47
+
48
+ Any block passed to `appraisal_matrix` will be run in each individual appraisal. For example, if you [rely on removing gems using appraisal](https://github.com/thoughtbot/appraisal?tab=readme-ov-file#removing-gems-using-appraisal) you can pass the exact same block to `appraisal_matrix`.
49
+
50
+ ```ruby
51
+ appraisal_matrix(activesupport: "6.1") do
52
+ remove_gem 'test_after_commit'
53
+ end
54
+ ```
55
+
56
+ ### Appraising more than one Gem
57
+
58
+ You can also pass more than one gem to `appraisal_matrix` to create a matrix of all combinations of the specified gems.
59
+
60
+ ```ruby
61
+ appraisal_matrix(activesupport: "6.1", sidekiq: "7.0")
62
+ ```
63
+
64
+ ### Version argument options
65
+
66
+ In addition to specifying the minimum requested version, users will be able to make additional version requests.
67
+
68
+ #### Maximum version (Coming soon!)
69
+
70
+ Include a maximum boundary (inclusive).
71
+ ```ruby
72
+ appraisal_matrix(activesupport: { min: "6.1", max: "7.1" })
73
+ ```
74
+
75
+ #### Version step (Coming soon!)
76
+
77
+ Only test the latest release of each major version.
78
+ ```ruby
79
+ appraisal_matrix(activesupport: { min: "6.1", max: "7.1", step: :major })
80
+ ```
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/invoca/appraisal-matrix.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop", "~> 1.21"
10
+ gem "appraisal", "~> 2.2.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop", "~> 1.21"
10
+ gem "appraisal", "~> 2.3.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop", "~> 1.21"
10
+ gem "appraisal", "~> 2.4.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rubocop", "~> 1.21"
10
+ gem "appraisal", "~> 2.5.0"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'appraisal'
4
+ require 'appraisal/matrix/rubygems_helper'
5
+
6
+ module Appraisal::Matrix
7
+ module AppraiseFileWithMatrix
8
+ include RubygemsHelper
9
+
10
+ # appraisal_matrix(rails: "6.0")
11
+ # appraisal_matrix(rails: "6.0", sidekiq: "5")
12
+ # appraisal_matrix(rails: "6.0", sidekiq: { min: “5.0”, max: “6.0”, step: :major })
13
+ # appraisal_matrix(rails: "6.0") do
14
+ # gem "sqlite3", "~> 2.5"
15
+ # end
16
+ def appraisal_matrix(**kwargs, &block)
17
+ # names_and_versions_to_test
18
+ # [
19
+ # [[rails, 6.0], [rails, 6.1], [rails, 7.0], [rails, 7.1]],
20
+ # [[sidekiq, 1.0], [sidekiq, 2.0]],
21
+ # [[a, x], [a, y], [a, z]]
22
+ # ]
23
+ names_and_versions_to_test =
24
+ kwargs.map do |gem_name, version_request|
25
+ if version_request.is_a?(Hash)
26
+ raise "TODO: Version request options not implemented yet"
27
+ else
28
+ minimum_version = Gem::Version.new(version_request)
29
+ end
30
+
31
+ versions_to_test(gem_name, minimum_version).map do |version|
32
+ [gem_name, version]
33
+ end
34
+ end
35
+
36
+ # matrix
37
+ # [
38
+ # [[rails, 6.0], [sidekiq, 1.0], ...[a, x]]
39
+ # [[rails, 6.0], [sidekiq, 1.0], ...[a, y]]
40
+ # [[rails, 6.0], [sidekiq, 1.0], ...[a, z]]
41
+ # ...
42
+ # [[rails, 7.1], [sidekiq, 2.0], ...[a, z]]
43
+ # ]
44
+ matrix = names_and_versions_to_test[0].product(*names_and_versions_to_test[1..])
45
+
46
+ # Iterate over versions to test and create appraisal per
47
+ matrix.each do |appraisal_spec|
48
+ appraise appraisal_file_name(appraisal_spec) do
49
+ appraisal_spec.each do |gem_name, version|
50
+ gem gem_name, "~> #{version}.0"
51
+ end
52
+ instance_eval(&block) if block
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ # [["rails", "6.0"], ["sidekiq", "5"]]
60
+ # => "rails-6_0-sidekiq-5"
61
+ def appraisal_file_name(names_and_versions)
62
+ names_and_versions.map do |name, version|
63
+ "#{name}-#{version.gsub('.', '_')}"
64
+ end.join("-")
65
+ end
66
+ end
67
+ end
68
+
69
+ Appraisal::AppraisalFile.prepend(Appraisal::Matrix::AppraiseFileWithMatrix)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'open-uri'
5
+
6
+ module Appraisal
7
+ module Matrix
8
+ module RubygemsHelper
9
+ def versions_to_test(gem_name, minimum_version)
10
+ # Generate a set to store the versions to test against
11
+ versions_to_test = Set.new
12
+
13
+ # Load versions from rubygems api
14
+ URI.parse("https://rubygems.org/api/v1/versions/#{gem_name}.json").open do |raw_version_data|
15
+ JSON.parse(raw_version_data.read).each do |version_data|
16
+ version = Gem::Version.new(version_data['number'])
17
+ versions_to_test << version.segments[0..1].join('.') if version >= minimum_version && !version.prerelease?
18
+ end
19
+ end
20
+
21
+ versions_to_test
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appraisal
4
+ module Matrix
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "matrix/version"
4
+ require_relative "matrix/rubygems_helper"
5
+ require_relative "matrix/extensions/appraisal_file"
6
+
7
+ module Appraisal
8
+ module Matrix
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module Appraisal
2
+ module Matrix
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appraisal-matrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Drew Caddell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appraisal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ description: Appraisal file DSL for generating a matrix of gemfiles.
28
+ email:
29
+ - dcaddell@invoca.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Appraisals
37
+ - CHANGELOG.md
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - gemfiles/appraisal_2_2.gemfile
42
+ - gemfiles/appraisal_2_3.gemfile
43
+ - gemfiles/appraisal_2_4.gemfile
44
+ - gemfiles/appraisal_2_5.gemfile
45
+ - lib/appraisal/matrix.rb
46
+ - lib/appraisal/matrix/extensions/appraisal_file.rb
47
+ - lib/appraisal/matrix/rubygems_helper.rb
48
+ - lib/appraisal/matrix/version.rb
49
+ - sig/appraisal/matrix.rbs
50
+ homepage: https://github.com/invoca/appraisal-matrix
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ allowed_push_host: https://rubygems.org
55
+ homepage_uri: https://github.com/invoca/appraisal-matrix
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '3.0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.3.26
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Appraisal file DSL for generating a matrix of gemfiles.
75
+ test_files: []