name: Build

on:
  push:
    paths:
      - '.github/workflows/build.yml'
      - 'src-tauri/**/*'
      - 'src/**/*'
  pull_request:
    paths:
      - '.github/workflows/build.yml'
      - 'src-tauri/**/*'
      - 'src/**/*'

concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

jobs:
  build-win:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v1
        with:
          node-version: 16

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Install deps and build
        run: yarn && yarn build --debug

      - name: Compress build
        uses: vimtor/action-zip@v1
        with:
          files: src-tauri/target/debug/lang/ src-tauri/target/debug/keys/ src-tauri/target/debug/patch/ src-tauri/target/debug/Cultivation.exe src-tauri/target/debug/bundle/msi/
          recursive: true
          dest: Cultivation.zip

      - name: Upload build
        uses: actions/upload-artifact@v3
        with:
          name: CultivationWin
          path: Cultivation.zip

  build-ubuntu:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v1
        with:
          node-version: 16

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Install libraries
        run: sudo apt install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev

      - name: Install deps and build
        run: yarn && yarn build --debug

      - name: Compress build
        uses: vimtor/action-zip@v1
        with:
          files: src-tauri/target/debug/lang/ src-tauri/target/debug/keys/ src-tauri/target/debug/patch/ src-tauri/target/debug/cultivation
          recursive: true
          dest: Cultivation.zip

      - name: Upload build
        uses: actions/upload-artifact@v3
        with:
          name: CultivationLinux
          path: Cultivation.zip
