From cbb31a2999275d7b8716a8dfa073d00a1ccabd19 Mon Sep 17 00:00:00 2001 From: aguspe Date: Wed, 7 May 2025 23:39:03 +0200 Subject: [PATCH] Add support in the menu for github --- .github/workflows/integration.yml | 2 +- .github/workflows/push_gem.yml | 2 +- .github/workflows/reek.yml | 2 +- .github/workflows/rubocop.yml | 2 +- .github/workflows/selenium.yml | 2 +- .github/workflows/watir.yml | 2 +- lib/generators/generator.rb | 2 +- .../github_generator.rb} | 4 +- .../templates/github.tt} | 0 lib/generators/invoke_generators.rb | 9 +++-- lib/generators/menu_generator.rb | 24 ++++++++---- lib/version | 2 +- .../generators/actions_generator_spec.rb | 28 -------------- .../generators/github_generator_spec.rb | 38 +++++++++++++++++++ spec/integration/settings_helper.rb | 4 +- spec/integration/spec_helper.rb | 16 +++++--- 16 files changed, 85 insertions(+), 54 deletions(-) rename lib/generators/{actions/actions_generator.rb => infrastructure/github_generator.rb} (53%) rename lib/generators/{actions/templates/actions.tt => infrastructure/templates/github.tt} (100%) delete mode 100644 spec/integration/generators/actions_generator_spec.rb create mode 100644 spec/integration/generators/github_generator_spec.rb diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b579aac..5d2580c 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: infrastructure/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index fc37970..5f2d61e 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -26,7 +26,7 @@ jobs: with: egress-policy: audit - - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - uses: infrastructure/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Set up Ruby uses: ruby/setup-ruby@cacc9f1c0b3f4eb8a16a6bb0ed10897b43b9de49 # v1.176.0 with: diff --git a/.github/workflows/reek.yml b/.github/workflows/reek.yml index 2695f4a..d640c06 100644 --- a/.github/workflows/reek.yml +++ b/.github/workflows/reek.yml @@ -13,7 +13,7 @@ jobs: ruby-version: head - name: Check out code - uses: actions/checkout@v1 + uses: infrastructure/checkout@v1 - name: reek uses: reviewdog/action-reek@v1 diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index aa2049b..7ab21c0 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -17,7 +17,7 @@ jobs: ruby-version: head - name: Check out code - uses: actions/checkout@v1 + uses: infrastructure/checkout@v1 - name: rubocop uses: reviewdog/action-rubocop@v2 diff --git a/.github/workflows/selenium.yml b/.github/workflows/selenium.yml index bf11cac..7718eca 100644 --- a/.github/workflows/selenium.yml +++ b/.github/workflows/selenium.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: infrastructure/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/watir.yml b/.github/workflows/watir.yml index 37c7567..c39a91a 100644 --- a/.github/workflows/watir.yml +++ b/.github/workflows/watir.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: infrastructure/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 diff --git a/lib/generators/generator.rb b/lib/generators/generator.rb index 3fd4b4d..398932c 100644 --- a/lib/generators/generator.rb +++ b/lib/generators/generator.rb @@ -12,7 +12,7 @@ class Generator < Thor::Group def self.source_paths base_path = File.dirname(__FILE__) %W[#{base_path}/automation/templates #{base_path}/cucumber/templates - #{base_path}/rspec/templates #{base_path}/templates #{base_path}/actions/templates ] + #{base_path}/rspec/templates #{base_path}/templates #{base_path}/infrastructure/templates ] end def args diff --git a/lib/generators/actions/actions_generator.rb b/lib/generators/infrastructure/github_generator.rb similarity index 53% rename from lib/generators/actions/actions_generator.rb rename to lib/generators/infrastructure/github_generator.rb index c70e808..07853c4 100644 --- a/lib/generators/actions/actions_generator.rb +++ b/lib/generators/infrastructure/github_generator.rb @@ -2,10 +2,10 @@ require_relative '../generator' -class ActionsGenerator < Generator +class GithubGenerator < Generator def generate_actions_file return unless web? - template('actions.tt', "#{name}/.github/workflows/test_pipeline.yml") + template('github.tt', "#{name}/.github/workflows/test_pipeline.yml") end end diff --git a/lib/generators/actions/templates/actions.tt b/lib/generators/infrastructure/templates/github.tt similarity index 100% rename from lib/generators/actions/templates/actions.tt rename to lib/generators/infrastructure/templates/github.tt diff --git a/lib/generators/invoke_generators.rb b/lib/generators/invoke_generators.rb index a4f5e3a..f9a9453 100644 --- a/lib/generators/invoke_generators.rb +++ b/lib/generators/invoke_generators.rb @@ -1,4 +1,4 @@ -require_relative 'actions/actions_generator' +require_relative 'infrastructure/github_generator' require_relative 'automation/automation_generator' require_relative 'common_generator' require_relative 'cucumber/cucumber_generator' @@ -11,14 +11,16 @@ module InvokeGenerators module_function def generate_framework(structure = {}) - generators = %w[Automation Actions Common Helpers] + generators = %w[Automation Common Helpers] framework = structure[:framework] add_generator(generators, framework.capitalize) + add_generator(generators, structure[:ci_platform].capitalize) if structure[:ci_platform] generators.each do |generator| invoke_generator({ automation: structure[:automation], framework:, generator:, + ci_platform: structure[:ci_platform], name: structure[:name] }) end @@ -32,7 +34,8 @@ def invoke_generator(structure = {}) Object.const_get("#{structure[:generator]}Generator") .new([structure[:automation], structure[:framework], - structure[:name]]).invoke_all + structure[:name], + structure[:ci_platform]]).invoke_all end def to_bool(string) diff --git a/lib/generators/menu_generator.rb b/lib/generators/menu_generator.rb index d284746..71b98bc 100644 --- a/lib/generators/menu_generator.rb +++ b/lib/generators/menu_generator.rb @@ -31,6 +31,7 @@ def set_up_framework(options) structure = { automation: options[:automation], framework: options[:framework], + ci_platform: options[:ci_platform], name: @name } generate_framework(structure) @@ -50,26 +51,27 @@ def choose_mobile_platform def select_test_framework(automation) prompt.select('Please select your test framework') do |menu| - menu.choice :Cucumber, -> { create_framework('Cucumber', automation) } - menu.choice :Rspec, -> { create_framework('Rspec', automation) } + menu.choice :Cucumber, -> { select_ci_platform('Cucumber', automation) } + menu.choice :Rspec, -> { select_ci_platform('Rspec', automation) } menu.choice :Quit, -> { exit } end end - FrameworkOptions = Struct.new(:automation, :framework) + FrameworkOptions = Struct.new(:automation, :framework, :ci_platform) def create_framework_options(params) - FrameworkOptions.new(params[:automation], params[:framework]) + FrameworkOptions.new(params[:automation], params[:framework], params[:ci_platform]) end - def create_framework(framework, automation_type) + def create_framework(framework, automation_type, ci_platform = nil) options = create_framework_options(automation: automation_type, - framework: framework.downcase) + framework: framework.downcase, + ci_platform:) - # Print the chosen options puts 'Chosen Options:' puts " Automation Type: #{options[:automation]}" puts " Framework: #{options[:framework]}" + puts " CI Platform: #{options[:ci_platform]}" if options[:ci_platform] set_up_framework(options) prompt.say("You have chosen to use #{framework} with #{automation_type}") @@ -95,4 +97,12 @@ def automation_options(menu) menu.choice :Applitools, -> { choose_test_framework('applitools') } menu.choice :Axe, -> { choose_test_framework('axe') } end + + def select_ci_platform(framework, automation) + prompt.select('Would you like to configure CI?') do |menu| + menu.choice :'Github Actions', -> { create_framework(framework, automation, 'github') } + menu.choice :No, -> { create_framework(framework, automation) } + menu.choice :Quit, -> { exit } + end + end end diff --git a/lib/version b/lib/version index 45a1b3f..781dcb0 100644 --- a/lib/version +++ b/lib/version @@ -1 +1 @@ -1.1.2 +1.1.3 diff --git a/spec/integration/generators/actions_generator_spec.rb b/spec/integration/generators/actions_generator_spec.rb deleted file mode 100644 index 4babf0e..0000000 --- a/spec/integration/generators/actions_generator_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../lib/generators/actions/actions_generator' -require_relative '../spec_helper' - -describe ActionsGenerator do - shared_examples 'creates web automation framework' do |name| - it 'creates a github actions file' do - expect(File).to exist("#{name}/.github/workflows/test_pipeline.yml") - end - end - - context 'with rspec and selenium' do - include_examples 'creates web automation framework', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}" - end - - context 'with rspec and watir' do - include_examples 'creates web automation framework', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}" - end - - context 'with cucumber and selenium' do - include_examples 'creates web automation framework', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}" - end - - context 'with cucumber and watir' do - include_examples 'creates web automation framework', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}" - end -end diff --git a/spec/integration/generators/github_generator_spec.rb b/spec/integration/generators/github_generator_spec.rb new file mode 100644 index 0000000..9877532 --- /dev/null +++ b/spec/integration/generators/github_generator_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative '../../../lib/generators/infrastructure/github_generator' +require_relative '../spec_helper' + +describe GithubGenerator do + shared_examples 'selects github as an infrastructure option' do |name| + it 'creates a github infrastructure file' do + expect(File).to exist("#{name}/.github/workflows/test_pipeline.yml") + end + end + + shared_examples 'does not select any infrastructure option' do |name| + it 'does not create a github infrastructure file' do + expect(File).not_to exist("#{name}/.github/workflows/test_pipeline.yml") + end + end + + context 'with rspec and selenium' do + include_examples 'selects github as an infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_#{CI_PLATFORMS[1]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}" + end + + context 'with rspec and watir' do + include_examples 'selects github as an infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_#{CI_PLATFORMS[1]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}" + end + + context 'with cucumber and selenium' do + include_examples 'selects github as an infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}_#{CI_PLATFORMS[1]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}" + end + + context 'with cucumber and watir' do + include_examples 'selects github as an infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}_#{CI_PLATFORMS[1]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}" + end +end diff --git a/spec/integration/settings_helper.rb b/spec/integration/settings_helper.rb index 24ec943..49918ad 100644 --- a/spec/integration/settings_helper.rb +++ b/spec/integration/settings_helper.rb @@ -5,10 +5,12 @@ module SettingsHelper def create_settings(options) automation = options[:automation] framework = options[:framework] + ci_platform = options[:ci_platform] { automation:, framework:, - name: "#{framework}_#{automation}" + ci_platform:, + name: ci_platform ? "#{framework}_#{automation}_#{ci_platform}" : "#{framework}_#{automation}", } end end diff --git a/spec/integration/spec_helper.rb b/spec/integration/spec_helper.rb index 6e654a5..9f13865 100644 --- a/spec/integration/spec_helper.rb +++ b/spec/integration/spec_helper.rb @@ -7,16 +7,20 @@ AUTOMATION_TYPES = %w[android ios selenium watir cross_platform axe applitools].freeze FRAMEWORKS = %w[cucumber rspec].freeze +CI_PLATFORMS = [nil, 'github'].freeze RSpec.configure do |config| config.include(InvokeGenerators) config.include(SettingsHelper) + # rubocop:disable RSpec/BeforeAfterAll config.before(:all) do FRAMEWORKS.each do |framework| AUTOMATION_TYPES.each do |automation| - settings = create_settings(framework:, automation:) - generate_framework(settings) + CI_PLATFORMS.each do |ci_platform| + settings = create_settings(framework:, automation:, ci_platform:) + generate_framework(settings) + end end end end @@ -24,10 +28,12 @@ config.after(:all) do FRAMEWORKS.each do |framework| AUTOMATION_TYPES.each do |automation| - settings = create_settings(framework:, automation:) - FileUtils.rm_rf(settings[:name]) + CI_PLATFORMS.each do |ci_platform| + settings = create_settings(framework:, automation:, ci_platform:) + FileUtils.rm_rf(settings[:name]) + end end end end + # rubocop:enable RSpec/BeforeAfterAll end -# rubocop:enable RSpec/BeforeAfterAll