libpq 6.0.1

Safe binding for libpq
Documentation
on: [push, pull_request]

env:
  CARGO_TERM_COLOR: always
  PQ_DSN: postgres://postgres:root@localhost/

jobs:
  lint_fmt:
    name: cargo fmt
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Check formating
        run: cargo fmt -- --check

  lint_clippy:
    name: Clippy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - name: Run clippy
        run: cargo clippy --all-targets --all-features -- --deny warnings

  tests:
    name: Tests
    strategy:
      matrix:
        rust: ["stable", "beta", "nightly"]
        os: ["ubuntu-latest", "macos-latest", "windows-latest"]
        pg: ["14", "15", "16", "17", "18"]
        mode: ["debug", "release"]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}

      - uses: ikalnytskyi/action-setup-postgres@v8
        with:
          username: postgres
          password: root
          postgres-version: ${{ matrix.pg }}

      - name: Rustup update
        run: rustup update

      - name: Run tests (debug)
        if: matrix.mode == 'debug'
        run: cargo test --workspace --features "v${{ matrix.pg }}"

      - name: Run tests (release)
        if: matrix.mode == 'release'
        run: cargo test --workspace --features "v${{ matrix.pg }}" --release

  valgrind:
    name: Memory check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Install postgreSQL (Linux)
        run: |
          sudo apt-get update
          sudo apt-get install -y libpq-dev postgresql valgrind
          sudo service postgresql start && sleep 3
          sudo -u postgres psql --command "ALTER USER postgres PASSWORD 'root';"

      - name: build
        run: cargo test --no-run --features v14
      - name: valgrind
        run: valgrind --leak-check=full --error-exitcode=1 $(find target/debug/deps -executable -type f -name 'libpq-*')

  mimalloc:
    name: Allocation check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Install postgreSQL (Linux)
        run: |
          sudo apt-get update
          sudo apt-get install -y libpq-dev postgresql valgrind
          sudo service postgresql start && sleep 3
          sudo -u postgres psql --command "ALTER USER postgres PASSWORD 'root';"

      - name: Adds mimalloc
        run: |
          cargo add mimalloc
          sed -i '3 s/^/#[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;\n/' src/lib.rs
      - name: build
        run: cargo test --no-run --all-features
      - name: valgrind
        run: valgrind --leak-check=full --error-exitcode=1 $(find target/debug/deps -executable -type f -name 'libpq-*')

  arm:
    name: Compilation on ARM
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: arm-unknown-linux-gnueabihf

      - name: install
        run: |
          sudo apt-get update
          sudo apt-get install -y curl git build-essential
          sudo apt-get install -y libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf clang

      - name: build
        run: cargo build --all-features --target arm-unknown-linux-gnueabihf