File: ci-matrix

package info (click to toggle)
ruby-will-paginate 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: ruby: 2,940; sh: 50; makefile: 2
file content (43 lines) | stat: -rwxr-xr-x 1,251 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require "yaml"

ci_config = File.expand_path('../../.github/workflows/test.yml', __FILE__)
data = YAML.load(File.read(ci_config))
matrix = data.dig('jobs', 'test-rails', 'strategy', 'matrix')
ruby_versions = matrix.fetch('ruby')
gemfiles = matrix.fetch('gemfile')

requirements = {
  'environments/Gemfile.rails5.0.rb'    => ['>= 2.2', '< 3.0'],
  'environments/Gemfile.rails5.1.rb'    => ['>= 2.2', '< 3.0'],
  'environments/Gemfile.rails5.2.rb'    => ['>= 2.2', '< 3.0'],
  'environments/Gemfile.rails6.0.rb'    => '>= 2.5',
  'Gemfile'                             => '>= 2.5',
  'environments/Gemfile.rails-edge.rb'  => '>= 2.7',
}

commands = {}

commands['excludes'] = -> {
  excludes = []
  gemfiles.each do |gemfile|
    req = Gem::Requirement.new(requirements.fetch(gemfile))
    ruby_versions.each do |version|
      unless req.satisfied_by?(Gem::Version.new(version))
        excludes << { 'ruby' => version, 'gemfile' => gemfile }
      end
    end
  end

  matrix['exclude'] = excludes
  File.open(ci_config, 'w') do |file|
    yaml_str = YAML.dump(data)
    file.write(yaml_str)
  end
}

cmd = commands.fetch(ARGV[0]) do
  $stderr.puts "available commands: #{commands.keys.join(', ')}"
  exit 1
end
cmd.(*ARGV[1..-1])