133 lines
3.5 KiB
YAML
133 lines
3.5 KiB
YAML
name: Rust
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
SQLX_VERSION: 0.8.6
|
|
SQLX_FEATURES: "rustls,postgres"
|
|
DATABASE_URL: postgres://postgres:password@postgres:5432/newsletter
|
|
APP_DATABASE__HOST: postgres
|
|
APP_KV_STORE__HOST: redis
|
|
RUNNER_TOOL_CACHE: /toolcache
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: password
|
|
POSTGRES_DB: newsletter
|
|
ports:
|
|
- 15432:5432
|
|
redis:
|
|
image: redis
|
|
ports:
|
|
- 16379:6379
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
- name: Install mold linker
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y mold clang
|
|
- name: Install the Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
- name: Install sqlx-cli
|
|
run: cargo install sqlx-cli
|
|
--version=${{ env.SQLX_VERSION }}
|
|
--features ${{ env.SQLX_FEATURES }}
|
|
--no-default-features
|
|
--locked
|
|
- name: Migrate database
|
|
run: cargo sqlx migrate run
|
|
- name: Run tests
|
|
run: TEST_LOG=true cargo test
|
|
- name: Check that queries are fresh
|
|
run: cargo sqlx prepare --check --workspace
|
|
|
|
fmt:
|
|
name: Rustfmt
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install the Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
components: rustfmt
|
|
cache: false
|
|
- name: Enforce formatting
|
|
run: cargo fmt --check
|
|
|
|
clippy:
|
|
name: Clippy
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
SQLX_OFFLINE: true
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
- name: Install mold linker
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y mold clang
|
|
- name: Install the Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
components: clippy
|
|
- name: Linting
|
|
run: cargo clippy -- -D warnings
|
|
|
|
coverage:
|
|
name: Code coverage
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: password
|
|
POSTGRES_DB: newsletter
|
|
ports:
|
|
- 15432:5432
|
|
redis:
|
|
image: redis
|
|
ports:
|
|
- 16379:6379
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install mold linker
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y mold clang
|
|
- name: Install the Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
components: llvm-tools-preview
|
|
cache: false
|
|
- name: Install sqlx-cli
|
|
run: cargo install sqlx-cli
|
|
--version=${{ env.SQLX_VERSION }}
|
|
--features ${{ env.SQLX_FEATURES }}
|
|
--no-default-features
|
|
--locked
|
|
- name: Migrate database
|
|
run: cargo sqlx migrate run
|
|
- name: Install cargo-llvm-cov
|
|
uses: taiki-e/install-action@cargo-llvm-cov
|
|
- name: Generate code coverage
|
|
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
|
|
- name: Generate report
|
|
run: cargo llvm-cov report --html --output-dir coverage
|