name: Docker Database Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
docker-tests:
name: Docker DB Tests (${{ matrix.db }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
db: [sqlite, postgres, mysql]
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-docker-${{ matrix.db }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-docker-${{ matrix.db }}-
${{ runner.os }}-cargo-
- name: Set up Docker Compose
uses: docker/setup-compose-action@v1
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Start database service (only for pg/mysql jobs)
if: matrix.db != 'sqlite'
run: |
docker compose -f docker-compose.test.yml up -d --wait ${{ matrix.db }}
- name: Set INKLOG_TEST_DB_URL
run: |
case "${{ matrix.db }}" in
sqlite)
echo "INKLOG_TEST_DB_URL=sqlite:///tmp/inklog_ci_test.db?mode=rwc" >> $GITHUB_ENV
;;
postgres)
echo "INKLOG_TEST_DB_URL=postgres://inklog:inklog@localhost:5432/inklog_test" >> $GITHUB_ENV
;;
mysql)
echo "INKLOG_TEST_DB_URL=mysql://inklog:inklog@localhost:3306/inklog_test" >> $GITHUB_ENV
;;
esac
- name: Build tests (${{ matrix.db }} feature)
run: cargo build --tests --features ${{ matrix.db }}
- name: Run Docker integration tests
run: cargo test --test docker --features ${{ matrix.db }} -- --test-threads=1
- name: Run lib tests (${{ matrix.db }} feature)
run: cargo test --lib --features ${{ matrix.db }}
- name: Clippy (${{ matrix.db }} feature)
run: cargo clippy --all-targets --features ${{ matrix.db }} -- -D warnings
- name: Format check
run: cargo fmt --all -- --check
- name: Cleanup Docker services
if: always()
run: docker compose -f docker-compose.test.yml down -v