From 8520a82f8221c3150f18ddf6375944758ce7cf0b Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Mon, 1 Jul 2024 16:25:47 +0200 Subject: [PATCH] WIP --- .github/workflows/ci.yml | 208 +++++++++++++++++++++++++++++++++++++++ Rakefile | 122 ++++++++++++----------- build_matrix.yml | 199 +++++++++++-------------------------- 3 files changed, 334 insertions(+), 195 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..cfff26823 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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/action@v0.11 + 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" diff --git a/Rakefile b/Rakefile index 0c57b0db7..33685613d 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 diff --git a/build_matrix.yml b/build_matrix.yml index c9cc0d73b..97f768558 100644 --- a/build_matrix.yml +++ b/build_matrix.yml @@ -1,149 +1,68 @@ -semaphore: # Default `.semaphore/semaphore.yml` contents - version: v1.0 - name: AppSignal Ruby Build and Tests +github: + name: Ruby gem CI + "on": + push: + branches: + - "main" + - "develop" + - "github-actions" + pull_request: + types: + - opened + - reopened + - synchronize - agent: - machine: - type: e1-standard-2 - os_image: ubuntu2004 + jobs: + lint-git: + name: "Git linter (Lintje)" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch depth is required + - name: "Run Git linter" + uses: lintje/action@v0.11 - # Cancel all running and queued workflows before this one - auto_cancel: - running: - # Ignore main AND develop branch as we want it to build all workflows - when: "branch != 'main' AND branch != 'develop'" + 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 - global_job_config: - env_vars: - - name: RUNNING_IN_CI - value: "true" - - name: _BUNDLER_CACHE - value: "v3" - - name: _GEMS_CACHE - value: "v3" - prologue: - commands: - - checkout - - rm -f $HOME/.rbenv/plugins/rbenv-gem-rehash/etc/rbenv.d/exec/~gem-rehash.bash - - | - if [ -n "$RUBY_VERSION" ]; then - if ! (sem-version ruby "$RUBY_VERSION"); then - ruby_key="rbenv-ruby-$RUBY_VERSION" - echo "Attempting to build Ruby $RUBY_VERSION from source" - git -C "$HOME/.rbenv/plugins/ruby-build" pull - cache restore "$ruby_key" - sem-version ruby "$RUBY_VERSION" - if ! cache has_key "$ruby_key"; then - cache store "$ruby_key" "$HOME/.rbenv/versions/$RUBY_VERSION" - fi - fi - ./support/check_versions - else - echo Skipping Ruby install - fi + 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 - blocks: - - name: Validation - dependencies: [] - task: - prologue: - commands: - - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - ./support/bundler_wrapper install --jobs=3 --retry=3 - jobs: - - name: Validate CI setup - env_vars: - - name: RUBY_VERSION - value: 3.2.2 - - name: GEMSET - value: no_dependencies - - name: BUNDLE_GEMFILE - value: Gemfile - commands: - - ./support/bundler_wrapper exec rake build_matrix:semaphore:validate - epilogue: - on_pass: - commands: - - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) .bundle - - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) $HOME/.gem - - name: Ruby linters - dependencies: [] - task: - prologue: - commands: - - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - ./support/bundler_wrapper install --jobs=3 --retry=3 - jobs: - - name: RuboCop - env_vars: - - name: RUBY_VERSION - value: 3.2.2 - - name: GEMSET - value: no_dependencies - - name: BUNDLE_GEMFILE - value: Gemfile - commands: - - ./support/bundler_wrapper exec rubocop - epilogue: - on_pass: - commands: - - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) .bundle - - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) $HOME/.gem - - name: Other linters - dependencies: [] - task: - jobs: - - name: Git Lint (Lintje) - commands: - - script/lint_git - - name: Integration tests - dependencies: - - Validation - task: - prologue: - commands: - - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-diagnose-$(checksum Gemfile) - - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-diagnose-$(checksum Gemfile) - - ./support/bundler_wrapper install --jobs=3 --retry=3 - - ./support/bundler_wrapper exec rake extension:install - - "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report file found'" - - "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file found'" - - git submodule init - - git submodule update - jobs: - - name: Diagnose - env_vars: - - name: RUBY_VERSION - value: 3.0.2 - - name: LANGUAGE - value: ruby - commands: - - spec/integration/diagnose/bin/test - epilogue: - on_pass: - commands: - - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-diagnose-$(checksum Gemfile) .bundle - - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-diagnose-$(checksum Gemfile) $HOME/.gem + 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 matrix: - env_vars: # Shared for all jobs in the build matrix - - name: BUNDLE_PATH - value: "../.bundle/" - - name: RAILS_ENV - value: "test" - - name: JRUBY_OPTS - value: "" - - name: COV - value: "1" - prologue: # Shared for all jobs in the build matrix - commands: - - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) - - ./support/install_deps - - bundle config set clean 'true' - - ./support/bundler_wrapper install --jobs=3 --retry=3 + env: # Shared for all jobs in the build matrix + BUNDLE_PATH: "../.bundle/" + RAILS_ENV: "test" + JRUBY_OPTS: "" + COV: "1" epilogue: # Shared for all jobs in the build matrix on_pass: commands: