shvproto 6.1.6

Rust implementation of the SHV protocol
Documentation
name: Rust Build and Artifact Creation

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

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

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
          - os: windows-latest
            target: x86_64-pc-windows-msvc
    runs-on: ${{ matrix.os }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v6

    - name: Set up Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        target: ${{ matrix.target }}
        toolchain: ${{ matrix.toolchain }}
        override: true
        components: clippy

    - name: Build and Install Binary
      run: |
        mkdir -p ${{github.workspace}}/install
        export RUSTFLAGS="-A mismatched_lifetime_syntaxes"
        FEATURES="cq,cp2cp,serde"
        if rustup default | grep nightly; then
          FEATURES+=",specialization"
        fi
        cargo clippy --all-targets --features "${FEATURES}"
        cargo install --path '${{github.workspace}}' --root '${{github.workspace}}/install' --target ${{ matrix.target }} --features "${FEATURES}" --locked
      shell: bash

    - name: Upload Artifact
      uses: actions/upload-artifact@v7
      with:
        name: ${{ matrix.os }}-${{ matrix.toolchain }}-binary
        path: ${{github.workspace}}/install/bin

  create-nightly-release:
    name: Create nightly
    if: github.ref == 'refs/heads/master'
    needs: [build]
    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: Consolidate artifacts
        uses: actions/download-artifact@v8
        with:
          pattern: '*-latest-nightly-binary'
          merge-multiple: true

      - name: Rename artifacts
        run: |
          CP2CP_FILE_NAME="$(printf "cp2cp-nightly-g%s" "$(head -c 7 <<< '${{env.HASH_FOR_FILENAMES}}')")"
          mv cp2cp "${CP2CP_FILE_NAME}"
          mv cp2cp.exe "${CP2CP_FILE_NAME}.exe"

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

  coverage:
    name: Code coverage
    runs-on: ubuntu-latest
    steps:
      - name: Generate coverage
        uses: silicon-heaven/rust-pycobertura-action@v4.1.0
        with:
          project_name: libshvproto
          cargo_test_arguments: --features cq,cp2cp,serde

  check-version-bump:
    name: Check version bump
    runs-on: ubuntu-latest
    steps:
      - name: Check version bump
        id: version-check
        continue-on-error: ${{startsWith(github.head_ref, 'dependabot/')}}
        uses: silicon-heaven/rust-check-version-bump@v1.0.1

      - name: Checkout code
        if: steps.version-check.outcome == 'failure'
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
          ref: ${{github.head_ref}}

      - name: Bump version
        if: steps.version-check.outcome == 'failure'
        run: |
          [[ "$(grep '^version' Cargo.toml | head -n1)" =~ ([0-9]+\.[0-9]+\.)([0-9]+) ]]
          NEW_VERSION="${BASH_REMATCH[1]}$((BASH_REMATCH[2] + 1))"
          cargo install cargo-release
          echo Bumping "${BASH_REMATCH[0]} -> $NEW_VERSION"
          BUMP_TYPE='patch'
          yes | cargo release version "$BUMP_TYPE" --execute
          if [[ -f Cargo.lock ]]; then
              cargo update
          fi
          git diff
          git config --global user.name "Login will be determined by the Github API based on the creator of the token"
          git config --global user.email ""
          git commit -am '[dependabot-skip] Bump version'

      - name: Push changes
        if: steps.version-check.outcome == 'failure'
        uses: Asana/push-signed-commits@v1
        with:
          github-token: ${{ secrets.DEPENDABOT_GITHUB_TOKEN }}
          local_branch_name: ${{github.head_ref}}
          remote_branch_name: ${{github.head_ref}}

  tag-release:
    name: Tag Release
    if: github.ref == 'refs/heads/master'
    needs: [build, check-version-bump]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Get version from Cargo.toml
        id: get-version
        run: |
          version="$(grep '^version' Cargo.toml | head -n1 | sed 's/version\s*=\s*"\(.*\)"/\1/')"
          echo "version=$version" >> "$GITHUB_OUTPUT"

      - name: Create and push tag
        uses: rickstaa/action-create-tag@v1
        with:
          tag: ${{ steps.get-version.outputs.version }}