appraisal-matrix 0.1.0 → 0.3.0.pre.tstarck.1

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: 455050798ee698fa03781e94f45ea46774dfaacb293c0634346d25a0ffce067c
4
+ data.tar.gz: 818a60d1519378825f5bd40a564328d7c3440e5ce8cdbc26af9b9d6dda058b29
5
5
  SHA512:
6
- metadata.gz: 4a1d81416bbc19307d92feaf5df8f24d232863ad1325793fb15097a4021c458eb619bb5e997043df9e5ec2eab42392440a0ba79cbf36e8f8bad927f0ae94dfb7
7
- data.tar.gz: 81e255ddd188a08b97a81b6f5d4fefb558c20c884df44b10540cd6b4240717ad28519210b0dc24e9ee9347eb4e70b99f9e39c989a983d2c50b511acf8b281138
6
+ metadata.gz: 36660df655d219bbfb64b5f67c0bbd31718132d10adab5dccf28e1001e59340e41f18cc2a83493bb3be555d6f64a98ce5d36f4ccb1ce10cc744450a77bc38068
7
+ data.tar.gz: d4587264eec3f603cecc0b6fb1585dbe4769aefbfcb128a7b7e7c19b898c2b6acc95c097e8101f2d86c08004fdacb32ea12cc9dc54c4a7e27d16621f6a6b3da1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.6
data/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@ 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.3.0 - Unreleased
7
+ ### Changed
8
+ - Changed the block passed to `appraisal_matrix` to be called with the versions of gems for the current matrix entry.
9
+
10
+ ## 0.2.0 - 2024-07-09
11
+ ### Added
12
+ - Support special request options for `appraisal_matrix`:
13
+ - `versions`: An array of version restriction strings.
14
+ - `step`: The granularity of a release to be included in the matrix. Allowed to be :major, :minor, or :patch.
15
+
16
+ ## [0.1.0] - 2024-06-26
7
17
  ### Added
8
18
  - Add an extension to the Appraisal gem that provides an interface for generating a matrix of appraisals.
data/README.md CHANGED
@@ -53,6 +53,18 @@ appraisal_matrix(activesupport: "6.1") do
53
53
  end
54
54
  ```
55
55
 
56
+ #### Block arguments
57
+ If you would like to setup conditional logic based off of the versions of the gems in the matrix, you can pass a block with arguments to `appraisal_matrix`.
58
+
59
+ ```ruby
60
+ appraisal_matrix(activesupport: "6.1") do |activesupport:, sidekiq:|
61
+ # activesupport <Gem::Version>
62
+ if activesupport < "7"
63
+ remove_gem 'test_after_commit'
64
+ end
65
+ end
66
+ ```
67
+
56
68
  ### Appraising more than one Gem
57
69
 
58
70
  You can also pass more than one gem to `appraisal_matrix` to create a matrix of all combinations of the specified gems.
@@ -65,18 +77,27 @@ appraisal_matrix(activesupport: "6.1", sidekiq: "7.0")
65
77
 
66
78
  In addition to specifying the minimum requested version, users will be able to make additional version requests.
67
79
 
68
- #### Maximum version (Coming soon!)
80
+ #### Additional version restrictions
69
81
 
70
- Include a maximum boundary (inclusive).
82
+ Include additional version boundaries. Either include the requirement strings as an array or pass the `versions` key to the options hash.
71
83
  ```ruby
72
- appraisal_matrix(activesupport: { min: "6.1", max: "7.1" })
84
+ appraisal_matrix(activesupport: [">= 6.1", "< 7.1"])
85
+ appraisal_matrix(activesupport: ["~> 6.0", "!= 6.1.0"])
86
+ appraisal_matrix(activesupport: { versions: ["> 6.1.1"] })
73
87
  ```
74
88
 
75
- #### Version step (Coming soon!)
89
+ #### Version step
90
+
91
+ The default operation is to test against each minor version. You can choose to be more or less inclusive when necessary.
76
92
 
77
93
  Only test the latest release of each major version.
78
94
  ```ruby
79
- appraisal_matrix(activesupport: { min: "6.1", max: "7.1", step: :major })
95
+ appraisal_matrix(activesupport: { versions: [">= 6.1", "< 7.1"], step: :major })
96
+ ```
97
+
98
+ Or include all patch releases
99
+ ```ruby
100
+ appraisal_matrix(activesupport: { versions: [">= 6.1", "< 7.1"], step: :patch })
80
101
  ```
81
102
 
82
103
  ## 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,41 @@ 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
36
+ # appraisal_matrix(rails: "6.0", sidekiq: "5.0") do |rails:, sidekiq:|
37
+ # if rails < "7"
38
+ # # do something...
39
+ # else
40
+ # # do something else...
41
+ # end
42
+ # end
16
43
  def appraisal_matrix(**kwargs, &block)
17
44
  # names_and_versions_to_test
18
45
  # [
@@ -21,14 +48,21 @@ module Appraisal::Matrix
21
48
  # [[a, x], [a, y], [a, z]]
22
49
  # ]
23
50
  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
51
+ kwargs.map do |gem_name, version_options|
52
+ version_array =
53
+ case version_options
54
+ when String
55
+ parsed_options = version_options.include?(" ") ? [version_options] : [">= #{version_options}"]
56
+ VersionArray.new(gem_name: gem_name, versions: parsed_options)
57
+ when Integer, Float
58
+ VersionArray.new(gem_name: gem_name, versions: [">= #{version_options}"])
59
+ when Array
60
+ VersionArray.new(gem_name: gem_name, versions: version_options)
61
+ when Hash
62
+ VersionArray.new(gem_name: gem_name, **version_options)
63
+ end
30
64
 
31
- versions_to_test(gem_name, minimum_version).map do |version|
65
+ version_array.versions.map do |version|
32
66
  [gem_name, version]
33
67
  end
34
68
  end
@@ -49,7 +83,10 @@ module Appraisal::Matrix
49
83
  appraisal_spec.each do |gem_name, version|
50
84
  gem gem_name, "~> #{version}.0"
51
85
  end
52
- instance_eval(&block) if block
86
+ if block
87
+ block_args = appraisal_spec.to_h { |gem_name, version| [gem_name.to_sym, Gem::Version.new(version)] }
88
+ instance_exec(**block_args, &block)
89
+ end
53
90
  end
54
91
  end
55
92
  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.3.0.pre.tstarck.1"
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.3.0.pre.tstarck.1
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-15 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
@@ -64,11 +66,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
66
  version: '3.0'
65
67
  required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
- - - ">="
69
+ - - ">"
68
70
  - !ruby/object:Gem::Version
69
- version: '0'
71
+ version: 1.3.1
70
72
  requirements: []
71
- rubygems_version: 3.3.26
73
+ rubygems_version: 3.2.33
72
74
  signing_key:
73
75
  specification_version: 4
74
76
  summary: Appraisal file DSL for generating a matrix of gemfiles.