Skip to content

Commit

Permalink
no point in matrix if shakapacker v6 doesn't support node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Jun 26, 2024
1 parent a694c99 commit 2a5d78d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 111 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ jobs:
examples:
env:
SKIP_YARN_COREPACK_CHECK: 0
strategy:
fail-fast: false
matrix:
versions: ['oldest', 'newest']
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand All @@ -32,12 +28,12 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.versions == 'oldest' && '3.0' || '3.3' }}
ruby-version: 3.3
bundler: 2.5.9
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.versions == 'oldest' && '16' || '20' }}
node-version: 20
- name: Print system information
run: |
echo "Linux release: "; cat /etc/issue
Expand All @@ -56,7 +52,7 @@ jobs:
uses: actions/cache@v3
with:
path: vendor/bundle
key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }}
key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-newest
- id: get-sha
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: Install Node modules with Yarn for renderer package
Expand All @@ -66,7 +62,7 @@ jobs:
- name: yalc publish for react-on-rails
run: yalc publish
- name: Dynamically add the right shakapacker version to the Gemfile
run: echo "gem 'shakapacker', '~> ${{ matrix.versions == 'oldest' && '6.6.0' || '8.0.0' }}'" >> Gemfile
run: echo "gem 'shakapacker', '~> 8.0.0'" >> Gemfile
- name: Install Ruby Gems for package
run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3
- name: Ensure minimum required Chrome version
Expand All @@ -85,7 +81,7 @@ jobs:
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- name: Main CI
if: steps.changed-files.outputs.any_changed == 'true'
run: bundle exec rake run_rspec:${{ matrix.versions == 'oldest' && 'web' || 'shaka' }}packer_examples
run: bundle exec rake run_rspec:examples
- name: Store test results
uses: actions/upload-artifact@v3
with:
Expand Down
27 changes: 20 additions & 7 deletions rakelib/example_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "rake"
require "pathname"

require_relative "task_helpers"

Expand All @@ -10,16 +11,19 @@ module ReactOnRails
module TaskHelpers
class ExampleType
def self.all
@all ||= {webpacker_examples: [], shakapacker_examples: []}
@all ||= []
end

attr_reader :packer_type, :name, :generator_options
def self.namespace_name
"examples"
end

attr_reader :name, :generator_options

def initialize(packer_type: nil, name: nil, generator_options: nil)
@packer_type = packer_type
def initialize(name: nil, generator_options: nil)
@name = name
@generator_options = generator_options
self.class.all[packer_type.to_sym] << self
self.class.all << self
end

def name_pretty
Expand All @@ -38,6 +42,15 @@ def gemfile
File.join(dir, "Gemfile")
end

# Gems we need to add to the Gemfile before bundle installing
def required_gems
relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(dir))
[
"gem 'react_on_rails', path: '#{relative_gem_root}'",
"gem 'shakapacker'"
]
end

# Options we pass when running `rails new` from the command-line.
attr_writer :rails_options

Expand All @@ -53,12 +66,12 @@ def rails_options
method_name_normal = "#{task_type}_task_name" # ex: `clean_task_name`
method_name_short = "#{method_name_normal}_short" # ex: `clean_task_name_short`

define_method(method_name_normal) { "#{@packer_type}:#{task_type}_#{name}" }
define_method(method_name_normal) { "#{self.class.namespace_name}:#{task_type}_#{name}" }
define_method(method_name_short) { "#{task_type}_#{name}" }
end

def rspec_task_name_short
"#{packer_type}_#{name}"
"example_#{name}"
end

def rspec_task_name
Expand Down
30 changes: 16 additions & 14 deletions rakelib/webpacker_examples.rake → rakelib/examples.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@

require "yaml"
require "rails/version"
require "pathname"

require_relative "example_type"
require_relative "task_helpers"

namespace :webpacker_examples do # rubocop:disable Metrics/BlockLength
namespace :examples do # rubocop:disable Metrics/BlockLength
include ReactOnRails::TaskHelpers
# Loads data from examples_config.yml and instantiates corresponding ExampleType objects
examples_config_file = File.expand_path("examples_config.yml", __dir__)
examples_config = symbolize_keys(YAML.safe_load_file(examples_config_file))
examples_config[:example_type_data].each do |example_type_data|
ExampleType.new(packer_type: "webpacker_examples", **symbolize_keys(example_type_data))
end
examples_config[:example_type_data].each { |example_type_data| ExampleType.new(**symbolize_keys(example_type_data)) }

# Define tasks for each example type
ExampleType.all[:webpacker_examples].each do |example_type|
relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(example_type.dir))
ExampleType.all.each do |example_type|
# CLOBBER
desc "Clobbers (deletes) #{example_type.name_pretty}"
task example_type.clobber_task_name_short do
Expand All @@ -33,15 +29,11 @@ namespace :webpacker_examples do # rubocop:disable Metrics/BlockLength
# GENERATE
desc "Generates #{example_type.name_pretty}"
task example_type.gen_task_name_short => example_type.clobber_task_name do
puts "Running webpacker_examples:#{example_type.gen_task_name_short}"
mkdir_p(example_type.dir)
example_type.rails_options += "--skip-javascript"
sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
sh_in_dir(example_type.dir, "touch .gitignore")
sh_in_dir(example_type.dir,
"echo \"gem 'react_on_rails', path: '#{relative_gem_root}'\" >> #{example_type.gemfile}")
sh_in_dir(example_type.dir, "echo \"gem 'shakapacker', '~> 6.6.0'\" >> #{example_type.gemfile}")
sh_in_dir(example_type.dir, "cat #{example_type.gemfile}")
append_to_gemfile(example_type.gemfile, example_type.required_gems)
bundle_install_in(example_type.dir)
sh_in_dir(example_type.dir, "rake webpacker:install")
sh_in_dir(example_type.dir, example_type.generator_shell_commands)
Expand All @@ -55,8 +47,18 @@ namespace :webpacker_examples do # rubocop:disable Metrics/BlockLength
end

desc "Generates all example apps"
task gen_all: ExampleType.all[:webpacker_examples].map(&:gen_task_name)
task gen_all: ExampleType.all.map(&:gen_task_name)
end

desc "Generates all example apps. Run `rake -D examples` to see all available options"
task webpacker_examples: ["webpacker_examples:gen_all"]
task examples: ["examples:gen_all"]

private

# Appends each string in an array as a new line of text in the given Gemfile.
# Automatically adds line returns.
def append_to_gemfile(gemfile, lines)
old_text = File.read(gemfile)
new_text = lines.reduce(old_text) { |a, e| a << "#{e}\n" }
File.open(gemfile, "w") { |f| f.puts(new_text) }
end
24 changes: 5 additions & 19 deletions rakelib/run_rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,16 @@ namespace :run_rspec do
end

# Dynamically define Rake tasks for each example app found in the examples directory
ExampleType.all[:webpacker_examples].each do |example_type|
ExampleType.all.each do |example_type|
desc "Runs RSpec for #{example_type.name_pretty} only"
task example_type.rspec_task_name_short => example_type.gen_task_name do
run_tests_in(File.join(examples_dir, example_type.name)) # have to use relative path
end
end

# Dynamically define Rake tasks for each example app found in the examples directory
ExampleType.all[:shakapacker_examples].each do |example_type|
desc "Runs RSpec for #{example_type.name_pretty} only"
task example_type.rspec_task_name_short => example_type.gen_task_name do
run_tests_in(File.join(examples_dir, example_type.name)) # have to use relative path
end
end

desc "Runs Rspec for webpacker example apps only"
task webpacker_examples: "webpacker_examples:gen_all" do
ExampleType.all[:webpacker_examples].each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
end

desc "Runs Rspec for shakapacker example apps only"
task shakapacker_examples: "shakapacker_examples:gen_all" do
ExampleType.all[:shakapacker_examples].each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
desc "Runs Rspec for example apps only"
task examples: "examples:gen_all" do
ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
end

Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
Expand All @@ -69,8 +56,7 @@ namespace :run_rspec do
end

desc "run all tests"
task :run_rspec, [:packer] => ["all_but_examples"] do
Rake::Task["run_rspec:#{packer}_examples"].invoke
task run_rspec: %i[all_but_examples examples] do
puts "Completed all RSpec tests"
end
end
Expand Down
62 changes: 0 additions & 62 deletions rakelib/shakapacker_examples.rake

This file was deleted.

0 comments on commit 2a5d78d

Please sign in to comment.