coap-client 0.3.1

A CoAP client
Documentation
name: Rust

on:
  push:
    branches: [ main ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ main ]

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    continue-on-error: true
    
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          override: true
          components: rustfmt, clippy

      - name: Configure caching
        uses: actions/cache@v2
        if: ${{ matrix.os != 'macos-latest' }}
        with:
          key: check
          path: |
            ${{ env.HOME }}/.cargo
            ./target

      - name: Run cargo fmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: -- --check

  build:
    name: Build
    runs-on: ${{ matrix.os }}
    env:
      VCPKG_BINARY_SOURCES: 'clear;files,C:\vcpkg\archives,readwrite'

    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            output: coap-client
          - target: x86_64-apple-darwin
            os: macos-latest
            output: coap-client
          - target: armv7-unknown-linux-gnueabihf 
            os: ubuntu-latest
            output: coap-client
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            output: coap-client.exe

    steps:
    - uses: actions/checkout@v2
    - uses: FranzDiebold/github-env-vars-action@v1.2.1
      
    - name: Configure toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        target:  ${{ matrix.target }}
        override: true
    
    - name: Configure linux caching
      if: ${{ matrix.os != 'windows-latest' }}
      uses: actions/cache@v2
      with:
        key: ${{ matrix.os }}-${{ matrix.target }}
        path: |
          ./target
          /usr/share/rust/.cargo/.cargo/bin
          /usr/share/rust/.cargo/.cargo/registry/index
          /usr/share/rust/.cargo/.cargo/registry/cache
          /usr/share/rust/.cargo/.cargo/git/db
    
    - name: Configure windows caching
      if: ${{ matrix.os == 'windows-latest' }}
      uses: actions/cache@v2
      with:
        key: ${{ matrix.os }}-${{ matrix.target }}
        path: |
          C:\vcpkg\archives
          C:\Rust\.cargo\bin
          C:\Rust\.cargo\registry\index
          C:\Rust\.cargo\registry\cache
          C:\Rust\.cargo\git\db

    - name: Install openssl (apt armv7)
      if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
      uses: ryankurte/action-apt@v0.3.0
      with:
        arch: armhf
        packages: libssl-dev:armhf libssl1.1:armhf zlib1g-dev:armhf zlib1g:armhf libc-dev:armhf

    - name: Install cross toolchain (armv7)
      if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
      run: sudo apt install gcc-arm-linux-gnueabihf

    - name: Enable cross compilation (armv7)
      if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
      run: |
        echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV

    - name: Install openssl (vcpkg)
      if: ${{ matrix.os == 'windows-latest' }}
      timeout-minutes: 30
      run: |
        vcpkg integrate install
        vcpkg install openssl:x64-windows-static
        echo "OPENSSL_DIR=C:/vcpkg/installed/x64-windows-static/" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
        echo "OPENSSL_ROOT_DIR=C:/vcpkg/installed/x64-windows-static/" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
        echo "OPENSSL_STATIC=1" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append

    - name: Build release
      uses: actions-rs/cargo@v1
      with:
        command: build
        args: --target ${{ matrix.target }} --release

    - name: Copy / Rename utility
      run: |
        cp target/${{ matrix.target }}/release/${{ matrix.output }} ${{ matrix.output }}
        tar -czvf coap-client-${{ matrix.target }}.tgz ${{ matrix.output }}

    - name: Upload artifacts
      uses: actions/upload-artifact@v1
      with:
        name: coap-client-${{ matrix.target }}.tgz
        path: coap-client-${{ matrix.target }}.tgz

    - name: Upload binary to release
      if: ${{ startsWith(github.ref, 'refs/tags/v') }}
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: coap-client-${{ matrix.target }}.tgz
        asset_name: coap-client-${{ matrix.target }}.tgz
        tag: ${{ github.ref }}
        overwrite: true


  test:
    name: Test
    runs-on: ${{ matrix.os }}
    needs: build
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            output: coap-client
          - target: x86_64-apple-darwin
            os: macos-latest
            output: coap-client
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            output: coap-client.exe

    steps:
    - uses: actions/checkout@v2
    - uses: FranzDiebold/github-env-vars-action@v1.2.1
    
    - uses: actions/download-artifact@v2
      with:
        name: coap-client-${{ matrix.target }}.tgz
    
    - name: "Extract build artifact"
      run: tar -xvf coap-client-${{ matrix.target }}.tgz
    
    - name: "Run utility"
      run: ./${{ matrix.output }} --log-level debug coap://coap.me/hello get