From 85b5a8227f5d5fe4c0c22a19269b691d426d5c19 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Tue, 22 Aug 2023 09:24:56 -0400 Subject: [PATCH] update workflows --- .github/pre-commit | 25 ++++++++++++++++++++++ .github/workflows/tests.yml | 2 +- README.md | 34 ++++++------------------------ docker-compose.yml | 2 +- .env-dev-values => env.development | 0 .env-example => env.example | 0 init.sh | 28 ++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 30 deletions(-) create mode 100755 .github/pre-commit rename .env-dev-values => env.development (100%) rename .env-example => env.example (100%) create mode 100755 init.sh diff --git a/.github/pre-commit b/.github/pre-commit new file mode 100755 index 0000000..41ee58a --- /dev/null +++ b/.github/pre-commit @@ -0,0 +1,25 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". +#!/bin/sh + +set -e +rubyfiles=$(git diff --cached --name-only --diff-filter=ACM "*.rb" "Gemfile" | tr '\n' ' ') +[ -z "$rubyfiles" ] && exit 0 + +# Standardize all ruby files +echo "๐Ÿงน Formatting staged Ruby files using standardrb ($(echo $rubyfiles | wc -w | awk '{print $1}') total)" +echo "$rubyfiles" | xargs docker-compose run --rm web bundle exec standardrb --fix + +# Add back the modified/prettified files to staging +echo "$rubyfiles" | xargs git add + +echo "๐Ÿ“‹ Running tests with rspec" +docker-compose run --rm web bundle exec rspec --format progress + +exit 0 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2e4fa4d..88314e6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Create .env file - run: cat .env-example .env-dev-values > .env + run: cat env.* > .env - name: Load .env file uses: xom9ikk/dotenv@v2 - name: Set up Ruby 3.2 diff --git a/README.md b/README.md index e0257fd..1f54440 100644 --- a/README.md +++ b/README.md @@ -11,41 +11,19 @@ git clone git@github.com:mlibrary/get-this.git cd get-this ``` -copy .env-example to .env - -``` -cp .env-example .env -``` - -edit .env with actual environment variables; ask a developer if you need them - -build container -``` -docker-compose build -``` - -bundle install -``` -docker-compose run --rm web bundle install +run the `init.sh` script. +```bash +./init.sh ``` -npm install -``` -docker-compose run --rm web npm install -``` - -build the css - -``` -docker-compose run --rm web npm run build -``` +edit .env with the appropriate environment variables start containers -``` + +```bash docker-compose up -d ``` - ## Updating `institution_hours_exceptions.json` `config/institution_hours_exceptions.json` is a static file that needs to be updated yearly. diff --git a/docker-compose.yml b/docker-compose.yml index f1747c7..59e26ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: - gem_cache:/gems env_file: - .env - - .env-dev-values + - env.development command: - bundle - exec diff --git a/.env-dev-values b/env.development similarity index 100% rename from .env-dev-values rename to env.development diff --git a/.env-example b/env.example similarity index 100% rename from .env-example rename to env.example diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..29eff30 --- /dev/null +++ b/init.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +#must be run from the project root directory +if [ -f ".env" ]; then + echo "๐ŸŒŽ .env exists. Leaving alone" +else + echo "๐ŸŒŽ .env does not exist. Copying env.example to .env" + cp env.example .env +fi + +if [ -f ".git/hooks/pre-commit" ]; then + echo "๐Ÿช .git/hooks/pre-commit exists. Leaving alone" +else + echo " ๐Ÿช .git/hooks/pre-commit does not exist. Copying .github/pre-commit to .git/hooks/" + cp .github/pre-commit .git/hooks/pre-commit +fi + +echo "๐Ÿšข Build docker images" +docker-compose build + +echo "๐Ÿ“ฆ Installing Gems" +docker-compose run --rm web bundle + +echo "๐Ÿ“ฆ Installing Node modules" +docker-compose run --rm web npm install + +echo "๐Ÿ“ฆ Building js and css" +docker-compose run --rm web npm run build