Skip to content

Commit 0c19ee9

Browse files
committed
add basic integration test for cargo-sqlx
1 parent 70ee3e3 commit 0c19ee9

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/cargo-sqlx.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
- name: Load schema
45+
working-directory: examples/mysql/todos
46+
run: |
47+
export CONTAINER_ID=$(docker ps --filter "ancestor=postgres:${{ matrix.postgres }}" --format "{{.ID}}")
48+
docker cp schema.sql $CONTAINER_ID:/schema.sql
49+
docker exec $CONTAINER_ID bash -c "psql -d $DATABASE_URL -f ./schema.sql"
50+
51+
- name: install cargo-sqlx
52+
run: cargo install -f --path cargo-sqlx/
53+
54+
- name: test `cargo sqlx prepare [--check]`
55+
working-directory: examples/postgres/todos/
56+
env:
57+
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres
58+
run: |
59+
cargo sqlx prepare &&
60+
cargo sqlx prepare --check
61+
62+
# now we have no connection to the database, we should be able to still build
63+
- name: build example without DB
64+
working-directory: examples/postgres/todos/
65+
run: |
66+
cargo clean -p sqlx-example-postgres-todos &&
67+
cargo build
68+
69+
# check that the application works without rebuilding it
70+
- name: run example
71+
working-directory: examples/postgres/todos/
72+
env:
73+
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres
74+
run: |
75+
./target/debug/sqlx-example-postgres-todos add "test if `cargo sqlx prepare` worked" &&
76+
./target/debug/sqlx-example-postgres-todos done 1
77+
78+
- name: Prepare build directory for cache
79+
run: |
80+
find ./target/debug -maxdepth 1 -type f -delete \
81+
&& rm -fr ./target/debug/{deps,.fingerprint}/*sqlx* \
82+
&& rm -f ./target/.rustc_info.json

0 commit comments

Comments
 (0)