Skip to content

Commit

Permalink
Merge pull request #5728 from elasticspoon/feat/update-bin-scripts
Browse files Browse the repository at this point in the history
feat: update bin scripts
  • Loading branch information
compwron authored May 20, 2024
2 parents 36d54ff + 2aa1f6b commit b9d6bd5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,6 @@ If you are using Ubuntu on WSL and receive the following message when trying to
...check out the instructions on [installing google-chrome and chromedriver for WSL Ubuntu](https://github.com/rubyforgood/casa/blob/main/doc/WSL_SETUP.md#google-chrome).

**Installing Packages**
1. `cd casa/`
1. `bundle install` install ruby dependencies.
1. `yarn` install javascript dependencies.

**Database Setup**
1. `bin/rails db:setup` create schema
requires running local postgres, with a role created for whatever user you're running rails as
1. `bin/rails db:seed:replant` generates test data (can be rerun to regenerate test data)

**Compile Assets**
1. `yarn build` compile javascript
  `yarn build:dev` to auto recompile for when you edit js files
3. `yarn build:css` compile css
  `yarn build:css:dev` to auto recompile for when you edit sass files

### Platform Specific Installation Instructions
- [Docker](doc/DOCKER.md)
- [Linux](doc/LINUX_SETUP.md)
Expand All @@ -144,7 +128,9 @@ If you are using Ubuntu on WSL and receive the following message when trying to
1. Install imagemagick to see images locally. Instructions: https://imagemagick.org/script/download.php

## Running the App / Verifying Installation
1. `bin/rails server` or `bin/rails s` to start the local webserver
1. `cd casa/`
1. Run `bin/setup`
1. Run `bin/dev` and visit http://localhost:3000/ to see the app running.

**Logging in with seed users**

Expand Down Expand Up @@ -175,6 +161,9 @@ If you have trouble running tests, check out CI scripts in [`.github/workflows/`
Test coverage is run by simplecov on all builds and aggregated by CodeClimate

**Cleaning up before you pull request**

Run `bin/lint` to run all linters and fix issues. This will run:

1. `bundle exec standardrb --fix` auto-fix Ruby linting issues [more linter info](https://github.com/testdouble/standard)
1. `bundle exec erblint --lint-all --autocorrect` [ERB linter](https://github.com/Shopify/erb-lint)
1. `yarn lint:fix` to run the [JS linter](https://standardjs.com/index.html) and fix issues
Expand Down
7 changes: 7 additions & 0 deletions bin/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

bundle exec standardrb --fix --format progress
bundle exec erblint --lint-all --autocorrect
yarn lint:fix
echo "Linting Factories"
rails factory_bot:lint
46 changes: 34 additions & 12 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
require "fileutils"
require 'fileutils'

# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
system(*args, exception: true) || abort("\n== Command #{args} failed ==")
Expand All @@ -12,27 +12,49 @@ FileUtils.chdir APP_ROOT do
# This script is a way to set up or update your development environment automatically.
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.
expected_ruby_version = `cat .ruby-version`.chomp
current_ruby_version = `ruby -v`.chomp
unless current_ruby_version.include?(expected_ruby_version)
puts "Ruby version must be #{expected_ruby_version}. You are on #{current_ruby_version}"
exit
end

puts "== Installing dependencies =="
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
puts "\n== Installing dependencies =="
system! 'gem install foreman'
system! 'gem install bundler --conservative'
system!('bundle update --bundler --verbose')
system!('bundle check') || system!('bundle install')

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
# puts '\n== Copying sample files =='
# unless File.exist?('config/database.yml')
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
# end

unless File.exist?('.env')
puts '== Setup .env file from .env.example =='
puts "\n== Setup .env file from .env.example =="
system!('cp .env.example .env')
end

puts "\n== Preparing database =="
system! "bin/rails db:prepare"
puts '⚠️ If you use docker to run postgres, make sure your database is running ⚠️'
system! 'bin/rails db:reset'
system! 'bin/rails db:test:prepare'

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! "bin/rails restart"
system! 'bin/rails restart'

puts "\n== Running post-deployment tasks =="
system! 'bin/rake after_party:run'

puts "\n== Installing yarn packages =="
system!('yarn') || abort('install yarn and try again')

puts "\n==Building assets =="
system!('yarn build')
system!('yarn build:css')

puts "\n== Done =="
end
6 changes: 6 additions & 0 deletions bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ chdir APP_ROOT do

puts "\n== Restarting application server =="
system! 'bin/rails restart'

puts "\n==Building assets =="
system!('yarn build')
system!('yarn build:css')

puts "\n== Done =="
end

0 comments on commit b9d6bd5

Please sign in to comment.