appraisal-matrix 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a15e1a8f3f0f52235bc85e749b73a4fcf753393281f59ef10ce53033caa3a83b
4
- data.tar.gz: 0b097af634a61f3bad05e7513a28902fba3516ed17c23fbb3add3bb35135bf5c
3
+ metadata.gz: 5bc730eb59878944e9b078ee6486cfc104df8f820660a3b2f5f11b02c2d5b735
4
+ data.tar.gz: 7e13b5cb6866609568f7b30e62bbea9ed0120fcc107f1d73efebc1231316c22e
5
5
  SHA512:
6
- metadata.gz: 4a1d81416bbc19307d92feaf5df8f24d232863ad1325793fb15097a4021c458eb619bb5e997043df9e5ec2eab42392440a0ba79cbf36e8f8bad927f0ae94dfb7
7
- data.tar.gz: 81e255ddd188a08b97a81b6f5d4fefb558c20c884df44b10540cd6b4240717ad28519210b0dc24e9ee9347eb4e70b99f9e39c989a983d2c50b511acf8b281138
6
+ metadata.gz: d7e535ac299153fa96e41ba82924cd6160cfb9711554ef1a6741a1bad21f2b1872a81caefcf57af64fd966bc9576123fcdc7efb60793bb8378174bdbfa0740ce
7
+ data.tar.gz: cde84bde53c7dcae15b1311c63847536c34793b501ee3bfc62e536d6563dc30a9c4db7986344560184c85fc53af612cf8652801560eeee98fe8cfaef8fe1d15c
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.6
data/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
4
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
- ## [0.1.0] - Unreleased
6
+ ## 0.2.0 - 2024-07-09
7
+ ### Added
8
+ - Support special request options for `appraisal_matrix`:
9
+ - `versions`: An array of version restriction strings.
10
+ - `step`: The granularity of a release to be included in the matrix. Allowed to be :major, :minor, or :patch.
11
+
12
+ ## [0.1.0] - 2024-06-26
7
13
  ### Added
8
14
  - Add an extension to the Appraisal gem that provides an interface for generating a matrix of appraisals.
data/README.md CHANGED
@@ -65,18 +65,27 @@ appraisal_matrix(activesupport: "6.1", sidekiq: "7.0")
65
65
 
66
66
  In addition to specifying the minimum requested version, users will be able to make additional version requests.
67
67
 
68
- #### Maximum version (Coming soon!)
68
+ #### Additional version restrictions
69
69
 
70
- Include a maximum boundary (inclusive).
70
+ Include additional version boundaries. Either include the requirement strings as an array or pass the `versions` key to the options hash.
71
71
  ```ruby
72
- appraisal_matrix(activesupport: { min: "6.1", max: "7.1" })
72
+ appraisal_matrix(activesupport: [">= 6.1", "< 7.1"])
73
+ appraisal_matrix(activesupport: ["~> 6.0", "!= 6.1.0"])
74
+ appraisal_matrix(activesupport: { versions: ["> 6.1.1"] })
73
75
  ```
74
76
 
75
- #### Version step (Coming soon!)
77
+ #### Version step
78
+
79
+ The default operation is to test against each minor version. You can choose to be more or less inclusive when necessary.
76
80
 
77
81
  Only test the latest release of each major version.
78
82
  ```ruby
79
- appraisal_matrix(activesupport: { min: "6.1", max: "7.1", step: :major })
83
+ appraisal_matrix(activesupport: { versions: [">= 6.1", "< 7.1"], step: :major })
84
+ ```
85
+
86
+ Or include all patch releases
87
+ ```ruby
88
+ appraisal_matrix(activesupport: { versions: [">= 6.1", "< 7.1"], step: :patch })
80
89
  ```
81
90
 
82
91
  ## Development
data/catalog-info.yaml ADDED
@@ -0,0 +1,31 @@
1
+ # This file is partially auto-generated by the invoca-backstage-tools gem
2
+ # The following fields should not be edited manually as they are auto-generated
3
+ # based on the contents of the repo:
4
+ # - metadata.name
5
+ # - metadata.title
6
+ # - metadata.description
7
+ # - annotations.github.com/project-slug
8
+ # - invoca.com/version-repository-location
9
+ # - invoca.com/version-repository-name
10
+ # - spec.type
11
+ # - spec.owner
12
+ ---
13
+ apiVersion: backstage.io/v1alpha1
14
+ kind: Component
15
+ metadata:
16
+ name: appraisal-matrix-gem
17
+ title: Appraisal::Matrix
18
+ description: Appraisal file DSL for generating a matrix of gemfiles.
19
+ tags:
20
+ - ruby
21
+ - gem
22
+ annotations:
23
+ buildkite.com/project-slug: invoca/appraisal-matrix
24
+ github.com/project-slug: invoca/appraisal-matrix
25
+ invoca.com/version-repository-location: rubygems
26
+ invoca.com/version-repository-name: appraisal-matrix
27
+ spec:
28
+ type: library
29
+ lifecycle: production
30
+ owner: octothorpe
31
+ dependsOn: []
@@ -5,14 +5,34 @@ require 'appraisal/matrix/rubygems_helper'
5
5
 
6
6
  module Appraisal::Matrix
7
7
  module AppraiseFileWithMatrix
8
- include RubygemsHelper
9
8
 
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
9
+ class VersionArray
10
+ SUPPORTED_VERSION_STEPS = [:major, :minor, :patch].freeze
11
+
12
+ attr_reader :gem_name, :version_requirements, :step
13
+
14
+ def initialize(gem_name:, versions:, step: :minor)
15
+ SUPPORTED_VERSION_STEPS.include?(step) or raise("Unsupported version step: #{step}")
16
+
17
+ @gem_name = gem_name
18
+ @version_requirements = Gem::Requirement.new(versions)
19
+ @step = step.to_sym
20
+ end
21
+
22
+ def versions
23
+ RubygemsHelper.versions_to_test(gem_name, version_requirements, step)
24
+ end
25
+ end
26
+
27
+ # Define a matrix of appraisals to test against
28
+ # Expected usage:
29
+ # appraisal_matrix(rails: "6.0")
30
+ # appraisal_matrix(rails: "> 6.0.3")
31
+ # appraisal_matrix(rails: [">= 6.0", "< 7.1"])
32
+ # appraisal_matrix(rails: { versions: [">= 6.0", "< 7.1"], step: "major" })
33
+ # appraisal_matrix(rails: "6.0") do
34
+ # gem "sqlite3", "~> 2.5"
35
+ # end
16
36
  def appraisal_matrix(**kwargs, &block)
17
37
  # names_and_versions_to_test
18
38
  # [
@@ -21,14 +41,21 @@ module Appraisal::Matrix
21
41
  # [[a, x], [a, y], [a, z]]
22
42
  # ]
23
43
  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
44
+ kwargs.map do |gem_name, version_options|
45
+ version_array =
46
+ case version_options
47
+ when String
48
+ parsed_options = version_options.include?(" ") ? [version_options] : [">= #{version_options}"]
49
+ VersionArray.new(gem_name: gem_name, versions: parsed_options)
50
+ when Integer, Float
51
+ VersionArray.new(gem_name: gem_name, versions: [">= #{version_options}"])
52
+ when Array
53
+ VersionArray.new(gem_name: gem_name, versions: version_options)
54
+ when Hash
55
+ VersionArray.new(gem_name: gem_name, **version_options)
56
+ end
30
57
 
31
- versions_to_test(gem_name, minimum_version).map do |version|
58
+ version_array.versions.map do |version|
32
59
  [gem_name, version]
33
60
  end
34
61
  end
@@ -5,20 +5,46 @@ require 'open-uri'
5
5
 
6
6
  module Appraisal
7
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?
8
+ class RubygemsHelper
9
+ class << self
10
+ # Returns a set of versions to test against for a given gem.
11
+ #
12
+ # @param gem_name [String, Symbol] The name of the gem.
13
+ # @param version_requirement [Gem::Requirement] The version requirement for the gem.
14
+ # @param step [Symbol] The step value.
15
+ #
16
+ # @return [Set] A set of versions to test against.
17
+ def versions_to_test(gem_name, version_requirement, step)
18
+ # Generate a set to store the versions to test against
19
+ versions_to_test = Set.new
20
+
21
+ # Load versions from rubygems api
22
+ URI.parse("https://rubygems.org/api/v1/versions/#{gem_name}.json").open do |raw_version_data|
23
+ JSON.parse(raw_version_data.read).each do |version_data|
24
+ version = Gem::Version.new(version_data['number'])
25
+ versions_to_test << version_for_step(version, step) if include_version?(version, version_requirement)
26
+ end
18
27
  end
28
+
29
+ versions_to_test
19
30
  end
20
31
 
21
- versions_to_test
32
+ private
33
+
34
+ SEGMENT_STEP_SIZES = {
35
+ major: 1,
36
+ minor: 2,
37
+ patch: 3
38
+ }.freeze
39
+
40
+ def version_for_step(version, step)
41
+ size_for_step = SEGMENT_STEP_SIZES[step] or raise ArgumentError, "unsupported requested version step: #{step}, expected #{SEGMENT_STEP_SIZES.keys}"
42
+ version.segments.first(size_for_step).join(".")
43
+ end
44
+
45
+ def include_version?(version, version_requirement)
46
+ !version.prerelease? && version_requirement.satisfied_by?(version)
47
+ end
22
48
  end
23
49
  end
24
50
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Appraisal
4
4
  module Matrix
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appraisal-matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Caddell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-26 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -33,11 +33,13 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".rspec"
35
35
  - ".rubocop.yml"
36
+ - ".ruby-version"
36
37
  - Appraisals
37
38
  - CHANGELOG.md
38
39
  - LICENSE.txt
39
40
  - README.md
40
41
  - Rakefile
42
+ - catalog-info.yaml
41
43
  - gemfiles/appraisal_2_2.gemfile
42
44
  - gemfiles/appraisal_2_3.gemfile
43
45
  - gemfiles/appraisal_2_4.gemfile
@@ -68,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
70
  - !ruby/object:Gem::Version
69
71
  version: '0'
70
72
  requirements: []
71
- rubygems_version: 3.3.26
73
+ rubygems_version: 3.3.27
72
74
  signing_key:
73
75
  specification_version: 4
74
76
  summary: Appraisal file DSL for generating a matrix of gemfiles.