ci: add comprehensive quality checks before Docker build

Added test job that must pass before building Docker image:
- Code formatting check (mix format --check-formatted)
- Compilation with warnings as errors
- Credo static analysis (--strict mode)
- Full test suite with PostgreSQL + TimescaleDB

Build job now depends on test job passing (needs: test).

This prevents broken code from being deployed to production.
This commit is contained in:
Graham McIntire 2026-03-05 09:14:23 -06:00
parent 0ac99f679c
commit c225078668
No known key found for this signature in database

View file

@ -14,8 +14,70 @@ concurrency:
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: timescale/timescaledb:latest-pg17
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: towerops_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '27.1'
elixir-version: '1.17.3'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libsnmp-dev snmp-mibs-downloader
- name: Restore dependencies cache
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Check code formatting
run: mix format --check-formatted
- name: Compile with warnings as errors
run: mix compile --warnings-as-errors
env:
MIX_ENV: test
- name: Run Credo
run: mix credo --strict
- name: Run tests
run: mix test --warnings-as-errors
env:
MIX_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/towerops_test
build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4