From b7c77be11f517913f37911f2504a847538e36740 Mon Sep 17 00:00:00 2001 From: Chris Lowis Date: Thu, 3 Aug 2023 18:18:26 -0500 Subject: [PATCH] Run tests in github actions To set this up I more or less followed an example I found online[1]. I decided to use the "alpine" postgres image as the author suggests to make the container creation quicker. I opted for the latest postgres 15, as this matches my development environment (and, I hope, production when we get there). [1] https://boringrails.com/articles/building-a-rails-ci-pipeline-with-github-actions/ --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++ Gemfile.lock | 5 ++++ 2 files changed, 62 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c241df55 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI +on: [push] + +jobs: + linters: + name: Linters + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Run linters + run: | + bin/rake rubocop + + tests: + name: Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_USER: myapp + POSTGRES_DB: myapp_test + POSTGRES_PASSWORD: password + ports: ["5432:5432"] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Setup test database + env: + RAILS_ENV: test + PGHOST: localhost + PGUSER: myapp + PGPASSWORD: password + run: | + bin/rails db:setup + + - name: Run tests + env: + RAILS_ENV: test + PGHOST: localhost + PGUSER: myapp + PGPASSWORD: password + run: bin/rake test:all diff --git a/Gemfile.lock b/Gemfile.lock index b55879c9..0179bad3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,6 +149,8 @@ GEM nio4r (2.5.9) nokogiri (1.15.3-arm64-darwin) racc (~> 1.4) + nokogiri (1.15.3-x86_64-linux) + racc (~> 1.4) parallel (1.23.0) parser (3.2.2.3) ast (~> 2.4.1) @@ -235,6 +237,8 @@ GEM railties (>= 6.0.0) tailwindcss-rails (2.0.30-arm64-darwin) railties (>= 6.0.0) + tailwindcss-rails (2.0.30-x86_64-linux) + railties (>= 6.0.0) thor (1.2.2) timeout (0.4.0) turbo-rails (1.4.0) @@ -260,6 +264,7 @@ GEM PLATFORMS arm64-darwin-22 + x86_64-linux DEPENDENCIES bootsnap