shvbroker 3.20.13

Rust implementation of the SHV broker
Documentation
name: Rust

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

on:
  push:
    branches: [ "master", "dbg-action" ]
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: write
  # For syyyr/rust-pycobertura-action
  pull-requests: write

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        toolchain: [stable, nightly]
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            features: --all-features
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            features: --features entra-id
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v6
    - name: Install system dependencies
      if: matrix.os == 'ubuntu-latest'
      run: |
        sudo apt update
        sudo apt-get install -y libudev-dev pkg-config
    - name: Set up Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        target: ${{ matrix.target }}
        components: clippy
        toolchain: ${{ matrix.toolchain }}
        override: true
    - name: Clippy
      run: cargo clippy --all-targets ${{matrix.features}} -- --deny warnings
    - name: Build
      run: cargo build ${{matrix.features}}
    - name: Run tests
      run: cargo test ${{matrix.features}} -- --test-threads=1

  create-nightly-release:
    name: Create nightly
    if: github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    env:
      HASH_FOR_FILENAMES: ${{github.event.pull_request.head.sha || github.sha}}
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
      - name: Install system dependencies
        run: |
          sudo apt update
          sudo apt-get install -y libudev-dev pkg-config

      - name: Build and Install Binary
        run: |
          mkdir -p ${{github.workspace}}/install
          cargo install --path '${{github.workspace}}' --root '${{github.workspace}}/install' --all-features --locked
        shell: bash

      - name: Rename artifacts
        run: |
          SHVBROKER_FILE_NAME="$(printf "shvbroker-nightly-g%s" "$(head -c 7 <<< '${{env.HASH_FOR_FILENAMES}}')")"
          mv '${{github.workspace}}/install/bin/shvbroker' "${{github.workspace}}/install/bin/${SHVBROKER_FILE_NAME}"

      - name: Create release
        env:
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
        uses: silicon-heaven/rust-nightly-release-action@v1.0.0
        with:
          path_glob: ${{github.workspace}}/install/bin/shvbroker*

  coverage:
    name: Code coverage
    runs-on: ubuntu-latest
    steps:
      - name: Install system dependencies
        run: |
          sudo apt update
          sudo apt-get install -y libudev-dev pkg-config
      - name: Generate coverage
        uses: silicon-heaven/rust-pycobertura-action@v4.0.1
        with:
          project_name: shvbroker

  upload-crates-io:
    name: Publish crates on crates.io
    if: github.ref == 'refs/heads/master'
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Install system dependencies
        run: |
          sudo apt update
          sudo apt-get install -y libudev-dev pkg-config

      - name: Publish to crates.io
        run: |
          cargo login <<< "${{secrets.CRATES_IO_TOKEN}}"
          cargo publish