From 41a939d4af2e998871b3268d259bd6d7adfa6fb1 Mon Sep 17 00:00:00 2001 From: madmatvey Date: Fri, 17 May 2024 13:22:00 +0400 Subject: [PATCH] actions --- .github/workflows/main.yml | 80 ++++++++++++++++++++++++++++++++++++++ Gemfile.lock | 4 +- config/database.yml | 4 ++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..49272f6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,80 @@ +name: CI + +on: [push] + +jobs: + code_checks: + runs-on: ubuntu-latest + container: + image: ruby:3.2.2 + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: 'db' + MYSQL_USER: 'rails_user' + MYSQL_PASSWORD: 'password' + MYSQL_ROOT_PASSWORD: 'password' + MYSQL_TCP_PORT: 3307 + ports: + - 3307:3307 + # needed because the postgres container does not provide a healthcheck + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + steps: + - uses: actions/checkout@v1 + + - uses: actions/setup-node@v1 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + + - name: Gem cache + id: cache-bundle + uses: actions/cache@v1 + with: + path: vendor/bundle + key: bundle-${{ hashFiles('**/Gemfile.lock') }} + + - name: Bundle install + env: + RAILS_ENV: test + run: | + gem install bundler + bundle install --jobs 4 --retry 3 --path vendor/bundle + - name: Install yarn + run: npm install -g yarn + + # NOTE: Yarn cache doesn't seem to be working quite yet + - name: Get yarn cache dir + id: yarn-cache-dir + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Yarn cache + id: cache-yarn + uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache-dir.outputs.dir }} + key: yarn-${{ hashFiles('**/yarn.lock') }} + + - name: Yarn install + run: yarn install + + - name: Setup DB, Run tests + env: + RAILS_ENV: test + DB_PORT: ${{ job.services.mysql.ports[3307] }} + RAILS_ENV: test + run: | + bin/rails db:create db:schema:load + bundle exec rspec + + - name: Rubocop + run: bundle exec rubocop + + - name: Audit + run: bundle exec rake audit \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index c780028..2c935f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,7 +181,8 @@ GEM regexp_parser (2.9.1) reline (0.4.2) io-console (~> 0.5) - rexml (3.2.6) + rexml (3.2.8) + strscan (>= 3.0.9) rspec-core (3.13.0) rspec-support (~> 3.13.0) rspec-expectations (3.13.0) @@ -246,6 +247,7 @@ GEM stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) + strscan (3.1.0) thor (1.3.1) timeout (0.4.1) turbo-rails (1.5.0) diff --git a/config/database.yml b/config/database.yml index 7059849..782d360 100644 --- a/config/database.yml +++ b/config/database.yml @@ -30,6 +30,10 @@ development: test: <<: *default database: homework_assignment_2024_test + <% if ENV['CI'] %> + host: 127.0.0.1 + port: <%= ENV['DB_PORT'] %> + <% end %> # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is