test ci #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rust CI | |
| on: | |
| push: | |
| branches: [ "master", "main", "develop" ] | |
| pull_request: | |
| branches: [ "master", "main", "develop" ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| DATABASE_URL: postgresql://postgres:password@localhost:5432/osu_backend_test | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_DB: osu_backend_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Checkout migrations | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Osef-me/migrations | |
| path: migrations | |
| - uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| components: rustfmt, clippy | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Install sqlx-cli | |
| run: cargo install sqlx-cli --no-default-features --features postgres | |
| - name: Wait for PostgreSQL | |
| run: | | |
| until pg_isready -h localhost -p 5432 -U postgres; do | |
| echo "Waiting for PostgreSQL..." | |
| sleep 1 | |
| done | |
| - name: Run migrations | |
| run: sqlx migrate run | |
| env: | |
| DATABASE_URL: ${{ env.DATABASE_URL }} | |
| - name: Format check | |
| run: cargo fmt --all -- --check | |
| - name: Clippy check | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Build | |
| run: cargo build --verbose --all-features | |
| env: | |
| DATABASE_URL: ${{ env.DATABASE_URL }} | |
| - name: Run tests | |
| run: cargo test --verbose --all-features | |
| env: | |
| DATABASE_URL: ${{ env.DATABASE_URL }} | |
| - name: Test migrations rollback | |
| run: | | |
| sqlx migrate revert | |
| sqlx migrate run | |
| env: | |
| DATABASE_URL: ${{ env.DATABASE_URL }} |