# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial

# This workflow checks out and build a bunch of crates that uses Slint,
# with the current branch

name: Crater

on:
  workflow_dispatch:

jobs:
  crater:
    env:
      SLINT_NO_QT: 1
      CARGO_INCREMENTAL: false
      RUST_BACKTRACE: 1
    strategy:
      fail-fast: false
      matrix:
        git_url:
          # from madewithslint
          - "https://github.com/slint-ui/cargo-ui"
          - "https://github.com/jturcotte/chiptrack"
          - "https://github.com/GaspardCulis/slint-tetris"
          - "https://github.com/Futsch1/image-sieve"
          #- "https://github.com/dngulin/gpcl" # depends on the winit backend
          - "https://codeberg.org/flovansl/co_sl"
          #- "https://github.com/ElevenJune/mastermind_Rust" # Not upgraded to Slint 1.0
          #- "https://github.com/Project-Trains/launcher" # Not upgraded to Slint 1.0
          - "https://github.com/Vinegret43/dispute"
          - "https://github.com/bjorn/raccoin"

          - "https://github.com/Decodetalkers/launchre"
          - "https://github.com/Decodetalkers/haruhishot"
          - "https://github.com/smalltext/trace-slint/"
          - "https://github.com/danrauch/thermocam"
          - "https://github.com/saturn77/magnet"
          - "https://github.com/Heng30/chatbox"

          - "https://github.com/zzq0097/mmm_rs"
          - "https://github.com/rurishigeo/Probe-Downloader"
          - "https://github.com/aka-deVOID/blog"
          - "https://github.com/CMahaff/lasim" # many stars
          - "https://github.com/spades9/image-tools"
          - "https://github.com/studylessshape/calculator-by-rs"
          - "https://github.com/gleb-skobinsky/system-metrics"
          - "https://github.com/AccAutomaton/ECJTU-CAN-Helper"
          - "https://github.com/Vadoola/pv-unlocker"
          - "https://github.com/Tricked-dev/stardew-mod-manager"
          - "https://github.com/zzoe/liando"
          - "https://github.com/Knowit-Objectnet/infoskjerm-trondheim"
          - "https://github.com/CaleGlisson/Zelda_pattern_rust"
          - "https://github.com/dweiss96/rf2_league_mod_tool"
          - "https://github.com/Badless/slint-editor"
          - "https://github.com/IvanB101/hamming-huffman"
          - "https://github.com/colelawrence/here-now"
          - "https://github.com/izuku0550/Custom-Note-Builder"
          - "https://github.com/mrquantumoff/quadrant_lite"

          - "https://github.com/lechos22/p2ptun"
          - "https://github.com/ChronosWS/asma"
          - "https://github.com/LeeeSe/MessAuto"
          - "https://github.com/jpnurmi/jpos-weather"
          - "https://github.com/zebra-sh/zebra-pass"
          - "https://github.com/planet0104/satellite_wallpaper"
          - "https://github.com/osp-project/RizPackageTools"
          - "https://github.com/Heng30/rssbox"
          - "https://github.com/xenein/CountMeDown-rs"
          - "https://github.com/vicanso/image-converter"
          - "https://github.com/JeremiasMeister/rust-heightmap-generator"
          - "https://github.com/leonardosalsi/rustop"
          - "https://github.com/joaofl/any-serve"
          - "https://github.com/Heng30/uibox"
          - "https://github.com/ilmai/plugin-things"

          # Use our private API (eg: backend winit)
          # - "https://github.com/Davide255/LVIE"
          # - "https://github.com/Vadoola/Tomotroid"
          # - "https://github.com/Horbin-Magician/rotor-rs"

          # - "https://codeberg.org/moire/moire"  # Broken because of other dependencies.

          # Needs extra dependencies
          # - "https://github.com/nununoisy/gb-presenter-rs"
          # - "https://github.com/nununoisy/nsf-presenter-rs"
          # - "https://github.com/bombless/slint-tree"


          #- "https://github.com/link9c/media_backup"  #(windows only (failed to resolve: use of undeclared crate or module `winres`))
          #- "https://github.com/Vadoola/ignition_npp_tools" #windows only

          # Not updated to Slint 1.0
          #- "https://github.com/jannes/han-cihui"
          #- "https://github.com/leofidus/ntfs-explorer"
          #- "https://github.com/gsuyemoto/rust-bombfield"
          #- "https://github.com/kizeevov/l5"
          #- "https://github.com/SergioGasquez/espup-slint"

        sub_path: ["."]

        include:
          - git_url: "https://github.com/griccardos/rusl"
            sub_path: "slint"
          - git_url: "https://github.com/Berrysoft/tunet-rust"
            sub_path: "tunet-gui"
          #- git_url: "https://github.com/DanielMadmon/tasker"  # needs "themis dep"
          #  sub_path: "bin/tasker_gui"
          - git_url: "https://github.com/matthiasbeyer/distrox"
            sub_path: "distrox-gui"
          - git_url: "https://github.com/Kllngii/Wetterstation"
            sub_path: "wetterstation-ui"
          - git_url: "https://github.com/plule/theremotion"
            sub_path: "theremotion-ui"
          - git_url: "https://github.com/matthiasbeyer/deskodon"
            sub_path: "frontend"
          - git_url: "https://github.com/malwaredb/malwaredb-rs"
            extra_args: "--features=admin-gui"
            sub_path: "."
          - git_url: "https://github.com/Martoni/QRNote"
            sub_path: "qr-note"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/install-linux-dependencies
        with:
          extra-packages: libpango1.0-dev libatk1.0-dev libgtk-3-dev alsa-utils libasound2-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libjack-jackd2-dev autoconf libxcb-xrm0 libxcb-xrm-dev automake  libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-cursor-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev libudev-dev clang libavcodec-dev libavformat-dev libavutil-dev libavfilter-dev libavdevice-dev libasound2-dev pkg-config
      # Don't use the cache because we don't run this job often, and it would cache the .cargo/config with extra keys
      - uses: dtolnay/rust-toolchain@stable
      - name: setup patch
        run: |
          echo "" >> ~/.cargo/config
          echo [patch.crates-io] >> ~/.cargo/config
          echo slint = { path = \"$GITHUB_WORKSPACE/api/rs/slint\" } >> ~/.cargo/config
          echo slint-build = { path = \"$GITHUB_WORKSPACE/api/rs/build\" }  >> ~/.cargo/config
          echo slint-interpreter = { path = \"$GITHUB_WORKSPACE/internal/interpreter\" }  >> ~/.cargo/config
          echo i-slint-backend-winit = { path = \"$GITHUB_WORKSPACE/internal/backends/winit\" }  >> ~/.cargo/config
      - name: Checkout the repo
        run: |
          cd $HOME
          git clone ${{ matrix.git_url }}  the_repo --depth 1
          cd the_repo
          git submodule update --init
      - name: build
        run: |
          cd $HOME/the_repo
          cd ${{ matrix.sub_path }}
          cargo update
          cargo check ${{ matrix.extra_args }}
