console-display 0.1.0

A tui library that focuses primarily on providing high resolution display functionality in the console.
Documentation
name: Continuous Integration

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"
  RUSTDOCFLAGS: "-Dwarnings"
  AUTO_FORMAT: ${{ vars.AUTO_FORMAT }}

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4

    - name: Cache cargo registry
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo
          ~/.rustup
          target
        key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-

    - name: Add Rust to PATH
      run: |
        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
        echo "$HOME/.rustup/bin" >> $GITHUB_PATH

    - name: Install Rust nightly
      run: |
        if [ -d "$HOME/.cargo/" ] && [ -d "$HOME/.rustup/" ] && [ -f "$HOME/.cargo/bin/cargo-llvm-cov" ]; then
            echo "Rust is already installed. Skipping installation."
            rustup component add --toolchain nightly-x86_64-unknown-linux-gnu clippy rustfmt llvm-tools-preview
        else
            echo "Rust is not installed. Installing via rustup..."
            curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
            cargo install cargo-llvm-cov
        fi

    - name: Show rust version
      run: rustc --version

    - name: Format code
      if: env.AUTO_FORMAT == 'true'
      run: cargo +nightly fmt --all

    - name: Check formatting
      if: env.AUTO_FORMAT != 'true'
      run: |
        cargo +nightly fmt --all --check || {
          echo "Formatting failed — please run 'cargo +nightly fmt --all' locally before pushing.";
          exit 1;
        }
    
    # Allow dirty flag added for convinience. Be careful when auto-formatting is enabled.
    - name: Clippy apply suggestions
      if: env.AUTO_FORMAT == 'true'
      run: RUSTFLAGS="-Dclippy::all" cargo +nightly clippy --all-targets --all-features --fix --allow-dirty -- -W clippy::pedantic -W clippy::nursery -W clippy::cargo -A clippy::cast-precision-loss

    # Still need to run clippy as well, because cargo clippy fix makes errors into warnings. See: https://github.com/rust-lang/rust-clippy/discussions/9979
    - name: Clippy
      run: RUSTFLAGS="-Dclippy::all" cargo +nightly clippy --all-targets --all-features -- -W clippy::pedantic -W clippy::nursery -W clippy::cargo -A clippy::cast-precision-loss

    # Replaces cargo test and checks test coverage.
    - name: Test coverage
      run: |
        cargo +nightly llvm-cov clean --workspace;
        cargo +nightly llvm-cov --no-report --workspace --all-features --all-targets;
        cargo +nightly llvm-cov --no-report --workspace --all-features --doctests;
        cargo +nightly llvm-cov report --fail-under-regions 40;
        
    # Needed to catch dangling references in documentation.
    - name: Build documentation
      run: cargo +nightly doc --no-deps;