colink 0.3.10

CoLink Rust SDK
Documentation
on:
  push:
    branches:
      - main
  pull_request:

name: check

jobs:
  check:
    strategy:
      matrix:
        mq: [standalone, rabbitmq, redis]
        ci_image: [ubuntu-latest, macos-latest]
        include:
          - mq: rabbitmq
            docker_image: "rabbitmq:3.8-management"
            mq_uri: "amqp://guest:guest@127.0.0.1"
            mq_api: "http://guest:guest@127.0.0.1:15672/api"
          - mq: redis
            docker_image: "redis"
            mq_uri: "redis://127.0.0.1:16379"
    runs-on: ${{ matrix.ci_image }}
    defaults:
      run:
        shell: bash
    steps:
      - name: Install docker
        if: ${{ startsWith(matrix.ci_image, 'macos') }}
        run: |
          brew install docker
          colima start
      - name: Start container (MySQL)
        run: |
          docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test_db -p 3306:3306 -d mysql:8.0
          MYSQL_HOST="127.0.0.1"
          echo "MYSQL_DATABASE_URL=mysql://root:password@${MYSQL_HOST}:3306/test_db" >> $GITHUB_ENV
      - name: Start container (mq)
        if: ${{ matrix.mq != 'standalone' }}
        run: docker run -d -p 5672:5672 -p 15672:15672 -p 16379:6379 ${{ matrix.docker_image }}
      - name: Start container (redis) # for storage macro
        run: docker run -d -p 6379:6379 redis
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: Install Rust
        run: |
          rustup toolchain install stable --no-self-update --component rustfmt --component clippy
          rustup default stable
      - name: Install protobuf
        if: ${{ startsWith(matrix.ci_image, 'ubuntu') }}
        run: sudo apt update && sudo apt install protobuf-compiler -y
      - name: Install protobuf(macos)
        if: ${{ startsWith(matrix.ci_image, 'macos') }}
        run: brew install protobuf
      - name: Check
        if: ${{ startsWith(matrix.ci_image, 'ubuntu') }}  # skip check in macos because it is slow
        run: cargo check --release
      - name: Build
        run: cargo build --all-targets
      - name: Format check
        if: ${{ startsWith(matrix.ci_image, 'ubuntu') }}
        run: cargo fmt --all -- --check
      - name: Clippy test
        if: ${{ startsWith(matrix.ci_image, 'ubuntu') }}
        run: cargo clippy --profile test -- -D warnings -D clippy::dbg_macro
      - name: Download Server
        run: bash download-server.sh
        working-directory: tests
      - name: Run tests
        if: ${{ matrix.mq != 'standalone' }}
        env:
          COLINK_SERVER_MQ_URI: ${{ matrix.mq_uri }}
          COLINK_SERVER_MQ_API: ${{ matrix.mq_api }}
        run: cargo test --features="storage_macro_dbc"
      - name: Run tests (standalone)
        if: ${{ matrix.mq == 'standalone' }}
        run: cargo test --features="storage_macro_dbc"