rsmgclient 3.0.0

Memgraph database adapter for Rust programming language.
Documentation
name: CI

on:
  push:
  pull_request:
  workflow_dispatch:
    inputs:
      apple:
        type: boolean
        default: false
        description: "Build and test on Mac OS"
      windows:
        type: boolean
        default: false
        description: "Build and test on Windows (VCPKG)"
      windows_mingw:
        type: boolean
        default: false
        description: "Build and test on Windows (MinGW)"
      linux:
        type: boolean
        default: false
        description: "Build and test on Linux"
      linux_wasm:
        type: boolean
        default: false
        description: "Build and test on Linux (Wasm)"

jobs:
  clang_check:
    if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
    runs-on: ubuntu-latest
    steps:
    - name: Set-up repository
      uses: actions/checkout@v4
    - name: Install environment
      run: |
        sudo apt install -y clang-format
    - name: Run clang formatter
      run: |
        ./tool/format.sh

  build_and_test_apple:
    if: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.apple) }}
    strategy:
      matrix:
        platform: [macos-14, macos-15]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Set-up repository
        uses: actions/checkout@v4
      # NOTE: CI can't execute end2end tests because there is no way to run
      #       Memgraph on CI MacOS machines.
      - name: Build and test mgclient
        run: |
          mkdir build
          cd build
          cmake -DOPENSSL_ROOT_DIR="$(ls -rd -- /usr/local/Cellar/openssl@1.1/* | head -n 1)" -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON ..
          cmake --build . --parallel
          ctest -E "example|integration"
          sudo make install

  build_windows_compiler:
    if: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.windows) }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-2022
          - os: windows-2025
    runs-on: ${{ matrix.os }}
    env:
      VCPKG_ROOT: "${{ github.workspace }}\\vcpkg"
      deps: "openssl:x64-windows"
    steps:
      - name: Set-up repository
        uses: actions/checkout@v4
      - name: Restore vcpkg and its artifacts
        uses: actions/cache@v4
        id: vcpkg-cache
        with:
          path: ${{ env.VCPKG_ROOT }}
          key: ${{ matrix.os }}-${{ env.deps }}
      - name: Get vcpkg
        if: ${{ steps.vcpkg-cache.outputs.cache-hit != 'true' }}
        run: |
          cd ${{ github.workspace }}
          git clone https://github.com/Microsoft/vcpkg.git
          cd vcpkg
          .\bootstrap-vcpkg.bat
      - name: Remove system vcpkg
        run: rm -rf "$VCPKG_INSTALLATION_ROOT"
        shell: bash
      - name: Install vcpkg packages
        run: |
          ${{ env.VCPKG_ROOT }}\vcpkg.exe install ${{ env.deps }}
      - name: Build and test mgclient
        run: |
          mkdir build
          cd build
          cmake -DOPENSSL_ROOT_DIR="${{ env.VCPKG_ROOT }}\installed\x64-windows" ..
          cmake --build .

  build_and_test_linux:
    if: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.linux) }}
    strategy:
     matrix:
        platform: [ubuntu-24.04, fedora-41]
        mgversion: ["latest"]
        packages: ["gcc g++ clang cmake git"]
        gcc-postfix: [""]
        clang-postfix: [""]
    runs-on: ["self-hosted", "X64"]
    env:
      MEMGRAPH_NETWORK: "host"
    steps:
      - name: Set-up repository
        uses: actions/checkout@v4

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Launch Docker Container
        run: |
          docker network create ${{ env.MEMGRAPH_NETWORK }} || true
          platform="${{ matrix.platform }}"
          tag=${platform//-/:}
          docker run -d --rm --name testcontainer --network ${{ env.MEMGRAPH_NETWORK }} "$tag" sleep infinity      

      - name: Install environment
        run: |
          if [[ "${{ matrix.platform }}" == ubuntu* ]]; then
            docker exec -i testcontainer bash -c "apt update && apt install -y ${{ matrix.packages }} libssl-dev"
          else
            docker exec -i testcontainer bash -c "dnf install -y ${{ matrix.packages }} openssl-devel"
          fi

      - name: Copy Repo Into Container
        run: |
          docker cp . testcontainer:/mgclient

      - name: Set Memgraph Version
        run: |
          if [[ "${{ matrix.mgversion }}" == "latest" ]]; then
            mgversion=$(curl -s https://api.github.com/repos/memgraph/memgraph/releases/latest | jq -r .tag_name)
            mgversion=${mgversion#v}
          else
            mgversion="${{ matrix.mgversion }}"
          fi
          echo "MGVERSION=$mgversion" >> $GITHUB_ENV

      - name: Download Memgraph Docker image
        run: |
          curl -L https://download.memgraph.com/memgraph/v${{ env.MGVERSION }}/docker/memgraph-${{ env.MGVERSION }}-docker.tar.gz > memgraph-docker.tar.gz

      - name: Load and run Memgraph Docker image
        run: |
          docker load -i memgraph-docker.tar.gz
          docker run -d --rm --name memgraphcontainer --network ${{ env.MEMGRAPH_NETWORK }} -p 7687:7687 memgraph/memgraph --telemetry-enabled=false 
          rm memgraph-docker.tar.gz
          sleep 5
          docker logs memgraphcontainer

      - name: Build with gcc, test and install mgclient
        run: |
          cmake_configure="cmake \
            -DCMAKE_C_COMPILER=gcc${{ matrix.gcc-postfix }} \
            -DCMAKE_CXX_COMPILER=g++${{ matrix.gcc-postfix }} \
            -DCMAKE_BUILD_TYPE=Release \
            -DBUILD_TESTING=ON \
            -DBUILD_TESTING_INTEGRATION=ON \
            -DC_WARNINGS_AS_ERRORS=ON \
            -DCPP_WARNINGS_AS_ERRORS=ON \
            .."

          docker exec -i testcontainer bash -c "
            mkdir /mgclient/build-gcc && 
            cd /mgclient/build-gcc && 
            $cmake_configure && 
            cmake --build . --parallel && 
            ctest --output-on-failure && 
            make install"
          
      - name: Build with clang, test and install mgclient
        run: |
          cmake_configure="cmake \
            -DCMAKE_C_COMPILER=clang${{ matrix.clang-postfix }} \
            -DCMAKE_CXX_COMPILER=clang++${{ matrix.clang-postfix }} \
            -DCMAKE_BUILD_TYPE=Release \
            -DBUILD_TESTING=ON \
            -DBUILD_TESTING_INTEGRATION=ON \
            -DC_WARNINGS_AS_ERRORS=ON \
            -DCPP_WARNINGS_AS_ERRORS=ON \
          .."

          docker exec -i testcontainer bash -c "
            mkdir /mgclient/build-clang && 
            cd /mgclient/build-clang && 
            $cmake_configure && 
            cmake --build . --parallel && 
            ctest --output-on-failure && 
            make install"

      - name: Cleanup
        if: always()
        run: |
          docker stop testcontainer || echo "testcontainer already stopped"
          docker stop memgraphcontainer || echo "memgraphcontainer already stopped"
          docker wait testcontainer || true
          docker wait memgraphcontainer || true
          docker rm "${{ env.MEMGRAPH_NETWORK }}" || echo "network already removed"
          docker rmi "${{ matrix.platform }}" || echo "${{ matrix.platform }} image not found"
          docker rmi memgraph/memgraph || echo "memgraph/memgraph image not found"



  # GitHub actions can't run Linux Docker container on Windows machine
  # https://github.com/actions/virtual-environments/issues/1143.
  #
  # The only option to test this project on GitHub Actions under Windows is to
  # run Memgraph under [WSL](https://docs.microsoft.com/en-us/windows/wsl/).
  # Memgraph has to be started manually because systemd is not available on
  # WSL (init process does not exist).
  # This particular test might be flaky (hence the additional memgraph process check)
  build_and_test_windows_mingw:
    if: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.windows_mingw) }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-2022, windows-2025]
        msystem: [MINGW64]
        arch: [x86_64]
        mgversion: ["latest"]
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - name: Set-up repository
        uses: actions/checkout@v4
      - uses: msys2/setup-msys2@v2
        with:
          msystem: ${{ matrix.msystem }}
          update: true
          install: git base-devel mingw-w64-${{ matrix.arch }}-toolchain mingw-w64-${{ matrix.arch }}-cmake mingw-w64-${{ matrix.arch }}-openssl
      - uses: Vampire/setup-wsl@v5
        with:
            distribution: Ubuntu-24.04
      - name: Set Memgraph Version
        run: |
          if [[ "${{ matrix.mgversion }}" == "latest" ]]; then
            mgversion=$(
              curl -s https://api.github.com/repos/memgraph/memgraph/releases/latest \
              | grep -m1 '"tag_name":' \
              | sed -E 's/.*"([^"]+)".*/\1/' \
              | sed 's/^v//'
            )
          else
            mgversion="${{ matrix.mgversion }}"
          fi
          echo "MGVERSION=$mgversion" >> $GITHUB_ENV
      - name: Download, install and run Memgraph under WSL
        shell: wsl-bash {0} # root shell
        run: |
          mkdir ~/memgraph
          curl -L https://download.memgraph.com/memgraph/v${{ env.MGVERSION }}/ubuntu-24.04/memgraph_${{ env.MGVERSION }}-1_amd64.deb --output ~/memgraph/memgraph.deb
          dpkg -i ~/memgraph/memgraph.deb
          nohup /usr/lib/memgraph/memgraph --bolt-port 7687 --bolt-cert-file="" --bolt-key-file="" --data-directory="~/memgraph/data" --storage-properties-on-edges=true --storage-snapshot-interval-sec=0 --storage-wal-enabled=false --data-recovery-on-startup=false --storage-snapshot-on-exit=false --telemetry-enabled=false --log-file='' &
          sleep 1 # Wait for Memgraph a bit.
      - name: Build and test mgclient
        run: |
          mkdir build
          cd build
          cmake .. -G "MinGW Makefiles" -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5
          cmake --build . --parallel

      - name: Verify Memgraph is running under WSL
        shell: wsl-bash {0}
        run: |
          # process
          if ! pgrep -x memgraph; then
            echo "❌ Memgraph not running" >&2
            exit 1
          fi
          echo "✅ Memgraph check passed"

      - name: Run Tests
        run: |
          ctest --verbose -R "allocator|value|example_basic|integration_basic"

  build_and_test_linux_wasm:
    if: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.linux_wasm) }}
    strategy:
     matrix:
        platform: [ubuntu-24.04]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Set-up repository
        uses: actions/checkout@v4

      - name: Build with clang
        run: |
          mkdir build
          cd build
          cmake .. -DCMAKE_BUILD_TYPE=Release -DC_WARNINGS_AS_ERRORS=ON -DWASM=ON
          make