From c1529926db2e554a71fcd0b8852749e48a64dbb2 Mon Sep 17 00:00:00 2001 From: nofaralfasi Date: Tue, 20 Feb 2024 18:28:46 +0200 Subject: [PATCH] Use reusable GitHub Actions for testing --- .github/workflows/unit_tests.yaml | 22 ++++++++++++++++++++++ .gitignore | 3 +++ .rubocop.yml | 3 +++ Gemfile | 6 ++++++ Rakefile | 23 ++++++++++++++++++++--- hammer_cli_foreman_leapp.gemspec | 8 +++----- lib/hammer_cli_foreman_leapp/i18n.rb | 5 ++++- 7 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/unit_tests.yaml diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml new file mode 100644 index 0000000..1e3b5d6 --- /dev/null +++ b/.github/workflows/unit_tests.yaml @@ -0,0 +1,22 @@ +name: CI + +on: + pull_request: + push: + branches: + - 'master' + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + rubocop: + name: Rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + + test: + name: Tests + uses: theforeman/actions/.github/workflows/test-gem.yml@v0 + with: + command: bundle exec rake test diff --git a/.gitignore b/.gitignore index 06ba05f..006a171 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ pkg # Locale files locale/*/*.edit.po locale/*/*.po.time_stamp + +# RubyMine +.idea diff --git a/.rubocop.yml b/.rubocop.yml index 71db957..719ac16 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - rubocop-performance + Style/Documentation: Enabled: false Lint/RaiseException: diff --git a/Gemfile b/Gemfile index 1f4c45f..e7e04f1 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,9 @@ source 'https://rubygems.org' gemspec gem 'gettext', '>= 3.1.3', '< 4.0.0' +gem 'rake', '~> 13.0' + +group :test do + gem 'rubocop', '~> 1.57.0' + gem 'rubocop-performance', '~> 1.5.2' +end diff --git a/Rakefile b/Rakefile index 32e73c2..e2afb47 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,24 @@ require 'bundler/gem_tasks' Bundler::GemHelper.install_tasks -require "hammer_cli_foreman_leapp/version" -require "hammer_cli_foreman_leapp/i18n" -require "hammer_cli/i18n/find_task" +Rake::TestTask.new do |t| + t.libs.push 'lib' + t.verbose = true +end + +require 'hammer_cli_foreman_leapp/version' +require 'hammer_cli_foreman_leapp/i18n' +require 'hammer_cli/i18n/find_task' HammerCLI::I18n::FindTask.define(HammerCLIForemanLeapp::I18n::LocaleDomain.new, HammerCLIForemanLeapp.version.to_s) + +default_tasks = [:test] + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new + default_tasks.prepend(:rubocop) +rescue StandardError + puts 'Rubocop not loaded.' +end + +task default: default_tasks diff --git a/hammer_cli_foreman_leapp.gemspec b/hammer_cli_foreman_leapp.gemspec index 28b7c89..b9eadac 100644 --- a/hammer_cli_foreman_leapp.gemspec +++ b/hammer_cli_foreman_leapp.gemspec @@ -18,12 +18,10 @@ Gem::Specification.new do |spec| spec.platform = Gem::Platform::RUBY spec.summary = 'Foreman Leapp plugin for Hammer CLI' - spec.files = Dir['{lib,config}/**/*', 'LICENSE', 'README*'] + Dir["locale/**/*.{po,pot,mo}"] + spec.files = Dir['{lib,config}/**/*', 'LICENSE', 'README*'] + Dir['locale/**/*.{po,pot,mo}'] spec.require_paths = ['lib'] spec.test_files = Dir['{test}/**/*'] - spec.add_dependency 'hammer_cli_foreman', '>= 2.0.0', '< 4.0.0' - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'rubocop', '~> 0.80' + spec.add_dependency 'hammer_cli_foreman', '~> 3.10' + spec.required_ruby_version = '>= 2.7', '< 4' end diff --git a/lib/hammer_cli_foreman_leapp/i18n.rb b/lib/hammer_cli_foreman_leapp/i18n.rb index baca2c5..9c80f4f 100644 --- a/lib/hammer_cli_foreman_leapp/i18n.rb +++ b/lib/hammer_cli_foreman_leapp/i18n.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'hammer_cli/i18n' module HammerCLIForemanLeapp @@ -24,5 +26,6 @@ def locale_dir end end -domain = [HammerCLIForemanLeapp::I18n::LocaleDomain.new, HammerCLIForemanLeapp::I18n::SystemLocaleDomain.new].find { |d| d.available? } +domain = [HammerCLIForemanLeapp::I18n::LocaleDomain.new, + HammerCLIForemanLeapp::I18n::SystemLocaleDomain.new].find(&:available?) HammerCLI::I18n.add_domain(domain) if domain