Skip to content

Commit

Permalink
Make ruby tests a reusable workflow
Browse files Browse the repository at this point in the history
This application depends on the Content Schemas. Making the tests
reusable allows Publishing API to run the tests when the Content Schemas
are updated.
  • Loading branch information
theseanything committed Jan 11, 2023
1 parent bffe254 commit 856f5f3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 46 deletions.
47 changes: 1 addition & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,5 @@ jobs:

test-ruby:
name: Test Ruby
runs-on: ubuntu-latest
steps:
- name: Setup Postgres
id: setup-postgres
uses: alphagov/govuk-infrastructure/.github/actions/setup-postgres@main
uses: ./.github/workflows/rspec.yml

- name: Setup Redis
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main

- name: Checkout repository
uses: actions/checkout@v3

- name: Checkout Publishing API (for Content Schemas)
uses: actions/checkout@v3
with:
repository: alphagov/publishing-api
ref: deployed-to-production
path: vendor/publishing-api

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

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Precompile assets
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main

- name: Initialize database
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-postgres.outputs.db-url }}
run: bundle exec rails db:setup

- name: Run RSpec
env:
RAILS_ENV: test
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas
TEST_DATABASE_URL: ${{ steps.setup-postgres.outputs.db-url }}
run: bundle exec rake spec

- name: Check i18n coverage
env:
RAILS_ENV: test
run: bundle exec rake i18n_cov:ci
68 changes: 68 additions & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Run RSpec

on:
workflow_call:
inputs:
ref:
description: 'The branch, tag or SHA to checkout'
required: false
type: string
publishingApiRef:
description: 'The branch, tag or SHA to checkout Publishing API'
required: false
default: 'deployed-to-production'
type: string

jobs:
run-rspec:
name: Run RSpec
runs-on: ubuntu-latest
steps:
- name: Setup Postgres
id: setup-postgres
uses: alphagov/govuk-infrastructure/.github/actions/setup-postgres@main

- name: Setup Redis
uses: alphagov/govuk-infrastructure/.github/actions/setup-redis@main

- name: Checkout repository
uses: actions/checkout@v3
with:
repository: alphagov/content-publisher
ref: ${{ inputs.ref || github.ref }}

- name: Checkout Publishing API (for Content Schemas)
uses: actions/checkout@v3
with:
repository: alphagov/publishing-api
ref: ${{ inputs.publishingApiRef }}
path: vendor/publishing-api

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

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Precompile assets
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main

- name: Initialize database
env:
RAILS_ENV: test
TEST_DATABASE_URL: ${{ steps.setup-postgres.outputs.db-url }}
run: bundle exec rails db:setup

- name: Run RSpec
env:
RAILS_ENV: test
GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas
TEST_DATABASE_URL: ${{ steps.setup-postgres.outputs.db-url }}
run: bundle exec rake spec

- name: Check i18n coverage
env:
RAILS_ENV: test
run: bundle exec rake i18n_cov:ci

0 comments on commit 856f5f3

Please sign in to comment.