From e1361eedc9063e7bf124d01b1a363d46e8233b96 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 29 Dec 2023 15:12:55 +0100 Subject: [PATCH 1/2] Split the rake file in themed task files --- Gemfile | 1 + Rakefile | 91 ++------------------------------------------ tasks/cleaning.rake | 7 ++++ tasks/releasing.rake | 23 +++++++++++ tasks/testing.rake | 53 ++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 88 deletions(-) create mode 100644 tasks/cleaning.rake create mode 100644 tasks/releasing.rake create mode 100644 tasks/testing.rake diff --git a/Gemfile b/Gemfile index 61ba1d2d3e3..418d2955a5e 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,7 @@ gem 'rspec-rails', '~> 6.0.3', require: false gem 'rspec-retry', '~> 0.6.2', require: false gem 'simplecov', require: false gem 'simplecov-cobertura', require: false +gem 'rake', require: false, groups: [:lint, :release] gem 'rails-controller-testing', require: false gem 'puma', '< 6', require: false gem 'i18n-tasks', '~> 0.9', require: false diff --git a/Rakefile b/Rakefile index f352bc442ee..64473d43214 100644 --- a/Rakefile +++ b/Rakefile @@ -1,90 +1,5 @@ # frozen_string_literal: true -require 'bundler' -require 'bundler/gem_tasks' - -task default: :spec - -def print_title(gem_name = '') - title = ["Solidus", gem_name].join(' ').strip - puts "\n#{'-' * title.size}\n#{title}\n#{'-' * title.size}" -end - -def subproject_task(project, task, title: project, task_name: nil) - task_name ||= "#{task}:#{project}" - task task_name do - print_title(title) - Dir.chdir("#{File.dirname(__FILE__)}/#{project}") do - sh "rake #{task}" - end - end -end - -%w[spec db:drop db:create db:migrate db:reset].each do |task| - %w(api backend core frontend sample).each do |project| - desc "Run specs for #{project}" if task == 'spec' - subproject_task(project, task) - end - - desc "Run rake #{task} for each Solidus engine" - task task => %w(api backend core frontend sample).map { |p| "#{task}:#{p}" } -end - -desc "Run backend JS specs" -subproject_task("backend", "spec:js", title: "backend JS", task_name: "spec:backend:js") - -# Add backend JS specs to `rake spec` dependencies -task spec: 'spec:backend:js' - -task test: :spec -task test_app: 'db:reset' - -desc "clean the whole repository by removing all the generated files" -task :clean do - rm_f "Gemfile.lock" - rm_rf "sandbox" - rm_rf "pkg" - - %w(api backend core frontend sample).each do |gem_name| - print_title(gem_name) - rm_f "#{gem_name}/Gemfile.lock" - rm_rf "#{gem_name}/pkg" - rm_rf "#{gem_name}/spec/dummy" - end -end - -SOLIDUS_GEM_NAMES = %w[core api backend sample] - -%w[build install].each do |task_name| - desc "Run rake #{task} for each Solidus gem" - task task_name do - SOLIDUS_GEM_NAMES.each do |gem_name| - cd(gem_name) { sh "rake #{task_name}" } - end - end -end - -# We need to redefine release task to skip creating and pushing git tag -Rake::Task["release"].clear -desc "Build and push solidus gems to RubyGems" -task "release" => ["build", "release:guard_clean", "release:rubygem_push"] do - SOLIDUS_GEM_NAMES.each do |gem_name| - cd(gem_name) { sh "rake release:rubygem_push" } - end -end - -namespace :solidus do - desc "Report code coverage results for all solidus gems" - task :coverage, [:formatter] do |task, args| - require "simplecov" - SimpleCov.merge_timeout 3600 - if ENV["COVERAGE_DIR"] - SimpleCov.coverage_dir(ENV["COVERAGE_DIR"]) - end - if args[:formatter] == "cobertura" - require "simplecov-cobertura" - SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter - end - SimpleCov.result.format! - end -end +import 'tasks/cleaning.rake' +import 'tasks/releasing.rake' +import 'tasks/testing.rake' diff --git a/tasks/cleaning.rake b/tasks/cleaning.rake new file mode 100644 index 00000000000..403a380e999 --- /dev/null +++ b/tasks/cleaning.rake @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rake/clean' + +CLOBBER.include "sandbox" +CLOBBER.include "Gemfile.lock" +CLOBBER.include "{*/,}pkg" diff --git a/tasks/releasing.rake b/tasks/releasing.rake new file mode 100644 index 00000000000..4142046b470 --- /dev/null +++ b/tasks/releasing.rake @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'bundler/gem_tasks' + +SOLIDUS_GEM_NAMES = %w[core api backend sample] + +%w[build install].each do |task_name| + desc "Run rake #{task} for each Solidus gem" + task task_name do + SOLIDUS_GEM_NAMES.each do |gem_name| + cd(gem_name) { sh "rake #{task_name}" } + end + end +end + +# We need to redefine release task to skip creating and pushing git tag +Rake::Task["release"].clear +desc "Build and push solidus gems to RubyGems" +task "release" => ["build", "release:guard_clean", "release:rubygem_push"] do + SOLIDUS_GEM_NAMES.each do |gem_name| + cd(gem_name) { sh "rake release:rubygem_push" } + end +end diff --git a/tasks/testing.rake b/tasks/testing.rake new file mode 100644 index 00000000000..3d8eca98b26 --- /dev/null +++ b/tasks/testing.rake @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +task default: :spec + +def print_title(gem_name = '') + title = ["Solidus", gem_name].join(' ').strip + puts "\n#{'-' * title.size}\n#{title}\n#{'-' * title.size}" +end + +def subproject_task(project, task, title: project, task_name: nil) + task_name ||= "#{task}:#{project}" + task task_name do + print_title(title) + Dir.chdir("#{File.dirname(__FILE__)}/#{project}") do + sh "rake #{task}" + end + end +end + +%w[spec db:drop db:create db:migrate db:reset].each do |task| + %w(api backend core frontend sample).each do |project| + desc "Run specs for #{project}" if task == 'spec' + subproject_task(project, task) + end + + desc "Run rake #{task} for each Solidus engine" + task task => %w(api backend core frontend sample).map { |p| "#{task}:#{p}" } +end + +desc "Run backend JS specs" +subproject_task("backend", "spec:js", title: "backend JS", task_name: "spec:backend:js") + +# Add backend JS specs to `rake spec` dependencies +task spec: 'spec:backend:js' + +task test: :spec +task test_app: 'db:reset' + +namespace :solidus do + desc "Report code coverage results for all solidus gems" + task :coverage, [:formatter] do |_task, args| + require "simplecov" + SimpleCov.merge_timeout 3600 + if ENV["COVERAGE_DIR"] + SimpleCov.coverage_dir(ENV["COVERAGE_DIR"]) + end + if args[:formatter] == "cobertura" + require "simplecov-cobertura" + SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + end + SimpleCov.result.format! + end +end From 413c4c95abb6e0de52932cf8754239b0ea9cc117 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 29 Dec 2023 14:30:40 +0100 Subject: [PATCH 2/2] Move linting commands to rake tasks Only check files tracked by git and not generated and temporary files. --- .circleci/config.yml | 13 +++---------- .eslintrc.json | 10 ---------- .gitignore | 1 + .rubocop.yml | 7 +------ Gemfile | 2 +- Rakefile | 1 + tasks/linting.rake | 19 +++++++++++++++++++ 7 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 tasks/linting.rake diff --git a/.circleci/config.yml b/.circleci/config.yml index 9fee099d201..5e0062d9a89 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -246,20 +246,13 @@ jobs: - run: 'bundle install' - run: name: Check Ruby - command: | - bundle exec rubocop --parallel --format junit --out "$PWD/test-results/rubocop-results.xml" --format progress + command: "bin/rake lint:rb" - run: name: Check ERB - command: | - # enable recursive globbing with "**" - shopt -s globstar - - # we're only interested in errors - bundle exec erb-format **/*.html.erb > /dev/null + command: "bin/rake lint:erb" - run: name: Check JavaScript - command: | - npx -y eslint "**/*.js" + command: "bin/rake lint:js" - store_test_results: path: test-results diff --git a/.eslintrc.json b/.eslintrc.json index d49769ebf66..18178945e5b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,15 +1,5 @@ { "extends": "eslint:recommended", - "ignorePatterns": [ - "*tailwind.config.js", - "**/spec", - "**/vendor", - "**/node_modules", - "sandbox", - "coverage", - "core/doc", - "tmp" - ], "parserOptions": { "ecmaVersion": 2019 }, diff --git a/.gitignore b/.gitignore index 9af8c03be0d..3e4993f90ee 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ yarn.lock package-lock.json .env /admin/app/assets/builds +/test-results diff --git a/.rubocop.yml b/.rubocop.yml index 1d351c842af..4dda7c638e7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,12 +8,7 @@ require: AllCops: Exclude: - - 'vendor/**/*' - - '**/vendor/**/*' - - '*/spec/dummy/**/*' - - 'sandbox/**/*' - - '**/templates/**/*' - - 'tmp/**/*' + - '**/{tmp,vendor,spec/dummy,sandbox,templates,pkg}/**/*' TargetRubyVersion: 3.0 NewCops: disable SuggestExtensions: false diff --git a/Gemfile b/Gemfile index 418d2955a5e..0fc5e12ecc4 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,7 @@ group :admin do end group :lint do - gem 'erb-formatter', require: false + gem 'erb-formatter', '~> 0.7', require: false gem 'rubocop', '~> 1', require: false gem 'rubocop-performance', '~> 1.4', require: false gem 'rubocop-rails', '~> 2.9', require: false diff --git a/Rakefile b/Rakefile index 64473d43214..a7dca64a10b 100644 --- a/Rakefile +++ b/Rakefile @@ -3,3 +3,4 @@ import 'tasks/cleaning.rake' import 'tasks/releasing.rake' import 'tasks/testing.rake' +import 'tasks/linting.rake' diff --git a/tasks/linting.rake b/tasks/linting.rake new file mode 100644 index 00000000000..2d8b1c6993f --- /dev/null +++ b/tasks/linting.rake @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +namespace :lint do + task :rb do + ci_options = "-f junit -o '#{__dir__}/../test-results/rubocop-results.xml' " if ENV['CI'] + + sh %{bundle exec rubocop -P -f q #{ci_options}$(git ls-files -co --exclude-standard | grep -E "\\.rb$" | grep -v "/templates/")} + end + + task :erb do + sh 'bundle exec erb-format $(git ls-files -co --exclude-standard | grep -E "\.html.erb$") > /dev/null' + end + + task :js do + sh 'npx -y eslint $(git ls-files -co --exclude-standard | grep -E "\.js$" | grep -vE "/(vendor|config|spec)/")' + end +end + +task lint: %w[lint:rb lint:erb lint:js]