Skip to content
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

Add support for CircleCI 2.0 #934

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/suspenders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "suspenders/generators/static_generator"
require "suspenders/generators/stylesheet_base_generator"
require "suspenders/generators/forms_generator"
require "suspenders/generators/ci_generator"
require "suspenders/generators/db_optimizations_generator"
require "suspenders/generators/factories_generator"
require "suspenders/generators/lint_generator"
Expand All @@ -17,4 +16,5 @@
require "suspenders/generators/production/timeout_generator"
require "suspenders/actions"
require "suspenders/adapters/heroku"
require "suspenders/adapters/circleci"
require "suspenders/app_builder"
46 changes: 46 additions & 0 deletions lib/suspenders/adapters/circleci.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Suspenders
module Adapters
class CircleCI
def initialize(app_builder)
@app_builder = app_builder
end

def configure_circleci
app_builder.empty_directory(".circleci")
app_builder.template "circleci.yml.erb", ".circleci/config.yml"
end

def configure_circleci_deployment
deploy_command = <<-YML.strip_heredoc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why this isn't in the the circleci.yml.erb file?

deploy:
docker:
- image: buildpack-deps:trusty
steps:
- checkout
- run:
name: Deploy to staging
command: bin/deploy staging

workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master

YML

app_builder.append_file ".circleci/config.yml", deploy_command
end

private

attr_reader :app_builder
end
end
end
20 changes: 11 additions & 9 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class AppBuilder < Rails::AppBuilder
:set_heroku_remotes,
)

def_delegators(
:circleci_adapter,
:configure_circleci,
:configure_circleci_deployment,
)

def readme
template 'README.md.erb', 'README.md'
end
Expand Down Expand Up @@ -242,15 +248,7 @@ def create_deploy_script
end

def configure_automatic_deployment
deploy_command = <<-YML.strip_heredoc
deployment:
staging:
branch: master
commands:
- bin/deploy staging
YML

append_file "circle.yml", deploy_command
configure_circleci_deployment
end

def create_github_repo(repo_name)
Expand Down Expand Up @@ -343,5 +341,9 @@ def raise_on_missing_translations_in(environment)
def heroku_adapter
@heroku_adapter ||= Adapters::Heroku.new(self)
end

def circleci_adapter
@circleci_adapter ||= Adapters::CircleCI.new(self)
end
end
end
7 changes: 6 additions & 1 deletion lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def suspenders_customization
invoke :setup_bundler_audit
invoke :setup_spring
invoke :generate_default
invoke :configure_circleci
invoke :setup_default_directories
invoke :create_local_heroku_setup
invoke :create_heroku_apps
Expand Down Expand Up @@ -177,12 +178,16 @@ def remove_routes_comment_lines
build :remove_routes_comment_lines
end

def configure_circleci
say "Configuring CircleCI"
build :configure_circleci
end

def generate_default
run("spring stop")
generate("suspenders:static")
generate("suspenders:stylesheet_base")
generate("suspenders:testing")
generate("suspenders:ci")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to keep this in the generator, so people can remove CI support if they don't want it (or, for people who just add the gem to their Gemfile, so people can add CI support if they want it).

generate("suspenders:js_driver")
unless options[:api]
generate("suspenders:forms")
Expand Down
26 changes: 0 additions & 26 deletions lib/suspenders/generators/ci_generator.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/features/circleci_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "spec_helper"

RSpec.describe "CircleCI" do
before(:all) do
drop_dummy_database
remove_project_directory
run_suspenders
setup_app_dependencies
end

it "creates CircleCI config file" do
expect(File).to exist("#{project_path}/.circleci/config.yml")
end

it "uses the app name in the config file" do
circleci_config = IO.read("#{project_path}/.circleci/config.yml")

expect(circleci_config).to match(/working_directory: ~\/#{app_name}/)
end

def app_name
SuspendersTestHelpers::APP_NAME
end
end
27 changes: 21 additions & 6 deletions spec/features/heroku_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,30 @@
expect(readme).to include("./bin/deploy staging")
expect(readme).to include("./bin/deploy production")

circle_yml_path = "#{project_path}/circle.yml"
circle_yml_path = "#{project_path}/.circleci/config.yml"
circle_yml = IO.read(circle_yml_path)

expect(circle_yml).to include <<-YML.strip_heredoc
deployment:
staging:
branch: master
commands:
- bin/deploy staging
deploy:
docker:
- image: buildpack-deps:trusty
steps:
- checkout
- run:
name: Deploy to staging
command: bin/deploy staging

workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master
YML
end
end
Expand Down
6 changes: 0 additions & 6 deletions templates/circle.yml.erb

This file was deleted.

53 changes: 53 additions & 0 deletions templates/circleci.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: 2
jobs:
build:
working_directory: ~/<%= app_name %>
docker:
- image: circleci/ruby:<%= Suspenders::RUBY_VERSION %>-node
environment:
RAILS_ENV: test
PGHOST: localhost
PGUSER: <%= app_name %>
- image: postgres:10.5
environment:
POSTGRES_USER: <%= app_name %>
POSTGRES_DB: <%= app_name %>_test
POSTGRES_PASSWORD: ""
steps:
- checkout

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give that you have have not spaced out the rest of this file, what are your thoughts on removing this whitespace?

- run:
name: Which Bundler?
command: bundle -v

- restore_cache:
keys:
- <%= app_name %>-{{ .Branch }}-{{ checksum "Gemfile.lock" }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be branch specific?

I kind of like the idea that this would restore the cache for any ol' branch so long as the gems are the same.

- <%= app_name %>-

- run:
name: Bundle Install
command: |
bundle install --deployment \
--retry=3 \
--jobs=3

- save_cache:
key: <%= app_name %>-{{ .Branch }}-{{ checksum "Gemfile.lock" }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

paths:
- vendor/bundle

- run:
name: Wait for database
command: dockerize -wait tcp://localhost:5432 -timeout 1m

- run:
name: Database setup
command: RAILS_ENV=development bin/setup

- run:
name: Run tests
command: COVERAGE=true bundle exec rake

- store_artifacts:
path: coverage