|
1 | | -name: Rust |
| 1 | +name: Rust CI |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [ "master" ] |
| 5 | + branches: [ "master", "main", "develop" ] |
6 | 6 | pull_request: |
7 | | - branches: [ "master" ] |
| 7 | + branches: [ "master", "main", "develop" ] |
8 | 8 |
|
9 | 9 | env: |
10 | 10 | CARGO_TERM_COLOR: always |
| 11 | + DATABASE_URL: postgresql://postgres:password@localhost:5432/osu_backend_test |
11 | 12 |
|
12 | 13 | jobs: |
13 | | - build: |
14 | | - |
| 14 | + test: |
15 | 15 | runs-on: ubuntu-latest |
| 16 | + |
| 17 | + services: |
| 18 | + postgres: |
| 19 | + image: postgres:15 |
| 20 | + env: |
| 21 | + POSTGRES_PASSWORD: password |
| 22 | + POSTGRES_DB: osu_backend_test |
| 23 | + options: >- |
| 24 | + --health-cmd pg_isready |
| 25 | + --health-interval 10s |
| 26 | + --health-timeout 5s |
| 27 | + --health-retries 5 |
| 28 | + ports: |
| 29 | + - 5432:5432 |
16 | 30 |
|
17 | 31 | steps: |
18 | | - - uses: actions/checkout@v4 |
19 | | - - name: Build |
20 | | - run: cargo build --verbose |
21 | | - - name: Run tests |
22 | | - run: cargo test --verbose |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Checkout migrations |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + repository: Osef-me/migrations |
| 38 | + path: migrations |
| 39 | + |
| 40 | + - uses: actions-rs/toolchain@v1 |
| 41 | + with: |
| 42 | + toolchain: stable |
| 43 | + components: rustfmt, clippy |
| 44 | + |
| 45 | + - name: Cache dependencies |
| 46 | + uses: actions/cache@v3 |
| 47 | + with: |
| 48 | + path: | |
| 49 | + ~/.cargo/registry |
| 50 | + ~/.cargo/git |
| 51 | + target |
| 52 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 53 | + |
| 54 | + - name: Install sqlx-cli |
| 55 | + run: cargo install sqlx-cli --no-default-features --features postgres |
| 56 | + |
| 57 | + - name: Wait for PostgreSQL |
| 58 | + run: | |
| 59 | + until pg_isready -h localhost -p 5432 -U postgres; do |
| 60 | + echo "Waiting for PostgreSQL..." |
| 61 | + sleep 1 |
| 62 | + done |
| 63 | + |
| 64 | + - name: Run migrations |
| 65 | + run: sqlx migrate run |
| 66 | + env: |
| 67 | + DATABASE_URL: ${{ env.DATABASE_URL }} |
| 68 | + working-directory: migrations |
| 69 | + |
| 70 | + - name: Format check |
| 71 | + run: cargo fmt --all -- --check |
| 72 | + |
| 73 | + - name: Clippy check |
| 74 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 75 | + |
| 76 | + - name: Build |
| 77 | + run: cargo build --verbose --all-features |
| 78 | + env: |
| 79 | + DATABASE_URL: ${{ env.DATABASE_URL }} |
| 80 | + |
| 81 | + - name: Run tests |
| 82 | + run: cargo test --verbose --all-features |
| 83 | + env: |
| 84 | + DATABASE_URL: ${{ env.DATABASE_URL }} |
| 85 | + |
| 86 | + - name: Test migrations rollback |
| 87 | + run: | |
| 88 | + sqlx migrate revert |
| 89 | + sqlx migrate run |
| 90 | + env: |
| 91 | + DATABASE_URL: ${{ env.DATABASE_URL }} |
| 92 | + working-directory: migrations |
0 commit comments