name: Rust

on: [push, pull_request, workflow_dispatch]

env:
  CARGO_TERM_COLOR: always
  DATABASE_URL: "sqlite://./dim_dev.db"

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
        - run: sudo apt-get update
        - run: sudo apt-get install -y libva-dev libva-drm2 libva2 sqlite3
        - uses: actions/checkout@v2

        - name: Download UI artifacts
          uses: dawidd6/action-download-artifact@v2
          with:
            workflow: react.yml
            workflow_conclusion: success
            branch: master
            name: webui
            path: ui/build
            repo: ${{github.repository}}

        - uses: actions-rs/toolchain@v1
          with:
              profile: minimal
              toolchain: nightly-2021-09-07
              override: true
              components: cargo
        - run: sqlite3 ./dim_dev.db -init ./database/migrations/20210619211347_dim.sql
        - name: Build Dim
          uses: actions-rs/cargo@v1
          with:
              command: build
              args: --verbose --release

        - name: Download ffmpeg artifacts
          uses: dawidd6/action-download-artifact@v2
          with:
            workflow: main.yml
            workflow_conclusion: success
            branch: master
            event: push
            name: bins
            path: utils
            repo: Dusk-Labs/ffmpeg-static

        - name: Create release dir
          run: |
            mkdir release
            cp target/release/dim release/dim
            cp -R utils release/utils
            chmod +x release/dim
            chmod +x release/utils/ffmpeg
            chmod +x release/utils/ffprobe

        - name: Compress release dir
          run: tar -zcvf release.tar.gz release

        - name: Save artifacts
          uses: actions/upload-artifact@v2
          with:
            name: release
            path: release.tar.gz

