Skip to content

Feat/migrations

Feat/migrations #22

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
ports:
- 5100:5432 # Map port 5100 on the host to 5432 in the container
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test_db
options: >-
--health-cmd="pg_isready -h localhost -p 5432 -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
# Install the dotenv CLI tool to load the .env file
- name: Install dotenv CLI
run: sudo apt-get install -y dotenv
# Install sqlx-cli to manage database and migrations
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features postgres
# Wait for PostgreSQL to be ready on the host's port 5100
- name: Wait for PostgreSQL
run: |
until pg_isready -h localhost -p 5100 -U postgres; do
echo "Waiting for PostgreSQL to be ready on port 5100..."
sleep 2
done
# Set up environment variables for PostgreSQL and from the .env file
- name: Load environment variables from .env
run: dotenv -f .env | tee -a $GITHUB_ENV
# Set up PostgreSQL environment variable for testing on port 5100
- name: Set up PostgreSQL environment variables
run: echo "DATABASE_URL=postgres://postgres:password@localhost:5100/test_db" >> $GITHUB_ENV
# Create the test_db database using sqlx-cli
- name: Create database
run: sqlx database create
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Run migrations using sqlx-cli
- name: Run migrations
run: sqlx migrate run
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Build project
- name: Build project
run: cargo build --verbose
# Run tests
- name: Run tests
run: cargo test
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
# Run linter
- name: Run linter
run: cargo clippy -- -D warnings
# Generate documentation
- name: Generate documentation
run: cargo doc --no-deps --document-private-items