|
| 1 | +name: cargo-sqlx |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + test-prepare: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + services: |
| 14 | + postgres: |
| 15 | + image: postgres:12 |
| 16 | + env: |
| 17 | + POSTGRES_USER: postgres |
| 18 | + POSTGRES_PASSWORD: postgres |
| 19 | + POSTGRES_DB: postgres |
| 20 | + ports: |
| 21 | + # will assign a random free host port |
| 22 | + - 5432/tcp |
| 23 | + # needed because the postgres container does not provide a healthcheck |
| 24 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v1 |
| 28 | + |
| 29 | + # Rust ------------------------------------------------ |
| 30 | + |
| 31 | + - name: Install Rust toolchain |
| 32 | + uses: actions-rs/toolchain@v1 |
| 33 | + with: |
| 34 | + toolchain: stable |
| 35 | + profile: minimal |
| 36 | + override: true |
| 37 | + |
| 38 | + - name: Cache target/ |
| 39 | + uses: actions/cache@v1 |
| 40 | + with: |
| 41 | + path: target |
| 42 | + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} |
| 43 | + |
| 44 | + # install `cargo-sqlx` |
| 45 | + - run: cargo install -f --path cargo-sqlx/ |
| 46 | + |
| 47 | + # test `cargo sqlx prepare [--check]` |
| 48 | + - working-directory: examples/postgres/todos/ |
| 49 | + env: |
| 50 | + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres |
| 51 | + run: | |
| 52 | + cargo sqlx prepare && |
| 53 | + cargo sqlx prepare --check |
| 54 | +
|
| 55 | + # now we have no connection to the database, we should be able to still build |
| 56 | + - working-directory: examples/postgres/todos/ |
| 57 | + run: | |
| 58 | + cargo clean -p sqlx-example-postgres-todos && |
| 59 | + cargo build |
| 60 | +
|
| 61 | + # check that the application works without rebuilding it |
| 62 | + - working-directory: examples/postgres/todos/ |
| 63 | + env: |
| 64 | + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres |
| 65 | + run: | |
| 66 | + ./target/debug/sqlx-example-postgres-todos add "test if `cargo sqlx prepare` worked" && |
| 67 | + ./target/debug/sqlx-example-postgres-todos done 1 |
| 68 | +
|
| 69 | + - name: Prepare build directory for cache |
| 70 | + run: | |
| 71 | + find ./target/debug -maxdepth 1 -type f -delete \ |
| 72 | + && rm -fr ./target/debug/{deps,.fingerprint}/*sqlx* \ |
| 73 | + && rm -f ./target/.rustc_info.json |
0 commit comments