env:
  CARGO_INCREMENTAL: '0'
  CARGO_NET_RETRY: '10'
  RUSTUP_MAX_RETRIES: '10'
  RUST_BACKTRACE: short
jobs:
  code-duplication:
    if: github.event_name != 'pull_request'
    name: Code Duplication
    needs: pre_ci
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/checkout@v4
      with:
        path: my_gh_stuff
        repository: valeratrades/v_flakes
        sparse-checkout: github/workflows
        sparse-checkout-cone-mode: false
    - name: Setup nightly Rust
      uses: dtolnay/rust-toolchain@nightly
    - name: Install mold linker
      run: sudo apt-get install -y mold
    - name: Install qlty
      uses: qltysh/qlty-action/install@main
    - name: Initialize qlty
      run: qlty init --no --no-upgrade-check
    - name: Check for code duplication
      run: cargo +nightly -Zscript -q my_gh_stuff/github/workflows/code-duplication.rs
    timeout-minutes: 15
  pre_ci:
    uses: valeratrades/.github/.github/workflows/pre_ci.yml@master
  rust-clippy:
    if: github.event_name != 'pull_request'
    name: Clippy
    needs: pre_ci
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@clippy
    - name: Download modified by pre-ci Cargo.toml files
      uses: actions/download-artifact@v4
      with:
        name: modified-cargo-files
    - run: rm -f .cargo/config.toml .cargo/config
    - run: cargo clippy --tests -- -Dwarnings
    timeout-minutes: 45
  rust-doc:
    env:
      RUSTDOCFLAGS: -Dwarnings
    if: needs.pre_ci.outputs.continue
    name: Documentation
    needs: pre_ci
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@nightly
    - name: Download modified by pre-ci Cargo.toml files
      uses: actions/download-artifact@v4
      with:
        name: modified-cargo-files
    - uses: dtolnay/install@cargo-docs-rs
    - run: cargo docs-rs
    timeout-minutes: 45
  rust-machete:
    name: Unused Dependencies
    runs-on: ubuntu-latest
    steps:
    - name: Installation
      uses: taiki-e/install-action@v2
      with:
        tool: cargo-machete
    - name: Cargo Machete
      run: "\t\t\t\t\t\tcargo machete\n\t\t\t\t\t\texit_code=$?\n\t\t\t\t\t\tif [\
        \ $exit_code = 0 ]; then\n\t\t\t\t\t\t\techo \"Found unused dependencies\"\
        \n\t\t\t\t\t\t\texit $exit_code\n\t\t\t\t\t\tfi\n\t\t\t"
  rust-sorted:
    name: Cargo Sorted
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Installation
      uses: taiki-e/install-action@v2
      with:
        tool: cargo-sort
    - name: Check if Cargo.toml is sorted
      run: "cargo sort --workspace --grouped --check\nexit_code=$?\nif [ $exit_code\
        \ != 0 ]; then\n  echo \"Cargo.toml is not sorted. Run \\`cargo sort -w\\\
        ` to fix it.\"\n  exit $exit_code\nfi\n"
  rust-sorted-derives:
    name: Sorted Derives
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Installation
      uses: taiki-e/install-action@v2
      with:
        tool: cargo-sort-derives
    - name: Assert derives are sorted
      run: "\t\t\t\tcargo sort-derives --check\n\t\t\t\texit_code=$?\n\t\t\t\tif [\
        \ $exit_code != 0 ]; then\n\t\t\t\t\techo \"Derives are not sorted. Run \\\
        `cargo sort-derives\\` to fix it.\"\n\t\t\t\t\texit $exit_code\n\t\t\t\tfi\n\
        \t\t\t"
  tokei:
    name: Reasonable Amount of Comments
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Installation
      uses: taiki-e/install-action@v2
      with:
        tool: tokei
    - name: Generate Tokei output
      run: tokei -o json > tokei_output.json
    - name: Install jq
      run: sudo apt-get install -y jq
    - name: Check Rust comments
      run: "\t\t\t\tcomments=$(jq '.Rust.comments' tokei_output.json)\n\t\t\t\tcode=$(jq\
        \ '.Rust.code' tokei_output.json)\n\n\t\t\t\t# compare: comments > code *\
        \ 0.15\n\t\t\t\tif [ $((comments * 100)) -ge $((code * 15)) ]; then\n\t\t\t\
        \t\t\techo \"Number of comments should be less than 15% of code\"\n\t\t\t\t\
        \t\texit 1\n\t\t\t\telse\n\t\t\t\t\t\techo \"Check passed: Number of comments\
        \ is less than 15% of code\"\n\t\t\t\tfi\n        \t\t\t"
name: Warnings
'on':
  pull_request: {}
  push: {}
  workflow_dispatch: {}
permissions:
  contents: read
