cf_speedtest 0.6.1

A command-line internet speed test tool
# Main CI workflow to validate PRs and branches are correctly formatted
# and pass tests.
#
# I took some of these workflows/jobs from
# https://github.com/ClementTsang/bottom
# 
# - cargo fmt
# - cargo test (built/test in separate steps)

name: ci

on:
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - master

env:
  RUST_BACKTRACE: 1
  CARGO_INCREMENTAL: 0
  CARGO_PROFILE_DEV_DEBUG: 0
  CROSS_VERSION: v0.2.5

concurrency:
  group: ${{ github.workflow }}-${{ github.event.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' || github.repository != '12932/cf_speedtest' }}

jobs:
  # Check if things should be skipped.
  pre-job:
    runs-on: ubuntu-latest
    outputs:
      should_skip: ${{ steps.skip_check.outputs.should_skip }}
    steps:
      - name: Check if this action should be skipped
        id: skip_check
        uses: fkirc/skip-duplicate-actions@v5.3.1
        with:
          skip_after_successful_duplicate: "true"
          paths: '[".cargo/**", ".github/workflows/rust.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml", "Cross.toml"]'
          do_not_skip: '["workflow_dispatch", "push"]'

  # Runs rustfmt + tests on the main supported platforms.
  supported:
    needs: pre-job
    runs-on: ${{ matrix.info.os }}
    if: ${{ needs.pre-job.outputs.should_skip != 'true' }}
    strategy:
      fail-fast: false
      matrix:
        info:
          - {
              os: "ubuntu-latest",
              target: "x86_64-unknown-linux-gnu",
              cross: false,
            }
          - {
              os: "ubuntu-latest",
              target: "aarch64-unknown-linux-gnu",
              cross: true,
            }
          - {
              os: "ubuntu-latest",
              target: "i686-unknown-linux-gnu",
              cross: true,
            }
          - {
              os: "windows-latest",
              target: "x86_64-pc-windows-msvc",
              cross: false,
            }
          - {
              os: "macos-13",
              target: "x86_64-apple-darwin",
              cross: false,
            }
          - {
              os: "ubuntu-latest",
              target: "x86_64-unknown-linux-musl",
              cross: true,
            }
          - {
              os: "ubuntu-latest",
              target: "i686-unknown-linux-musl",
              cross: true,
            }
          - {
              os: "ubuntu-latest",
              target: "armv7-unknown-linux-gnueabihf",
              cross: true,
            }
          - {
              os: "ubuntu-latest",
              target: "armv7-unknown-linux-musleabihf",
              cross: true,
            }
        features: ["--all-features", "--no-default-features"]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5.0.0

      - name: Set up Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: rustfmt, clippy
          target: ${{ matrix.info.target }}

      - name: Enable Rust cache
        uses: Swatinem/rust-cache@v2.8.1
        if: ${{ github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork }} # If it is a PR, only if not a fork
        with:
          shared-key: build-cache-${{ matrix.info.target }}

      - name: Install cross
        if: ${{ matrix.info.cross }}
        run: |

          dir="$RUNNER_TEMP/cross-download"
          mkdir "$dir"
          echo "$dir" >> $GITHUB_PATH
          cd "$dir"
          curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
          tar xf cross-x86_64-unknown-linux-musl.tar.gz

      - name: Check cargo fmt
        run: cargo fmt --all -- --check

      - name: Run clippy
        if: ${{ !matrix.info.cross }}
        run: cargo clippy --all-features --target=${{ matrix.info.target }} -- -D warnings

      - name: Build tests
        run: ${{ matrix.info.cross && 'cross' || 'cargo' }} test --no-run --locked ${{ matrix.features }} --target=${{ matrix.info.target }}
        env:
          RUST_BACKTRACE: full

      - name: Run tests
        if: ${{ !matrix.info.cross }}
        run: cargo test --no-fail-fast ${{ matrix.features }} --target=${{ matrix.info.target }} -- --nocapture --quiet
        env:
          RUST_BACKTRACE: full

  completion:
    name: "CI Pass Check"
    needs: [supported]
    runs-on: "ubuntu-latest"
    steps:
      - name: CI Passed
        run: |

          echo "CI workflow completed."