tgt 1.0.0

A simple TUI for Telegram
name: CI macOS

on:
  push:
    branches: [ main ]
    paths:
      - 'src/**'
      - 'Cargo.lock'
      - 'Cargo.toml'
      - 'rustfmt.toml'
      - 'config/**'
      - '.github/workflows/**'
  pull_request:
    branches: [ main ]
    paths:
      - 'src/**'
      - 'Cargo.lock'
      - 'Cargo.toml'
      - 'rustfmt.toml'
      - 'config/**'
      - '.github/workflows/**'

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  TDLIB_VERSION: af69dd4397b6dc1bf23ba0fd0bf429fcba6454f6
  API_HASH: a3406de8d171bb422bb6ddf3bbd800e2
  API_ID: 94575

jobs:
  ci:
    strategy:
      fail-fast: false
      matrix:
        os: [macos-13, macos-14]
        feature: [local-tdlib, download-tdlib, pkg-config]

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

    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Restore cache TDLib
        if: matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config'
        id: cache-tdlib-restore
        uses: actions/cache/restore@v4
        with:
          path: td/
          key: ${{ runner.os }}-${{ runner.arch }}-TDLib-${{ env.TDLIB_VERSION }}
      - name: Build TDLib
        if: steps.cache-tdlib-restore.outputs.cache-hit != 'true' && (matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config')
        run: |
          /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
          brew install gperf cmake openssl
          git clone https://github.com/tdlib/td.git
          cd td
          git checkout $TDLIB_VERSION
          rm -rf build
          mkdir build
          cd build
          cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=${{ runner.arch == 'ARM64' && '/opt/homebrew/opt/openssl/' || '/usr/local/opt/openssl/' }} -DCMAKE_INSTALL_PREFIX:PATH=../tdlib ..
          cmake --build . --target install
      - name: Save cache TDLib
        if: steps.cache-tdlib-restore.outputs.cache-hit != 'true' && (matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config')
        uses: actions/cache/save@v4
        with:
          path: td/
          key: ${{ steps.cache-tdlib-restore.outputs.cache-primary-key }}
      - name: Extract TDLib x86_64
        if: runner.arch == 'x64' && (matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config')
        run: |
          cp -r ./td/tdlib ./
          # cp ./tdlib/lib/libtdjson.*.dylib /usr/local/lib/
      - name: Extract TDLib ARM64
        if: runner.arch == 'ARM64' && (matrix.feature == 'local-tdlib' || matrix.feature == 'pkg-config')
        run: |
          sudo mkdir -p /usr/local/lib
          sudo cp -r ./td/tdlib ./
          # sudo cp ./tdlib/lib/libtdjson.*.dylib /usr/local/lib/
      - name: Set PKG_CONFIG_PATH and DYLD_LIBRARY_PATH
        if: matrix.feature == 'pkg-config'
        run: |
          echo "PKG_CONFIG_PATH=$(pwd)/tdlib/lib/pkgconfig" >> $GITHUB_ENV
          echo "DYLD_LIBRARY_PATH=$(pwd)/tdlib/lib" >> $GITHUB_ENV
      - name: Set LOCAL_TDLIB_PATH
        if: matrix.feature == 'local-tdlib'
        run: |
          echo "LOCAL_TDLIB_PATH=$(pwd)/tdlib" >> $GITHUB_ENV
      # - name: Cache cargo
      #   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') }}
      #     restore-keys: ${{ runner.os }}-cargo-
      - name: Run cargo build
        run: cargo build --no-default-features --verbose --features ${{ matrix.feature }}
      - name: Run cargo test
        run: cargo test --no-default-features --verbose --features ${{ matrix.feature }} -- --nocapture --test-threads=1
      - name: Run cargo clippy
        run: cargo clippy --no-default-features --all-targets --features ${{ matrix.feature }} -- -D warnings
      - name: Run cargo fmt
        run: cargo fmt --all -- --check
      # - name: Upload artifact
      #   uses: actions/upload-artifact@v4
      #   with:
      #     name: ${{ runner.os }}-artifact
      #     path: ./
      #     overwrite: true