diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4f5d81c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: Check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - run: cargo build --release + - run: cargo test + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy -- -D warnings + - run: cargo fmt --check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8434f61 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: Release + +on: + push: + tags: ["v*"] + +permissions: + contents: write + +jobs: + build: + name: Build ${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest + - target: aarch64-apple-darwin + os: macos-latest + - target: x86_64-pc-windows-msvc + os: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - uses: Swatinem/rust-cache@v2 + - run: cargo build --release --target ${{ matrix.target }} + - name: Package (Unix) + if: runner.os != 'Windows' + run: | + cd target/${{ matrix.target }}/release + tar czf ../../../fledge-plugin-speedtest-${{ matrix.target }}.tar.gz fledge-speedtest + - name: Package (Windows) + if: runner.os == 'Windows' + run: | + cd target/${{ matrix.target }}/release + 7z a ../../../fledge-plugin-speedtest-${{ matrix.target }}.zip fledge-speedtest.exe + - uses: softprops/action-gh-release@v2 + with: + files: | + fledge-plugin-speedtest-*.tar.gz + fledge-plugin-speedtest-*.zip diff --git a/src/main.rs b/src/main.rs index 1032677..eb96d32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,19 +16,9 @@ const UP_URL: &str = "https://speed.cloudflare.com/__up"; /// on fast links. We rotate through the list, repeating until --duration is up. /// Upload sizes are capped lower because Cloudflare's `__up` endpoint resets /// the connection on very large bodies. -const DOWNLOAD_SIZES: &[u64] = &[ - 100_000, - 1_000_000, - 10_000_000, - 25_000_000, - 100_000_000, -]; - -const UPLOAD_SIZES: &[u64] = &[ - 100_000, - 1_000_000, - 10_000_000, -]; +const DOWNLOAD_SIZES: &[u64] = &[100_000, 1_000_000, 10_000_000, 25_000_000, 100_000_000]; + +const UPLOAD_SIZES: &[u64] = &[100_000, 1_000_000, 10_000_000]; const WARMUP_BYTES: u64 = 100_000; const DEFAULT_DURATION_SECS: u64 = 10; @@ -155,7 +145,8 @@ fn measure_latency(client: &Client, show_progress: bool) -> Result { .send() .context("latency probe")?; let mut sink = Vec::new(); - resp.read_to_end(&mut sink).context("draining latency probe")?; + resp.read_to_end(&mut sink) + .context("draining latency probe")?; let ms = start.elapsed().as_secs_f64() * 1000.0; if ms < best { best = ms; @@ -259,12 +250,7 @@ fn measure_upload(client: &Client, window: Duration, show_progress: bool) -> Res let stop_clone = Arc::clone(&stop); let handle = thread::spawn(move || { while !stop_clone.load(Ordering::Relaxed) { - draw_progress_label( - "Upload", - start.elapsed().min(window), - window, - &label, - ); + draw_progress_label("Upload", start.elapsed().min(window), window, &label); thread::sleep(PROGRESS_TICK); } });