lingua 1.8.0

An accurate natural language detection library, suitable for short text and mixed-language text
Documentation
#
# Copyright © 2020-present Peter M. Stahl pemistahl@gmail.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Rust Build

on:
  push:
    branches:
      - main
    paths:
      - 'Cargo.lock'
      - 'Cargo.toml'
      - 'src/**'
      - 'tests/**'
      - '**.yml'
  pull_request:
    branches:
      - main
    paths:
      - 'Cargo.lock'
      - 'Cargo.toml'
      - 'src/**'
      - 'tests/**'
      - '**.yml'

jobs:
  rust-build:
    name: Rust on ${{ matrix.name }}

    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        include:
          - os: ubuntu-latest
            name: Linux 64-Bit

          - os: macos-latest
            name: MacOS 64-Bit

          - os: windows-latest
            name: Windows 64-Bit

    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Store or retrieve cargo caches
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

      - name: Build library with language subset
        run: cargo build --locked --no-default-features --features german

      - name: Build and test library
        run: cargo test --locked

      - name: Build and test binary
        run: cargo test --locked --bin accuracy_reports --features accuracy-reports

      - name: Check Clippy lints in library
        run: cargo clippy -- -Dwarnings

      - name: Check Clippy lints in binary
        run: cargo clippy --bin accuracy_reports --features accuracy-reports -- -Dwarnings

  wasm-build:
    name: WASM Build
    needs: rust-build

    runs-on: macos-latest

    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

      - name: Install Firefox and Geckodriver # not available anymore in macos-latest
        run: |
          brew install --cask firefox
          brew install geckodriver

      #- name: Enable Safari web driver
      #  run: sudo safaridriver --enable

      - name: Run WASM integration tests on NodeJS
        run: wasm-pack test --node

      - name: Run WASM integration tests in Chrome
        run: wasm-pack test --headless --chrome

      - name: Run WASM integration tests in Firefox
        run: wasm-pack test --headless --firefox

      # Safari WASM tests not working, reason unclear
      # Increasing driver timeout does not seem to work
      # https://github.com/wasm-bindgen/wasm-bindgen/pull/4320

      #- name: Run WASM integration tests in Safari
      #  env:
      #    WASM_BINDGEN_TEST_DRIVER_TIMEOUT: 10
      #  run: wasm-pack test --headless --safari

  coverage-report:
    name: Coverage Report
    needs: rust-build
    if: ${{ github.event_name == 'push' }}

    runs-on: ubuntu-latest

    container:
      image: xd009642/tarpaulin:develop-nightly
      options: --security-opt seccomp=unconfined

    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Generate coverage report
        run: cargo +nightly tarpaulin --lib --ignore-config --ignore-panics --ignore-tests --exclude-files src/python.rs src/script.rs src/wasm.rs src/bin/accuracy_reports.rs --verbose --timeout 120 --out xml

      - name: Workaround for codecov/feedback#263
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

      - name: Upload coverage report
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true