on: [pull_request]

name: Continuous integration

jobs:

  fmt:
     name: Rustfmt
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
       - uses: actions-rs/toolchain@v1
         with:
           profile: minimal
           toolchain: stable
           override: true
           components: rustfmt
       - uses: actions-rs/cargo@v1
         with:
           command: fmt
           args: --all -- --check

  build_windows:
      name: etradeTaxReturnHelper windows artifacts publish
      runs-on: windows-latest
      strategy:
        matrix:
          toolchain:
            - stable
      steps:
        - uses: actions/checkout@v3
        - run:  rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
        - name: Build
          run:  mkdir etradeTaxReturnHelper && cargo build --release && dir && dir target\release && xcopy target\release\etradeTaxReturnHelper.exe etradeTaxReturnHelper /R /K /O /Y
        - name: Archiving
          uses: actions/upload-artifact@v2
          with: 
            name: assets-for-download
            path: etradeTaxReturnHelper

  build_and_test:
      name: etradeTaxReturnHelper GUI building
      runs-on: ubuntu-latest
      steps:
        - name: Install system dependencies
          run: |
            sudo apt-get update
            sudo apt-get install -y libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev
        - uses: actions/checkout@v2
        - uses: actions-rs/toolchain@v1
          with:
            toolchain: stable
        - name: Cargo build
          env:
            LIBRARY_PATH: ./
          run: |
            cargo build --release
        - name: Cargo test
          env:
            LIBRARY_PATH: ./
          run: |
            cargo test

  build_and_test_no_gui:
      name: etradeTaxReturnHelper building
      runs-on: ubuntu-latest
      steps:
        - name: Install system dependencies
          run: |
            sudo apt-get update
        - uses: actions/checkout@v2
        - uses: actions-rs/toolchain@v1
          with:
            toolchain: stable
        - name: Cargo build
          env:
            LIBRARY_PATH: ./
          run: |
            cargo build --release --no-default-features
        - name: Cargo test
          env:
            LIBRARY_PATH: ./
          run: |
            cargo test --no-default-features
