image: "rust:latest" services: - postgres:latest variables: POSTGRES_DB: newsletter POSTGRES_USER: postgres POSTGRES_PASSWORD: password POSTGRES_HOST: postgres DB_PORT: 5432 DATABASE_URL: "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$DB_PORT/$POSTGRES_DB" APP_DATABASE__HOST: $POSTGRES_HOST cache: # Caches build artifacts so we don't build from scratch in both build and test key: ${CI_COMMIT_REF_SLUG} paths: - .cargo/bin - .cargo/registry/index - .cargo/registry/cache - target/debug/deps - target/debug/build policy: pull-push default: before_script: - export CARGO_HOME="$CI_PROJECT_DIR/.cargo" - export PATH="$CARGO_HOME/bin:$PATH" - rustc --version - cargo --version - if ! [ -x "$(command -v cargo-sqlx)" ]; then cargo install --version='~0.7' sqlx-cli --no-default-features --features rustls,postgres; fi - apt update -yq && apt-get install -yq postgresql-client - SKIP_DOCKER=true ./scripts/init_db.sh # This is to ensure that the database is reachable and give it some time to initialize. - until psql "dbname=$POSTGRES_DB user=$POSTGRES_USER password=$POSTGRES_PASSWORD host=postgres" -c '\l'; do sleep 3; done stages: - build - test build: stage: build script: - cargo build test-code: stage: test script: - cargo test - if ! [ -x "$(command -v cargo-tarpaulin)" ]; then cargo install cargo-tarpaulin; fi - cargo tarpaulin --ignore-tests lint-code: stage: test script: - rustup component add clippy - cargo clippy -- -D warnings