Skip to content

Add action to run tests #23

Add action to run tests

Add action to run tests #23

name: Test migrations and draw DB schema
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
env:
DOCKER_LOCALHOST: 172.17.0.1
POSTGRESQL_IMAGE: postgres:15.5
LIQUIBASE_IMAGE: liquibase/liquibase:4.19.0
TBLS_IMAGE: ghcr.io/k1low/tbls:v1.72.0
POSTGRESQL_DB: fintech
MIGRATIONS_FOLDER: product_engine/migrations
LIQUIBASE_CHANGELOG_FILE: changelog.xml
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Run PostgreSQL service
run: docker run --rm --name postgresql -p 5432:5432 -e POSTGRES_DB=${{env.POSTGRESQL_DB}} -e POSTGRES_HOST_AUTH_METHOD=trust --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 -d ${{env.POSTGRESQL_IMAGE}}
- name: Wait for PostgreSQL run and healthy
run: until docker inspect --format "{{json .State.Health.Status }}" postgresql | grep -m 1 "healthy"; do sleep 5; done
- name: Run migrations
run: docker run --rm -w /app -v "$(pwd)/${{env.MIGRATIONS_FOLDER}}":/app --network "host" ${{env.LIQUIBASE_IMAGE}} update --changelog-file=${{env.LIQUIBASE_CHANGELOG_FILE}} --url=jdbc:postgresql://${{env.DOCKER_LOCALHOST}}:5432/${{env.POSTGRESQL_DB}} --username=postgres
- name: Prepare tbls config
run: |
cat <<EOF > .tbls.yml
dsn: postgres://postgres@${{env.DOCKER_LOCALHOST}}:5432/${{env.POSTGRESQL_DB}}?sslmode=disable
docPath: dbdoc
er:
distance: 2
lint:
requireTableComment:
enabled: true
allOrNothing: false
requireColumnComment:
enabled: true
allOrNothing: false
unrelatedTable:
enabled: true
allOrNothing: false
requireColumns:
enabled: true
columns:
- name: id
duplicateRelations:
enabled: true
requireForeignKeyIndex:
enabled: true
exclude:
- databasechangeloglock
- databasechangelog
EOF
- name: Lint database
id: lint_database
run: docker run --rm -w /app -v "$(pwd):/app" --network "host" ${{env.TBLS_IMAGE}} lint
continue-on-error: true
- name: Show warning if lint fails
run: |
if [[ ${{ steps.lint_database.outcome }} == "failure" ]]; then echo "::warning title=DB Lint failed::Some database lint rules aren't met"; fi
- name: Draw DB schema
run: docker run --rm -w /app -v "$(pwd):/app" --network "host" ${{env.TBLS_IMAGE}} doc
if: success() || failure()
- name: Save DB schema to artifacts
uses: actions/[email protected]
with:
name: db-schema
path: dbdoc/schema.svg
if-no-files-found: error