Updates CI workflow for realworld

* Moves realworld into a separate file since it's long
* Adds checkout, db provisioning, and build steps for postgres and
  sqlite
This commit is contained in:
Samani G. Gikandi 2020-04-15 12:03:15 -07:00 committed by Ryan Leckey
parent 841d9a7f45
commit 45744e8033
2 changed files with 111 additions and 55 deletions

View file

@ -39,61 +39,6 @@ jobs:
# required because the `env` key does not expand environment variables
run: DATABASE_URL=sqlite://$PWD/todos.db cargo build
postgres-realworld:
runs-on: ubuntu-latest
strategy:
matrix:
postgres: [9.4, 10, 12]
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: realworld
ports:
- 5432/tcp
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v1
# Rust ------------------------------------------------
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Cache target/
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
# -----------------------------------------------------
# load schema.sql
- name: Load schema
working-directory: examples/postgres/realworld
run: |
export CONTAINER_ID=$(docker ps --filter "ancestor=postgres:${{ matrix.postgres }}" --format "{{.ID}}")
docker cp schema.sql $CONTAINER_ID:/schema.sql
docker exec $CONTAINER_ID bash -c "psql -d $DATABASE_URL -f ./schema.sql"
env:
# the in-container port is always 5432
DATABASE_URL: postgres://postgres:postgres@localhost:5432/realworld
# build the example
- working-directory: examples/postgres/realworld
run: cargo build
env:
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/realworld
postgres-listen:
runs-on: ubuntu-latest

111
.github/workflows/realworld.yml vendored Normal file
View file

@ -0,0 +1,111 @@
name: Build realworld
on:
pull_request:
push:
branches:
- master
jobs:
postgres:
runs-on: ubuntu-latest
strategy:
matrix:
postgres: [9.6, 10, 12]
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: realworld
ports:
- 5432/tcp
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v1
# Rust ------------------------------------------------
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Cache target/
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
# -----------------------------------------------------
- name: Load schema
working-directory: examples/realworld
run: |
export CONTAINER_ID=$(docker ps --filter "ancestor=postgres:${{ matrix.postgres }}" --format "{{.ID}}")
docker cp schema/postgres.sql $CONTAINER_ID:/schema.sql
docker exec $CONTAINER_ID bash -c "psql -d $DATABASE_URL -f ./schema.sql"
env:
# the in-container port is always 5432
DATABASE_URL: postgres://postgres:postgres@localhost:5432/realworld
- name: cargo build
run: cargo build --features postgres
working-directory: examples/realworld
env:
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/realworld
- name: run API integration tests
working-directory: examples/realworld
run: |
cargo run --features postgres -- --db postgres &
sleep 5;
npx newman@latest run https://raw.githubusercontent.com/gothinkster/realworld/master/api/Conduit.postman_collection.json \
--global-var "APIURL=http://localhost:8080/api" \
--global-var "USERNAME=sqlx_`date +%s`" \
--global-var "EMAIL=sqlx_`date +%s`@not.a.real.email" \
--global-var "PASSWORD=insecure"
env:
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/realworld
sqlite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Cache target/
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install sqlite3
run: |
sudo apt-get update
sudo apt-get install -y sqlite3
- name: Initialize db
working-directory: examples/realworld
run: |
sqlite3 realworld.db < schema/sqlite.sql
- name: cargo build
run: DATABASE_URL=sqlite://${PWD}/realworld.db cargo build --features sqlite
working-directory: examples/realworld
# TODO: run integration tests once #193 is resolved