name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  release:
    name: Release for ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            artifact_name: cosense
            asset_name: cosense-linux-amd64
          - os: windows-latest
            artifact_name: cosense.exe
            asset_name: cosense-windows-amd64.exe
          - os: macos-latest
            artifact_name: cosense
            asset_name: cosense-macos-amd64

    steps:
    - uses: actions/checkout@v2


    - name: Install dependencies on Ubuntu
      if: matrix.os == 'ubuntu-latest'
      run: |
        sudo apt-get update
        sudo apt-get install -y libdbus-1-dev

    - uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable

    - name: Build
      run: cargo build --release

    - name: Upload binaries to release
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: target/release/${{ matrix.artifact_name }}
        asset_name: ${{ matrix.asset_name }}
        tag: ${{ github.ref }}
