Skip to content

Commit

Permalink
Move testing to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
EGiataganas committed Aug 11, 2023
1 parent bc71609 commit 049c392
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 58 deletions.
21 changes: 0 additions & 21 deletions .github/actions/setup/action.yml

This file was deleted.

51 changes: 14 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,17 @@ jobs:
with:
rubocop: true

spec:
runs-on: ubuntu-20.04

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Ruby 3.2.2
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup
uses: ./.github/actions/setup

- name: Build assets
run: bundle exec rails assets:precompile

- name: Run specs
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
RAILS_ENV: test
run: |
bundle exec rake spec
specs:
uses: ./.github/workflows/testing.yml
strategy:
matrix:
specs:
- { group: "jobs", pattern: "*_spec.rb"}
- { group: "models", pattern: "*_spec.rb"}
- { group: "requests", pattern: "*_spec.rb"}
- { group: "services", pattern: "*_spec.rb"}
- { group: "system", pattern: "*_spec.rb"}
fail-fast: false
with:
name: "${{matrix.specs.group}}: ${{matrix.specs.pattern }}"
include: "spec/${{matrix.specs.group}}/**/${{matrix.specs.pattern}}"
81 changes: 81 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: Testing

on:
workflow_call:
inputs:
exclude:
type: string
required: false
default: ""
include:
type: string
required: false
default: "spec/**/*_spec.rb"
name:
type: string
required: true
ruby-version:
type: string
default: "3.2.2"

jobs:
tests:
name: ${{ inputs.name }}
runs-on: ubuntu-latest

services:
postgres:
image: postgres
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Ruby ${{ inputs.ruby-version }} and install gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v3
if: hashFiles('yarn.lock') != ''
with:
node-version-file: .node-version
cache: "yarn"

- name: Install packages
run: |
yarn install --frozen-lockfile
- name: Install postgres client
shell: bash
run: |
sudo apt-get -yqq install libpq-dev
- name: Setup test database
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
RAILS_ENV: test
run: |
bundle exec rails db:create db:schema:load
- name: Assets precompile
run: bundle exec rake assets:precompile --trace

- name: Run specs
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test
RAILS_ENV: test
SPEC_OPTS: '-f doc --exclude "${{ inputs.exclude }}" --pattern "${{ inputs.include }}"'
run: |
bundle exec rake spec

0 comments on commit 049c392

Please sign in to comment.