name: Rust-lint

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
  merge_group:

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  lint-linux:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          submodules: recursive
          fetch-depth: 0
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          rustflags: ""
          components: clippy, rustfmt
      - name: Set LLVM_VERSION
        run:
          echo "LLVM_VERSION=$(rustc --version --verbose | grep "LLVM version" | cut
          -d':' -f2 | xargs)" >> $GITHUB_ENV
      - name: Install SDL Dependencies
        # https://wiki.libsdl.org/SDL3/README-linux#build-dependencies
        uses: awalsh128/cache-apt-pkgs-action@v1
        with:
          packages: build-essential git make pkg-config cmake ninja-build
            gnome-desktop-testing libasound2-dev libpulse-dev libaudio-dev
            libfribidi-dev libjack-dev libsndio-dev libx11-dev libxext-dev
            libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev
            libxtst-dev libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev
            libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev
            libudev-dev libthai-dev libpipewire-0.3-dev libwayland-dev
            libdecor-0-dev liburing-dev libfontconfig-dev gettext
          version: lint-1.0
      - name: Install LLVM and Clang
        uses: KyleMayes/install-llvm-action@v2
        with:
          version: ${{ env.LLVM_VERSION }}
          force-url:
            https://github.com/llvm/llvm-project/releases/download/llvmorg-${{
            env.LLVM_VERSION }}/LLVM-${{ env.LLVM_VERSION }}-Linux-X64.tar.xz
      - name: Rustfmt Check
        uses: actions-rust-lang/rustfmt@v1
      - name: Lint
        run: |
          cargo install slint-tr-extractor
          cargo clippy -- -Dwarnings
          cargo clippy --no-default-features -- -Dwarnings
          find -name \*.slint | sort | xargs slint-tr-extractor -o /tmp/translations.pot
          msgcmp --use-untranslated /tmp/translations.pot data/translations/gopher64.pot
          msgcmp --use-untranslated data/translations/gopher64.pot /tmp/translations.pot
          find data/translations -name "*.po" | xargs -I {} msgcmp {} data/translations/gopher64.pot
