From 049c3926e66f22ea7f1ad09f3d06cc43d9992f61 Mon Sep 17 00:00:00 2001 From: Evangelos Giataganas Date: Fri, 11 Aug 2023 14:26:42 +0300 Subject: [PATCH] Move testing to separate file --- .github/actions/setup/action.yml | 21 --------- .github/workflows/build.yml | 51 ++++++-------------- .github/workflows/testing.yml | 81 ++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 58 deletions(-) delete mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/testing.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml deleted file mode 100644 index 2889b2d..0000000 --- a/.github/actions/setup/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Setup - -runs: - using: composite - steps: - - name: Install postgres client - shell: bash - run: | - sudo apt-get -yqq install libpq-dev - - name: Install gems - shell: bash - run: | - gem install bundler -v 2.4.17 - bundle install --jobs 4 --retry 3 --path vendor/bundle - - name: Setup database - shell: bash - env: - DATABASE_URL: postgres://postgres:postgres@localhost:5432/test - RAILS_ENV: test - run: | - bundle exec rails db:create db:schema:load diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a52296e..864818f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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}}" diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..6d39afa --- /dev/null +++ b/.github/workflows/testing.yml @@ -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