Skip to content

Commit

Permalink
Merge pull request #98 from TruemarkDev/generator-for-pronto-with-git…
Browse files Browse the repository at this point in the history
…hub-action

Draft: Generator for pronto with GitHub action
  • Loading branch information
abhaynikam authored May 23, 2024
2 parents c5743cb + 4c80bbc commit 5eb5dd2
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][])
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<testing_framework> --stubbing_libraries=<stubbing_libraries>`
- Install Pronto with Github Action: `rails generate boring:pronto:github_action:install`

## Screencasts

Expand Down
1 change: 1 addition & 0 deletions lib/boring_generators/generator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/boring/pronto/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def pronto_flay_gem_content
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def stages_configuration
end
end
end
end
end
45 changes: 45 additions & 0 deletions test/generators/pronto/github_action_install_generator_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5eb5dd2

Please sign in to comment.