Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tombruijn committed Jul 1, 2024
1 parent e3f7011 commit 8520a82
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 195 deletions.
208 changes: 208 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# DO NOT EDIT
# This is a generated file by the `rake build_matrix:github:generate` task.
# See `build_matrix.yml` for the build matrix.
# Generate this file with `rake build_matrix:github:generate`.
---
name: Ruby gem CI
'on':
push:
branches:
- main
- develop
- github-actions
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
lint-git:
name: Git linter (Lintje)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Git linter
uses: lintje/[email protected]
lint-style:
name: Ruby style linter (RuboCop)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop
validation:
name: Validation of CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: rake build_matrix:github:validate
integration_tests:
name: Diagnose integration tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- run: spec/integration/diagnose/bin/test
env:
LANGUAGE: ruby
ruby_2.7.8:
name: Ruby 2.7.8
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.8
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
ruby_3.0.5:
name: Ruby 3.0.5
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.5
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
ruby_3.1.3:
name: Ruby 3.1.3
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.3
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
ruby_3.2.1:
name: Ruby 3.2.1
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.1
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
ruby_3.3.1:
name: Ruby 3.3.1
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.1
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
ruby_jruby-9.4.1.0:
name: Ruby jruby-9.4.1.0
needs: validation
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: jruby-9.4.1.0
bundler-cache: true
- name: Install gem extension
run: "./support/bundler_wrapper exec rake extension:install"
- name: Print extension install report
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
file found'"
- name: Print Makefile log file
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
found'"
- name: Run tests for no_dependencies
env: {}
run: "./support/bundler_wrapper exec rake test"
- name: Run tests without extension
run: "./support/bundler_wrapper exec rake test:failure"
122 changes: 67 additions & 55 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,37 @@ VERSION_MANAGERS = {
}
}.freeze

def env_map(key, value)
{
"name" => key,
"value" => value
}
end

def build_task(matrix, ruby_version, type = nil)
def build_job(_matrix, ruby_version, type = nil)
{
"name" => "Ruby #{ruby_version}#{type ? " - #{type}" : nil}",
"dependencies" => ["Validation"],
"task" => {
"prologue" => matrix["prologue"].merge(
"commands" => matrix["prologue"]["commands"] + [
"./support/bundler_wrapper exec rake extension:install",
"[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report file found'", # rubocop:disable Layout/LineLength
"[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file found'"
]
),
"epilogue" => matrix["epilogue"],
"jobs" => []
}
"needs" => "validation",
"runs-on" => "ubuntu-latest",
"steps" => [
{
"name" => "Check out repository",
"uses" => "actions/checkout@v4"
},
{
"name" => "Install Ruby",
"uses" => "ruby/setup-ruby@v1",
"with" => {
"ruby-version" => ruby_version,
"bundler-cache" => true
}
},
{
"name" => "Install gem extension",
"run" => "./support/bundler_wrapper exec rake extension:install"
},
{
"name" => "Print extension install report",
"run" => "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report file found'" # rubocop:disable Layout/LineLength
},
{
"name" => "Print Makefile log file",
"run" => "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file found'"
}
]
}
end

Expand All @@ -50,62 +59,65 @@ def gems_with_gemfiles
end

namespace :build_matrix do
namespace :semaphore do
namespace :github do
task :generate do
yaml = YAML.load_file("build_matrix.yml")
matrix = yaml["matrix"]
defaults = matrix["defaults"]
semaphore = yaml["semaphore"]
github = yaml["github"]

builds = []
builds = {}
matrix["ruby"].each do |ruby|
ruby_version = ruby["ruby"]
ruby_primary_block = build_task(matrix, ruby_version)
ruby_secondary_block = build_task(matrix, ruby_version, "Gems").tap do |t|
t["dependencies"] = ["Ruby #{ruby_version}"]
end
ruby_primary_block = build_job(matrix, ruby_version)
# ruby_secondary_block = build_task(matrix, ruby_version, "Gems").tap do |t|
# t["dependencies"] = ["Ruby #{ruby_version}"]
# end
gemset_for_ruby(ruby, matrix).each do |gem|
next unless included_for_ruby?(matrix, gem, ruby)

env = matrix["env_vars"] + [
env_map("RUBY_VERSION", ruby_version),
env_map("GEMSET", gem["gem"]),
env_map("BUNDLE_GEMFILE", "gemfiles/#{gem["gem"]}.gemfile")
]
rubygems = gem["rubygems"] || ruby["rubygems"] || defaults["rubygems"]
env << env_map("_RUBYGEMS_VERSION", rubygems) if rubygems
bundler = gem["bundler"] || ruby["bundler"] || defaults["bundler"]
env << env_map("_BUNDLER_VERSION", bundler) if bundler

job = {
"name" => "Ruby #{ruby_version} for #{gem["gem"]}",
"env_vars" => env + ruby.fetch("env_vars", []),
"commands" => [
"./support/bundler_wrapper exec rake test"
]
env = {}
# env = matrix["env"].merge(
# "RUBY_VERSION" => ruby_version,
# "GEMSET" => gem["gem"],
# "BUNDLE_GEMFILE" => "gemfiles/#{gem["gem"]}.gemfile"
# )
# rubygems = gem["rubygems"] || ruby["rubygems"] || defaults["rubygems"]
# env = env.merge("_RUBYGEMS_VERSION" => rubygems) if rubygems
# bundler = gem["bundler"] || ruby["bundler"] || defaults["bundler"]
# env = env.merge("_BUNDLER_VERSION" => bundler) if bundler

step = {
"name" => "Run tests for #{gem["gem"]}",
"env" => env.merge(ruby.fetch("env", {})),
"run" => "./support/bundler_wrapper exec rake test"
}
if gem["gem"] == "no_dependencies"
ruby_primary_block["steps"] << step
# Only test the failure scenarios once per Ruby version
job["commands"] << "./support/bundler_wrapper exec rake test:failure"
ruby_primary_block["task"]["jobs"] << job
ruby_primary_block["steps"] << {
"name" => "Run tests without extension",
"run" => "./support/bundler_wrapper exec rake test:failure"
}
else
ruby_secondary_block["task"]["jobs"] << job
# ruby_secondary_block["task"]["jobs"] << job
end
end
builds << ruby_primary_block
builds << ruby_secondary_block if ruby_secondary_block["task"]["jobs"].count.nonzero?
builds["ruby_#{ruby["ruby"]}"] = ruby_primary_block
# builds << ruby_secondary_block if ruby_secondary_block["task"]["jobs"].count.nonzero?
end
semaphore["blocks"] += builds
github["jobs"] = github["jobs"].merge(builds)

header = "# DO NOT EDIT\n" \
"# This is a generated file by the `rake build_matrix:semaphore:generate` task.\n" \
"# This is a generated file by the `rake build_matrix:github:generate` task.\n" \
"# See `build_matrix.yml` for the build matrix.\n" \
"# Generate this file with `rake build_matrix:semaphore:generate`.\n"
generated_yaml = header + YAML.dump(semaphore)
File.write(".semaphore/semaphore.yml", generated_yaml)
puts "Generated `.semaphore/semaphore.yml`"
"# Generate this file with `rake build_matrix:github:generate`.\n"
generated_yaml = header + YAML.dump(github)
filename = ".github/workflows/ci.yml"
File.write(filename, generated_yaml)
puts "Generated `#{filename}`"
puts "Task count: #{builds.length}"
puts "Job count: #{builds.sum { |block| block["task"]["jobs"].count }}"
puts "Job count: #{github["jobs"].count}"
end

task :validate => :generate do
Expand Down
Loading

0 comments on commit 8520a82

Please sign in to comment.