-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub actions and danger #114
Open
reedrolemodel
wants to merge
8
commits into
master
Choose a base branch
from
github-actions-and-danger
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c1a934
Update Ruby version
wesrich 8097c65
Move Semaphore generator
wesrich 97fac54
Add Github Actions RSpec
wesrich 8884054
Add base Danger generators
wesrich 75397ca
Abbreviation for now
wesrich e62fc54
Fix 'exists?' => 'exist?'
wesrich da179ad
Update Danger stuff
wesrich 18f9e48
Rubocop
wesrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.0.0 | ||
3.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Description: | ||
Sets up a standard CI configuration | ||
|
||
Example: | ||
rails generate rolemodel:ci | ||
|
||
This will prompt to either run 'rolemodel:ci:semaphore' or 'rolemodel:ci:github' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Rolemodel | ||
class CiGenerator < Rails::Generators::Base | ||
def select_ci_platform | ||
ci_platform = ask('Which CI platform are you using? (semaphore/github)', limited_to: %w[semaphore github]) | ||
|
||
case ci_platform | ||
when 'semaphore' | ||
generate 'rolemodel:ci:semaphore' | ||
when 'github' | ||
generate 'rolemodel:ci:github' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Github Actions Generator | ||
|
||
## What you get | ||
|
||
* rspec.yml file to run the relevant CI commands | ||
* jest.yml file to run the relevant CI commands | ||
|
||
This is the basic config needed to use github actions. | ||
|
||
## Note | ||
This config assumes | ||
- `main` is the base branch | ||
- `yarn test` is the command to run JS tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Description: | ||
Sets up our standard github actions configuration | ||
|
||
Example: | ||
rails generate rolemodel:ci:github | ||
|
||
This will create: | ||
rspec.yml | ||
jest.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Rolemodel | ||
module Ci | ||
class GithubGenerator < Rails::Generators::Base | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def create_base_github_config | ||
template 'rspec.yml', '.github/workflows/rspec.yml' | ||
template 'rspec.yml', '.github/workflows/jest.yml' if File.exist?(Rails.root.join('package.json')) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: "RSpec" | ||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
ports: | ||
- "5432:5432" | ||
env: | ||
POSTGRES_DB: rails_test | ||
POSTGRES_USER: rails | ||
POSTGRES_PASSWORD: password | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
# Add or replace dependency steps here | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
# Add or replace database setup steps here | ||
- name: Set up database schema | ||
run: bin/rails db:schema:load | ||
# Add or replace test runners here | ||
- name: Run tests | ||
run: bin/rails |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/generators/rolemodel/ci/semaphore/semaphore_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Rolemodel | ||
module Ci | ||
class SemaphoreGenerator < Rails::Generators::Base | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def create_base_semaphore_config | ||
@project_name = Rails.application.class.try(:parent_name) || Rails.application.class.module_parent_name | ||
template 'semaphore.yml.erb', '.semaphore/semaphore.yml' | ||
|
||
if yes?('Does your project have JavaScript tests and/or eslint?') | ||
uncomment_lines('.semaphore/semaphore.yml', '- yarn test') | ||
uncomment_lines('.semaphore/semaphore.yml', '- yarn run eslint') | ||
end | ||
end | ||
|
||
def create_deplyment_commands | ||
default_heroku_prefix = (Rails.application.class.try(:parent_name) || Rails.application.class.module_parent_name).underscore.dasherize | ||
|
||
@heroku_prefix = ask('Enter the heroku project prefix', default: default_heroku_prefix) | ||
|
||
template 'heroku-deployment-commands.sh', '.semaphore/heroku-deployment-commands.sh' | ||
template 'staging-deploy.yml.erb', '.semaphore/staging-deploy.yml' | ||
template 'production-deploy.yml.erb', '.semaphore/production-deploy.yml' | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Danger Generator | ||
|
||
## What you get | ||
|
||
* danger.yml file to run danger itself | ||
* .danger/base.rb file to get basic review PR comments | ||
* .danger/rubocop.rb file to get rubocop PR comments | ||
* .danger/eslint.rb file to get eslint PR comments | ||
* .danger/brakeman.rb file to get brakeman PR comments | ||
|
||
This is the basic config needed to use semaphore. | ||
|
||
## Note | ||
This config assumes | ||
- `main` is the base branch | ||
- `yarn test` is the command to run JS tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Description: | ||
Sets up our standard danger configurations | ||
|
||
Example: | ||
rails generate rolemodel:danger | ||
|
||
This will create: | ||
Dangerfile | ||
.danger/base.rb | ||
.danger/brakeman.rb | ||
.danger/eslint.rb | ||
.danger/rubocop.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Rolemodel | ||
class DangerGenerator < Rails::Generators::Base | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def create_base_danger_config | ||
copy_file 'Dangerfile', 'Dangerfile' | ||
copy_file 'base.rb', '.danger/base.rb' | ||
gem_group :development, :test do | ||
gem 'danger' | ||
end | ||
end | ||
|
||
def create_github_action | ||
copy_file 'danger.yml', '.github/workflows/danger.yml' | ||
end | ||
|
||
def create_rubocop_config | ||
unless File.exist?(Rails.root.join('.rubocop.yml')) | ||
return unless yes?('Do you want to install rubocop?') | ||
generate 'rolemodel:linters:rubocop' | ||
end | ||
gem_group :development, :test do | ||
gem 'danger-rubocop' | ||
end | ||
copy_file 'rubocop.rb', '.danger/rubocop.rb' | ||
end | ||
|
||
def create_brakeman_config | ||
return unless yes?('Do you want to install brakeman?') | ||
|
||
gem_group :development, :test do | ||
gem 'brakeman' | ||
gem 'danger-brakeman' | ||
end | ||
copy_file 'brakeman.rb', '.danger/brakeman.rb' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# https://evilmartians.com/chronicles/danger-on-rails-make-robots-do-some-code-review-for-you | ||
|
||
# Shared consts | ||
CHANGED_FILES = (git.added_files + git.modified_files).freeze | ||
ADDED_FILES = git.added_files.freeze | ||
|
||
Dir[File.join(__dir__, '.danger/*.rb')].each do |danger_rule_file| | ||
danger_rule = danger_rule_file.gsub(%r{(^./.danger/|.rb)}, '') | ||
$stdout.print "- #{danger_rule} " | ||
# execute each check using `eval` | ||
eval File.read(danger_rule_file), binding, File.expand_path(danger_rule_file) # rubocop:disable Security/Eval | ||
$stdout.puts '✅' | ||
# allow a single check to fail without breaking others | ||
rescue Exception => e # rubocop:disable Lint/RescueException | ||
$stdout.puts '💥' | ||
|
||
# make sure the result is a failure if some check failed to execute | ||
raise "Danger rule :#{danger_rule} failed with exception: #{e.message}\n" \ | ||
"Backtrace: \n#{e.backtrace.join("\n")}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Danger uses 'fail' as part of their DSL, so we need to disable this cop | ||
# rubocop:disable Style/SignalException | ||
|
||
declared_trivial = github.pr_title.include? '#trivial' # rubocop:disable Lint/UselessAssignment | ||
|
||
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet | ||
warn('PR is classed as Work in Progress') if github.pr_title.include? '[WIP]' | ||
|
||
# Warn when there is a big PR | ||
warn('Big PR') if git.lines_of_code > 500 | ||
|
||
# Don't let testing shortcuts get into master by accident | ||
fail('fdescribe left in tests') if `grep -r fdescribe spec/**/*_spec.rb `.length > 1 | ||
fail('fit left in tests') if `grep -r fit spec/**/*_spec.rb `.length > 1 | ||
fail('focus left in tests') if `grep -r focus spec/**/*_spec.rb `.length > 1 | ||
|
||
# rubocop:enable Style/SignalException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
brakeman.lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "Danger" | ||
on: | ||
push: | ||
branches: ["master"] | ||
pull_request: | ||
branches: ["master"] | ||
jobs: | ||
danger: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'pull_request' # if only run pull request when multiple trigger workflow | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
- name: Running the Dangerfile for this repo | ||
run: bundle exec danger --verbose | ||
env: | ||
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
RUNNING_IN_ACTIONS: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
rubocop.lint( | ||
# Comment on individual files on the PR | ||
inline_comment: true, | ||
|
||
# New option to use the severity reported by Rubocop, e.g. errors | ||
# will fail the build. | ||
# https://github.com/ashfurrow/danger-rubocop/pull/61 | ||
report_severity: true, | ||
|
||
# Allowed Danger-Rubocop to fail the build, but it reported all offenses | ||
# as failures if true, or all as warnings if fails / not provided. The | ||
# option above allows for better specificity. | ||
# file_on_inline_comment: true, | ||
|
||
# Empty string will report on all files, even those not directly touched | ||
# in the current PR. This is useful in case a change impacts other files, | ||
# such as modifying the Rubocop config. | ||
files: '', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had issues using
DATABASE_URL
with parallel testing.Could you change to https://github.com/RoleModel/gimme-credit/blob/main/.github/workflows/ci.yml#L42-L53
It does require some updates to the database.yml for some reason though https://github.com/RoleModel/gimme-credit/blob/main/config/database.yml#L60-L65