Commit 4b6b2bc
Changed files (10)
bin/bootstrap
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# bin/bootstrap: Resolve all dependencies that the application requires to run.
+set -e
+
+cd "$(dirname "$0")/.."
+
+if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
+ brew bundle check >/dev/null 2>&1 || {
+ echo "==> Installing Homebrew dependencies…"
+ brew bundle
+ }
+fi
+
+if [ -f ".ruby-version" ] && [ -z "$(rbenv version-name 2>/dev/null)" ]; then
+ echo "==> Installing Ruby…"
+ rbenv install --skip-existing
+ which bundle >/dev/null 2>&1 || {
+ gem install bundler
+ rbenv rehash
+ }
+fi
+
+if [ -f "Gemfile" ]; then
+ echo "==> Installing gem dependencies…"
+ bundle check --path vendor/bundle >/dev/null 2>&1 || {
+ bundle install --path vendor/bundle --quiet --without production
+ }
+fi
bin/cibuild
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# bin/cibuild: Setup environment for CI to run tests. This is primarily
+# designed to run on the continuous integration server.
+
+set -e
+
+cd "$(dirname "$0")/.."
+
+echo "Tests started at…"
+date "+%H:%M:%S"
+
+# GC customizations
+export RUBY_GC_MALLOC_LIMIT=79000000
+export RUBY_GC_HEAP_INIT_SLOTS=800000
+export RUBY_HEAP_FREE_MIN=100000
+export RUBY_HEAP_SLOTS_INCREMENT=400000
+export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
+
+# setup environment
+RAILS_ROOT="$(cd "$(dirname "$0")"/.. && pwd)"
+export RAILS_ROOT
+export RAILS_ENV="test"
+export RACK_ROOT="$RAILS_ROOT"
+export RACK_ENV="$RAILS_ENV"
+export DISABLE_SPRING=1
+export HEADLESS=1
+
+test -d "/usr/share/rbenv/shims" && {
+ export PATH=/usr/share/rbenv/shims:$PATH
+}
+export PATH="$RACK_ROOT/bin:$PATH"
+
+# run tests
+echo "Running tests …"
+date "+%H:%M:%S"
+bin/test
bin/deploy
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+git push heroku master
bin/lint
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+bin/bootstrap
+bin/rake lint:all
bin/test
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# bin/test: Run test suite for application. Optionally pass in a path to an
+# individual test file to run a single test.
+
+set -e
+
+cd "$(dirname "$0")/.."
+
+[ -z "$DEBUG" ] || set -x
+
+RACK_ROOT="$(cd "$(dirname "$0")"/.. && pwd)"
+export RACK_ROOT
+
+if [ "$RAILS_ENV" = "test" ] || [ "$RACK_ENV" = "test" ]; then
+ # if executed and the environment is already set to `test`, then we want a
+ # clean from scratch application. This almost always means a ci environment,
+ # since we set the environment to `test` directly in `bin/cibuild`.
+ bin/setup
+else
+ # if the environment isn't set to `test`, set it to `test` and update the
+ # application to ensure all dependencies are met as well as any other things
+ # that need to be up to date, like db migrations. The environment not having
+ # already been set to `test` almost always means this is being called on it's
+ # own from a `development` environment.
+ export RAILS_ENV="test" RACK_ENV="test"
+
+ bin/update
+fi
+
+echo "==> Running tests…"
+
+if [ -n "$1" ]; then
+ # pass arguments to test call. This is useful for calling a single test.
+ bin/rake test "$1"
+else
+ bin/rake test
+ bin/yarn test
+fi
bin/update
@@ -1,29 +1,16 @@
-#!/usr/bin/env ruby
-require 'pathname'
-require 'fileutils'
-include FileUtils
+#!/bin/sh
-# path to your application root.
-APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+# bin/update: Update application to run for its current checkout.
-def system!(*args)
- system(*args) || abort("\n== Command #{args} failed ==")
-end
+set -e
-chdir APP_ROOT do
- # This script is a way to update your development environment automatically.
- # Add necessary update steps to this file.
+cd "$(dirname "$0")/.."
- puts '== Installing dependencies =='
- system! 'gem install bundler --conservative'
- system('bundle check') || system!('bundle install')
+bin/bootstrap
- puts "\n== Updating database =="
- system! 'bin/rails db:migrate'
-
- puts "\n== Removing old logs and tempfiles =="
- system! 'bin/rails log:clear tmp:clear'
-
- puts "\n== Restarting application server =="
- system! 'bin/rails restart'
-end
+echo "==> Updating database…"
+bin/rake db:migrate
+echo "==> Removing old logs and tempfiles…"
+bin/rails log:clear tmp:clear
+echo "==> Restarting application server…"
+bin/rails restart
lib/tasks/lint.rake
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+namespace :lint do
+ begin
+ require 'rubocop/rake_task'
+ require 'bundler/audit/task'
+
+ RuboCop::RakeTask.new
+ Bundler::Audit::Task.new
+ rescue LoadError => error
+ puts error.message
+ end
+
+ desc "run the brakeman vulnerability scanner"
+ task :brakeman do
+ require 'brakeman'
+ Brakeman.run(
+ app_path: Rails.root,
+ print_report: true,
+ config_file: Rails.root.join("config", "brakeman"),
+ )
+ end
+
+ desc "Run linters to check the quality of the code."
+ task all: [:rubocop, 'bundle:audit', :brakeman]
+end
Gemfile
@@ -45,12 +45,13 @@ group :development, :test do
end
group :development do
- # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
- # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
+ gem 'bundler-audit'
+ gem 'brakeman'
+ gem 'rubocop'
end
group :production do
Gemfile.lock
@@ -48,9 +48,14 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0)
+ ast (2.4.0)
bcrypt (3.1.11)
bindex (0.5.0)
+ brakeman (4.2.0)
builder (3.2.3)
+ bundler-audit (0.6.0)
+ bundler (~> 1.2)
+ thor (~> 0.18)
byebug (9.1.0)
capybara (2.15.4)
addressable
@@ -118,7 +123,11 @@ GEM
nio4r (2.1.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
+ parallel (1.12.1)
+ parser (2.5.0.3)
+ ast (~> 2.4.0)
pg (0.21.0)
+ powerpack (0.1.1)
public_suffix (3.0.0)
puma (3.10.0)
rack (2.0.3)
@@ -161,6 +170,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
+ rainbow (3.0.0)
rake (12.1.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
@@ -183,6 +193,14 @@ GEM
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
+ rubocop (0.53.0)
+ parallel (~> 1.10)
+ parser (>= 2.5)
+ powerpack (~> 0.1)
+ rainbow (>= 2.2.2, < 4.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (~> 1.0, >= 1.0.1)
+ ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
safe_yaml (1.0.4)
@@ -230,6 +248,7 @@ GEM
turbolinks-source (5.0.3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
+ unicode-display_width (1.3.0)
web-console (3.5.1)
actionview (>= 5.0)
activemodel (>= 5.0)
@@ -263,6 +282,8 @@ PLATFORMS
DEPENDENCIES
activerecord-session_store
bcrypt (~> 3.1.7)
+ brakeman
+ bundler-audit
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
@@ -281,6 +302,7 @@ DEPENDENCIES
rails-controller-testing
rails_12factor
rspec-rails (~> 3.6)
+ rubocop
saml-kit (~> 1.0)
sass-rails (~> 5.0)
scim-shady (~> 0.2)
Rakefile
@@ -4,3 +4,5 @@
require_relative 'config/application'
Rails.application.load_tasks
+
+task test: [:spec]