Skip to content

Add CI pipeline

Add CI pipeline #7

Workflow file for this run

name: Run Test Suite
on:
pull_request:
branches:
- main
push:
branches:
- main
- add-ci-tests
jobs:
prebuild:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate SHA256 for postgres_primary.dockerfile
run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV
- name: Calculate SHA256 for postgres_replica.dockerfile
run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV
- name: Compute container registry name
run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and tag primary Docker image
run: docker build -f postgres_primary.dockerfile -t $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} .
- name: Build and tag replica Docker image
run: docker build -f postgres_replica.dockerfile -t $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} .
- name: Push primary Docker image
run: docker push $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }}
- name: Push replica Docker image
run: docker push $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }}
rspec:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [3.1.6, 3.2.5, 3.3.5]
rails: ['~> 7.0.0', '7.1.0', '8.0.0']
name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.rails }}
services:
postgres_primary:
image: $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }}

Check failure on line 58 in .github/workflows/test.yml

View workflow run for this annotation

GitHub Actions / Run Test Suite

Invalid workflow file

The workflow is not valid. .github/workflows/test.yml (Line: 58, Col: 16): Unrecognized named-value: 'env'. Located at position 1 within expression: env.PRIMARY_SHA .github/workflows/test.yml (Line: 69, Col: 16): Unrecognized named-value: 'env'. Located at position 1 within expression: env.REPLICA_SHA
ports:
- 5432:5432
env:
POSTGRES_DB: postgres_primary_test
POSTGRES_USER: postgres_primary_test
POSTGRES_PASSWORD: postgres_primary_test
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
postgres_replica:
image: $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }}
ports:
- 5433:5432
env:
PGUSER: replicator
PGPASSWORD: replicator
PGPORT: 5433
PRIMARY_DATABASE_HOST: postgres_primary
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby: ${{ matrix.ruby }}
- name: Install dependencies
env:
RAILS_VERSION: ${{ matrix.rails }}
run: |
gem install bundler -v 2.5.13
bundle install
- name: Run RSpec tests
env:
PGHOST: postgres_primary
PG_PRIMARY_USER: postgres_primary_test
PG_PRIMARY_PASSWORD: postgres_primary_test
PG_PRIMARY_HOST: postgres_primary
PG_PRIMARY_PORT: 5432
PG_REPLICA_USER: postgres_primary_test
PG_REPLICA_PASSWORD: postgres_primary_test
PG_REPLICA_HOST: postgres-replica
PG_REPLICA_PORT: 5433
run: bundle exec rspec --format progress