Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 96 additions & 12 deletions .github/workflows/rust-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,119 @@ on:
branches:
- "*"

env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: true
SCCACHE_CACHE_SIZE: 2G
SCCACHE_DIR: /home/runner/.cache/sccache

jobs:
build:
name: Publish for ${{ matrix.os }}
name: Build for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [linux, windows, macos]

include:
- name: linux
# Tier 1 Platforms
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: bping
asset_name: bping-linux
- name: windows
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact_name: bping.exe
asset_name: bping-windows
- name: macos
- target: x86_64-apple-darwin
os: macos-latest
artifact_name: bping
asset_name: bping-macos
- target: i686-pc-windows-msvc
os: windows-latest
artifact_name: bping.exe
- target: i686-unknown-linux-gnu
os: ubuntu-latest
artifact_name: bping
gcc_package: gcc-multilib

# Tier 2 Platforms
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: bping
gcc_package: gcc-aarch64-linux-gnu
linker: aarch64-linux-gnu-gcc
- target: aarch64-apple-darwin
os: macos-latest
artifact_name: bping
- target: arm-unknown-linux-gnueabi
os: ubuntu-latest
artifact_name: bping
gcc_package: gcc-arm-linux-gnueabi
linker: arm-linux-gnueabi-gcc
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
artifact_name: bping
gcc_package: gcc-arm-linux-gnueabihf
linker: arm-linux-gnueabihf-gcc
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
artifact_name: bping
gcc_package: musl-tools

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Install build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y curl build-essential pkg-config libssl-dev
if [ ! -z "${{ matrix.gcc_package }}" ]; then
sudo apt-get install -y ${{ matrix.gcc_package }}
fi

- uses: actions-rs/toolchain@v1
- name: Configure Cargo for cross-compilation
if: matrix.linker != ''
run: |
mkdir -p ~/.cargo
echo "[target.${{ matrix.target }}]" >> ~/.cargo/config.toml
echo "linker = \"${{ matrix.linker }}\"" >> ~/.cargo/config.toml

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Configure sccache
run: |
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1-rust"
shared-key: "${{ matrix.target }}-build"
cache-targets: "true"
cache-on-failure: "true"
cache-all-crates: "true"
save-if: ${{ github.ref == 'refs/heads/master' }}
workspaces: |
. -> target

- name: Build
run: cargo build --release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}

- name: Show sccache stats
run: sccache --show-stats

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}-binary
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
127 changes: 109 additions & 18 deletions .github/workflows/rust-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,138 @@ on:
tags:
- "*"

env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: true
SCCACHE_CACHE_SIZE: 2G
SCCACHE_DIR: /home/runner/.cache/sccache

jobs:
publish:
name: Publish for ${{ matrix.os }}
name: Publish for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [linux, windows, macos]

include:
- name: linux
# Tier 1 Platforms
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: bping
asset_name: bping-linux
- name: windows
asset_name: bping-x86_64-linux-gnu
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact_name: bping.exe
asset_name: bping-windows
- name: macos
asset_name: bping-x86_64-windows-msvc.exe
- target: x86_64-apple-darwin
os: macos-latest
asset_name: bping-x86_64-darwin
- target: i686-pc-windows-msvc
os: windows-latest
asset_name: bping-i686-windows-msvc.exe
- target: i686-unknown-linux-gnu
os: ubuntu-latest
asset_name: bping-i686-linux-gnu
gcc_package: gcc-multilib

# Tier 2 Platforms
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
asset_name: bping-aarch64-linux-gnu
gcc_package: gcc-aarch64-linux-gnu
linker: aarch64-linux-gnu-gcc
- target: aarch64-apple-darwin
os: macos-latest
artifact_name: bping
asset_name: bping-macos
asset_name: bping-aarch64-darwin
- target: arm-unknown-linux-gnueabi
os: ubuntu-latest
asset_name: bping-arm-linux-gnueabi
gcc_package: gcc-arm-linux-gnueabi
linker: arm-linux-gnueabi-gcc
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
asset_name: bping-armv7-linux-gnueabihf
gcc_package: gcc-arm-linux-gnueabihf
linker: arm-linux-gnueabihf-gcc
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
asset_name: bping-x86_64-linux-musl
gcc_package: musl-tools

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
- name: Install build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y curl build-essential pkg-config libssl-dev
if [ ! -z "${{ matrix.gcc_package }}" ]; then
sudo apt-get install -y ${{ matrix.gcc_package }}
fi

- name: Configure Cargo for cross-compilation
if: matrix.linker != ''
run: |
mkdir -p ~/.cargo
echo "[target.${{ matrix.target }}]" >> ~/.cargo/config.toml
echo "linker = \"${{ matrix.linker }}\"" >> ~/.cargo/config.toml

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Configure sccache
run: |
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1-rust"
shared-key: "${{ matrix.target }}-release"
cache-targets: "true"
cache-on-failure: "true"
cache-all-crates: "true"
save-if: true # Always save cache for tagged releases
workspaces: |
. -> target

- name: Build
run: cargo build --release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}

- name: Show sccache stats
run: sccache --show-stats

- name: Strip
run: strip target/release/${{ matrix.artifact_name }}
- name: Strip binary
if: runner.os != 'Windows'
run: |
if [ "${{ matrix.target }}" != "aarch64-apple-darwin" ]; then
if [ -n "${{ matrix.linker }}" ]; then
${{ matrix.target }}-strip target/${{ matrix.target }}/release/bping
else
strip target/${{ matrix.target }}/release/bping
fi
fi

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/release/${{ matrix.artifact_name }}
file: target/${{ matrix.target }}/release/bping${{ runner.os == 'Windows' && '.exe' || '' }}
asset_name: ${{ matrix.asset_name }}
tag: ${{ github.ref }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}-release-binary
path: target/${{ matrix.target }}/release/bping${{ runner.os == 'Windows' && '.exe' || '' }}
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ opt-level = "z"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.12.5", features = ["json"] }
reqwest = { version = "0.12", features = [
"json",
"rustls-tls",
], default-features = false }
spinners = "4.1.1"
tokio = { version = "1.38.0", features = ["full"] }
dirs = "5.0.1"
Expand All @@ -24,7 +27,7 @@ colorful = "0.3.2"
indicatif = "0.17.8"
chrono = { version = "0.4", features = ["serde"] }
celes = "2.4.0"
thiserror = "1.0.61"
thiserror = "2.0"
async-stream = "0.3.5"
console = "0.15.8"
keshvar = { version = "0.5.0", features = ["serde", "emojis"] }
Expand Down
39 changes: 4 additions & 35 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ async fn main() -> eyre::Result<()> {
pb.set_style(spinner_style);

for region in &APP_CONFIG.regions {
for chunk in (0..APP_CONFIG.attempts).collect::<Vec<_>>().chunks(100) {
for chunk in (0..APP_CONFIG.attempts)
.collect::<Vec<_>>()
.chunks(APP_CONFIG.concurrency)
{
let mut chunk_set = JoinSet::new();

for _ in chunk {
Expand Down Expand Up @@ -137,37 +140,3 @@ async fn main() -> eyre::Result<()> {
pb.finish();
Ok(())
}

// async fn perform_job(
// req: &models::CreateJobAPIRequest,
// token: &str,
// ) -> Result<GetJobAPIResponse, BpingErrors> {
// let resp = api::post_job(req, token).await?;
// let job_id = resp.id;
// let res = api::get_job_results(&job_id, token).await?;
// Ok(res)
// }
//
// async fn check_node_availability(parsed_regions: Vec<String>) -> Result<(), BpingErrors> {
// if let Ok(available_nodes) = api::get_available_nodes().await {
// for region in parsed_regions {
// if custom_validators::is_continent(&region) {
// continue;
// }
//
// if let Some(country_code) = custom_validators::get_emoji_safe_region_code(&region) {
// if let None = available_nodes
// .results
// .iter()
// .find(|x| x.countrycode == country_code)
// {
// return Err(BpingErrors::JobErrors(
// crate::api::JobErrors::UnableToFindNodes,
// ));
// }
// }
// }
// }
//
// Ok(())
// }
7 changes: 7 additions & 0 deletions src/options/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Opts {
pub count: usize,
pub attempts: usize,
pub api_key: String,
pub concurrency: usize,
}

impl Opts {
Expand Down Expand Up @@ -47,10 +48,16 @@ impl Opts {
.env("BITPING_API_KEY")
.argument("api_key");

let concurrency = bpaf::long("concurrency")
.help("Specifies how many concurrent requests to send at once. Defaults to 100.")
.argument::<usize>("concurrency")
.fallback(100);

bpaf::construct!(Opts {
regions,
count,
attempts,
concurrency,
api_key,
endpoint,
})
Expand Down
Loading