From 6ec7bce853fe2c652a2abf894ba16861d370da72 Mon Sep 17 00:00:00 2001 From: Prabin Poudel <15196941+coolprobn@users.noreply.github.com> Date: Fri, 29 Mar 2024 22:36:21 +0545 Subject: [PATCH 1/2] Generator for Pronto with Gitlab CI --- lib/boring_generators/generator_helper.rb | 1 + lib/generators/boring/pronto/base_generator.rb | 2 +- .../boring/pronto/gitlab_ci/install/install_generator.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/boring_generators/generator_helper.rb b/lib/boring_generators/generator_helper.rb index 0d7cdb41..491e6f3a 100644 --- a/lib/boring_generators/generator_helper.rb +++ b/lib/boring_generators/generator_helper.rb @@ -25,6 +25,7 @@ def check_and_install_gem(*args) gem_file_content_array = File.readlines("Gemfile") + gem_exists = gem_file_content_array.any? { |line| line.include?(gem_name) } if gem_exists diff --git a/lib/generators/boring/pronto/base_generator.rb b/lib/generators/boring/pronto/base_generator.rb index d70569a1..e2db7263 100644 --- a/lib/generators/boring/pronto/base_generator.rb +++ b/lib/generators/boring/pronto/base_generator.rb @@ -44,4 +44,4 @@ def pronto_flay_gem_content end end end -end \ No newline at end of file +end diff --git a/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb b/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb index a2baca0c..d6083cad 100644 --- a/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb +++ b/lib/generators/boring/pronto/gitlab_ci/install/install_generator.rb @@ -102,4 +102,4 @@ def stages_configuration end end end -end \ No newline at end of file +end From 4c80bbc761aceb79977e68be403a88d7ca06e2c6 Mon Sep 17 00:00:00 2001 From: TheZero0-ctrl Date: Mon, 8 Apr 2024 17:28:51 +0545 Subject: [PATCH 2/2] add generator for the pronto for github action --- CHANGELOG.md | 1 + README.md | 1 + .../install/install_generator.rb | 27 ++++++++++ .../install/templates/pronto.yml.tt | 53 +++++++++++++++++++ .../github_action_install_generator_test.rb | 45 ++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 lib/generators/boring/pronto/github_action/install/install_generator.rb create mode 100644 lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt create mode 100644 test/generators/pronto/github_action_install_generator_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 088498e1..b287cf71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Adds Pronto Generator with Gitlab CI ([@coolprobn][]) * Adds Rack Mini Profiler generator. ([@mausamp][]) * Adds VCR generator. ([@TheZero0-ctrl][]) +* Adds Pronto Generator with Gihub Action. ([@TheZero0-ctrl][]) ## 0.13.0 (March 26th, 2024) * Adds Letter Opener generator. ([@coolprobn][]) diff --git a/README.md b/README.md index 276115ef..72ed7f3b 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ The boring generator introduces following generators: - Install Pronto with Gitlab CI: `rails generate boring:pronto:gitlab_ci:install` - Install Rack Mini Profiler: `rails generate boring:rack_mini_profiler:install` - Install VCR: `rails generate boring:vcr:install --testing_framework= --stubbing_libraries=` +- Install Pronto with Github Action: `rails generate boring:pronto:github_action:install` ## Screencasts diff --git a/lib/generators/boring/pronto/github_action/install/install_generator.rb b/lib/generators/boring/pronto/github_action/install/install_generator.rb new file mode 100644 index 00000000..90036846 --- /dev/null +++ b/lib/generators/boring/pronto/github_action/install/install_generator.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "generators/boring/pronto/base_generator" +require "boring_generators/generator_helper" + +module Boring + module Pronto + module GithubAction + class InstallGenerator < Boring::Pronto::BaseGenerator + desc "Adds Pronto configurations to Github Action" + source_root File.expand_path("templates", __dir__) + + class_option :ruby_version, type: :string, aliases: "-rv" + + include BoringGenerators::GeneratorHelper + + def add_pronto_configuration_for_github_action + say "Adding Pronto configurations to .github/workflows/pronto.yml", :green + + @ruby_version = options.ruby_version || app_ruby_version + + template("pronto.yml", ".github/workflows/pronto.yml") + end + end + end + end +end diff --git a/lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt b/lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt new file mode 100644 index 00000000..65febf00 --- /dev/null +++ b/lib/generators/boring/pronto/github_action/install/templates/pronto.yml.tt @@ -0,0 +1,53 @@ +on: [pull_request] + +name: Pronto + +jobs: + pronto: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + statuses: write + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: <%= @ruby_version %> + - name: Ruby gem cache + uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Install gems + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: 10.13.0 + - name: Find yarn cache location + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: JS package cache + uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install packages + run: | + yarn install --pure-lockfile + - name: Run Pronto + run: | + PRONTO_PULL_REQUEST_ID="${{ github.event.pull_request.number }}" PRONTO_GITHUB_ACCESS_TOKEN="${{ github.token }}" bundle exec pronto run -f github_status github_pr -c origin/${{ github.base_ref }} diff --git a/test/generators/pronto/github_action_install_generator_test.rb b/test/generators/pronto/github_action_install_generator_test.rb new file mode 100644 index 00000000..d3b244c6 --- /dev/null +++ b/test/generators/pronto/github_action_install_generator_test.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require "test_helper" +require "generators/boring/pronto/github_action/install/install_generator" + +class ProntoGithubActionInstallGeneratorTest < Rails::Generators::TestCase + tests Boring::Pronto::GithubAction::InstallGenerator + setup :build_app + teardown :teardown_app + + include GeneratorHelper + include ActiveSupport::Testing::Isolation + + def destination_root + app_path + end + + def test_should_configure_pronto_in_github_action_file + Dir.chdir(app_path) do + quietly do + generator.add_pronto_configuration_for_github_action + end + + template_app_ruby_version = `cat .ruby-version` + + assert_file ".github/workflows/pronto.yml" do |content| + assert_match("pronto:", content) + assert_match("ruby-version: #{template_app_ruby_version}", content) + end + end + end + + def test_should_add_correct_ruby_version + Dir.chdir(app_path) do + quietly do + generator({}, [ "--ruby_version=3.0.0" ]) + .add_pronto_configuration_for_github_action + end + + assert_file ".github/workflows/pronto.yml" do |content| + assert_match("ruby-version: 3.0.0", content) + end + end + end +end