From 152941377b060e9979a7c23dbac5bdc97d7fd654 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 10 May 2025 14:39:33 +0200 Subject: [PATCH] Add gitlab support --- .../infrastructure/gitlab_generator.rb | 11 +++++ .../infrastructure/templates/github.tt | 2 +- .../infrastructure/templates/gitlab.tt | 43 +++++++++++++++++++ lib/generators/invoke_generators.rb | 1 + lib/generators/menu_generator.rb | 1 + .../generators/gitlab_generator_spec.rb | 38 ++++++++++++++++ spec/integration/spec_helper.rb | 2 +- 7 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 lib/generators/infrastructure/gitlab_generator.rb create mode 100644 lib/generators/infrastructure/templates/gitlab.tt create mode 100644 spec/integration/generators/gitlab_generator_spec.rb diff --git a/lib/generators/infrastructure/gitlab_generator.rb b/lib/generators/infrastructure/gitlab_generator.rb new file mode 100644 index 0000000..9247dde --- /dev/null +++ b/lib/generators/infrastructure/gitlab_generator.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require_relative '../generator' + +class GitlabGenerator < Generator + def generate_gitlab_file + return unless web? + + template('gitlab.tt', "#{name}/gitlab-ci.yml") + end +end diff --git a/lib/generators/infrastructure/templates/github.tt b/lib/generators/infrastructure/templates/github.tt index a6b907f..649074f 100644 --- a/lib/generators/infrastructure/templates/github.tt +++ b/lib/generators/infrastructure/templates/github.tt @@ -19,7 +19,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1.0 + ruby-version: 3.4.0 bundler-cache: true - name: Checkout repository diff --git a/lib/generators/infrastructure/templates/gitlab.tt b/lib/generators/infrastructure/templates/gitlab.tt new file mode 100644 index 0000000..59e959d --- /dev/null +++ b/lib/generators/infrastructure/templates/gitlab.tt @@ -0,0 +1,43 @@ +stages: + - setup + - test + - report + +variables: + RUBY_VERSION: "3.4.0" + +setup_ruby: + stage: setup + image: ruby:${RUBY_VERSION} + script: + - bundle install --jobs $(nproc) --retry 3 + cache: + paths: + - vendor/bundle + +run_tests: + stage: test + image: ruby:${RUBY_VERSION} + script: + - mkdir -p allure-results + - <%- if framework == 'cucumber' -%> cucumber features --format pretty <%- else -%> bundle exec rspec spec --format documentation <%- end%> + artifacts: + paths: + - allure-results/ + when: always + +pages: + stage: report + image: alpine/git + dependencies: + - run_tests + script: + - apk add --no-cache curl unzip + - curl -o allure.zip -L https://github.com/allure-framework/allure2/releases/latest/download/allure-commandline.zip + - unzip allure.zip -d /tmp/ + - /tmp/allure-*/bin/allure generate allure-results --clean -o public + artifacts: + paths: + - public + only: + - main diff --git a/lib/generators/invoke_generators.rb b/lib/generators/invoke_generators.rb index f9a9453..143f25e 100644 --- a/lib/generators/invoke_generators.rb +++ b/lib/generators/invoke_generators.rb @@ -1,4 +1,5 @@ require_relative 'infrastructure/github_generator' +require_relative 'infrastructure/gitlab_generator' require_relative 'automation/automation_generator' require_relative 'common_generator' require_relative 'cucumber/cucumber_generator' diff --git a/lib/generators/menu_generator.rb b/lib/generators/menu_generator.rb index 71b98bc..0745113 100644 --- a/lib/generators/menu_generator.rb +++ b/lib/generators/menu_generator.rb @@ -101,6 +101,7 @@ def automation_options(menu) 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 :'Gitlab CI/CD', -> { create_framework(framework, automation, 'gitlab') } menu.choice :No, -> { create_framework(framework, automation) } menu.choice :Quit, -> { exit } end diff --git a/spec/integration/generators/gitlab_generator_spec.rb b/spec/integration/generators/gitlab_generator_spec.rb new file mode 100644 index 0000000..293429c --- /dev/null +++ b/spec/integration/generators/gitlab_generator_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative '../../../lib/generators/infrastructure/gitlab_generator' +require_relative '../spec_helper' + +describe GitlabGenerator do + shared_examples 'selects gitlab as an infrastructure option' do |name| + it 'creates a gitlab infrastructure file' do + expect(File).to exist("#{name}/gitlab-ci.yml") + end + end + + shared_examples 'does not select any infrastructure option' do |name| + it 'does not create a gitlab infrastructure file' do + expect(File).not_to exist("#{name}/gitlab-ci.yml") + end + end + + context 'with rspec and selenium' do + include_examples 'selects gitlab as an infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_#{CI_PLATFORMS[2]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}" + end + + context 'with rspec and watir' do + include_examples 'selects gitlab as an infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_#{CI_PLATFORMS[2]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}" + end + + context 'with cucumber and selenium' do + include_examples 'selects gitlab as an infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}_#{CI_PLATFORMS[2]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}" + end + + context 'with cucumber and watir' do + include_examples 'selects gitlab as an infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}_#{CI_PLATFORMS[2]}" + include_examples 'does not select any infrastructure option', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}" + end +end diff --git a/spec/integration/spec_helper.rb b/spec/integration/spec_helper.rb index 9f13865..00933a5 100644 --- a/spec/integration/spec_helper.rb +++ b/spec/integration/spec_helper.rb @@ -7,7 +7,7 @@ AUTOMATION_TYPES = %w[android ios selenium watir cross_platform axe applitools].freeze FRAMEWORKS = %w[cucumber rspec].freeze -CI_PLATFORMS = [nil, 'github'].freeze +CI_PLATFORMS = [nil, 'github', 'gitlab'].freeze RSpec.configure do |config| config.include(InvokeGenerators)