diff --git a/.github/workflows/build-examples.yml b/.github/workflows/build-examples.yml new file mode 100644 index 00000000..acd1fa2c --- /dev/null +++ b/.github/workflows/build-examples.yml @@ -0,0 +1,251 @@ +name: Build Examples + +on: + pull_request: + push: + branches: + - master + +jobs: + sqlite-todos: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Install sqlite3 + run: | + sudo apt update + sudo apt install -yq sqlite3 + + - name: Create sqlite db + working-directory: examples/sqlite/todos + run: echo ".exit" | sqlite3 todos.db -init schema.sql + + - working-directory: examples/sqlite/todos + # required because the `env` key does not expand environment variables + run: DATABASE_URL=sqlite://$PWD/todos.db cargo build + + postgres-realworld: + runs-on: ubuntu-latest + + strategy: + matrix: + postgres: [9.4, 10, 12] + + services: + postgres: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: realworld + ports: + - 5432/tcp + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # ----------------------------------------------------- + # install the psql client + - name: Install PostgreSQL client + run: | + sudo bash -c "echo deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main >> /etc/apt/sources.list.d/pgdg.list" + wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - + sudo apt-get update + sudo apt-get -yq install libpq-dev postgresql-client-${{ matrix.postgres }} + + # load schema.sql + - working-directory: examples/postgres/realworld + run: psql -d $DATABASE_URL -f ./schema.sql + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/realworld + + # build the example + - working-directory: examples/postgres/realworld + run: cargo build + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/realworld + + postgres-listen: + runs-on: ubuntu-latest + + strategy: + matrix: + postgres: [9.4, 10, 12] + + services: + postgres: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432/tcp + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # build the example + - working-directory: examples/postgres/listen + run: cargo build + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres + + postgres-todos: + runs-on: ubuntu-latest + + strategy: + matrix: + postgres: [9.4, 10, 12] + + services: + postgres: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: todos + ports: + - 5432/tcp + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # ----------------------------------------------------- + + # install the psql client + - name: Install PostgreSQL client + run: | + sudo bash -c "echo deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main >> /etc/apt/sources.list.d/pgdg.list" + wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - + sudo apt-get update + sudo apt-get -yq install libpq-dev postgresql-client-${{ matrix.postgres }} + + # load schema.sql + - working-directory: examples/postgres/todos + run: psql -d $DATABASE_URL -f ./schema.sql + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/todos + + # build the example + - working-directory: examples/postgres/todos + run: cargo build + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/todos + + mysql-todos: + runs-on: ubuntu-latest + + strategy: + matrix: + image: ["mysql:5.7.28", "mysql:8.0.18", "mariadb:10.1.43", "mariadb:10.4.11"] + + services: + mysql: + image: ${{ matrix.image }} + env: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: todos + ports: + # will assign a random free host port + - 3306/tcp + # needed because the container does not provide a healthcheck + options: >- + --health-cmd "mysqladmin ping --silent" --health-interval 30s --health-timeout 30s + --health-retries 10 -v /data/mysql:/var/lib/mysql + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Load schema + working-directory: examples/mysql/todos + run: | + export CONTAINER_ID=$(docker ps --filter "ancestor=${{ matrix.image }}" --format "{{.ID}}") + docker cp schema.sql $CONTAINER_ID:/schema.sql + docker exec $CONTAINER_ID bash -c "mysql -uroot -ppassword todos < /schema.sql" + + - working-directory: examples/mysql/todos + run: cargo build + env: + DATABASE_URL: mysql://root:password@localhost:${{ job.services.mysql.ports[3306] }}/todos + diff --git a/examples/postgres/listen/src/main.rs b/examples/postgres/listen/src/main.rs index 1f902e15..16dd2dfa 100644 --- a/examples/postgres/listen/src/main.rs +++ b/examples/postgres/listen/src/main.rs @@ -24,7 +24,7 @@ async fn main() -> Result<(), Box> { println!("Starting LISTEN loop."); - listener.listen_all(&["chan0", "chan1", "chan2"]).await?; + listener.listen_all(vec!["chan0", "chan1", "chan2"]).await?; let mut counter = 0usize; loop { diff --git a/examples/postgres/realworld/schema.sql b/examples/postgres/realworld/schema.sql index 2d53d7a5..cb465e78 100644 --- a/examples/postgres/realworld/schema.sql +++ b/examples/postgres/realworld/schema.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS users ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + id BIGSERIAL PRIMARY KEY, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ, diff --git a/examples/postgres/todos/schema.sql b/examples/postgres/todos/schema.sql index 51b23fe2..d064112e 100644 --- a/examples/postgres/todos/schema.sql +++ b/examples/postgres/todos/schema.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS todos ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + id BIGSERIAL PRIMARY KEY, description TEXT NOT NULL, done BOOLEAN NOT NULL DEFAULT FALSE ); diff --git a/examples/postgres/todos/src/main.rs b/examples/postgres/todos/src/main.rs index 918c6bad..90942bb6 100644 --- a/examples/postgres/todos/src/main.rs +++ b/examples/postgres/todos/src/main.rs @@ -72,7 +72,7 @@ WHERE id = $1 Ok(rows_affected > 0) } -async fn list_todos(pool: &mut PgPool) -> anyhow::Result<()> { +async fn list_todos(pool: &PgPool) -> anyhow::Result<()> { let recs = sqlx::query!( r#" SELECT id, description, done