diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae51c3a..9596d51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,25 +4,30 @@ on: workflow_dispatch: pull_request: push: + branches: + - master jobs: unit-test: - name: Unit test using ${{matrix.rust}} + name: Unit test runs-on: ubuntu-latest timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - rust: [ 1.77, nightly, beta, stable ] steps: - name: Checkout code uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@master with: - toolchain: ${{matrix.rust}} + toolchain: stable + components: clippy + - uses: extractions/setup-just@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Install cargo-nextest + uses: taiki-e/install-action@nextest - name: Run unit tests run: | - cargo test --release + just unit-test + lint: name: Lint runs-on: ubuntu-latest @@ -30,9 +35,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@master with: toolchain: stable components: clippy + - uses: extractions/setup-just@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run lint - run: cargo clippy --all-targets --all-features + run: just lint diff --git a/Cargo.toml b/Cargo.toml index ac8c798..cbb35f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ tracing = "0.1.40" tracing-subscriber = { version = "0.3.18" } tower-http = { version = "0.5.2", features = ["add-extension", "trace", "cors", "timeout"] } tokio = { version = "1.37.0", features = ["rt-multi-thread", "signal", "macros", "net", "io-util"] } -axum = { version = "0.7" } +axum = { version = "0.7.5" } diff --git a/README.md b/README.md index 0948861..e6f1c12 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [github](https://github.com/zarvd/echoserver) [crates.io](https://crates.io/crates/echoserver) -[docs.rs](https://docs.rs/echoserver) [build status](https://github.com/zarvd/echoserver/actions?query%3Amaster) [dependency status](https://deps.rs/repo/github/zarvd/echoserver) diff --git a/justfile b/justfile index ea1d13f..38a734f 100644 --- a/justfile +++ b/justfile @@ -1,26 +1,29 @@ -image_repo := "ghcr.io/zarvd/echoserver" - default: just --list +# Build the project build: - cargo build --release - -run: - cargo run --release + cargo build +# Format code with rust fmt: cargo fmt -test: - cargo test --release +# Run unit tests against the current platform +unit-test: + cargo nextest run +# Lint code with clippy lint: - cargo clippy --release + cargo fmt --all -- --check + cargo clippy --all-targets --all-features +# Clean workspace clean: cargo clean +image_repo := "ghcr.io/zarvd/echoserver" +# Build docker image image tag: clean docker buildx build ./ \ --output=type=docker \ diff --git a/src/http.rs b/src/http.rs index 9e1e2aa..1cebb52 100644 --- a/src/http.rs +++ b/src/http.rs @@ -48,10 +48,10 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { let listener = TcpListener::bind(addr) .await - .expect(&format!("bind HTTP server on {addr}")); + .unwrap_or_else(|e| panic!("failed to bind HTTP server on {addr}: {e}")); axum::serve(listener, app) .await - .expect(&format!("serve HTTP server on {addr}")); + .unwrap_or_else(|e| panic!("failed to serve HTTP server on {addr}: {e}")); Ok(()) } diff --git a/src/signal.rs b/src/signal.rs index fc250c2..2ffaa81 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -7,7 +7,7 @@ pub async fn shutdown() { () = recv_signal_and_shutdown(SignalKind::terminate()) => {} }; - info!("recv signal and shutting down"); + info!("received signal and shutting down"); } async fn recv_signal_and_shutdown(kind: SignalKind) { diff --git a/src/tcp.rs b/src/tcp.rs index 1db2339..acc917b 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -34,7 +34,7 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { let lis = TcpListener::bind(addr) .await - .expect(&format!("bind TCP server on {addr}")); + .unwrap_or_else(|e| panic!("failed to bind TCP server on {addr}: {e}")); loop { match lis.accept().await { @@ -42,7 +42,7 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { tokio::spawn(handle(socket)); } Err(e) => { - error!("[TCP/{}] Failed to accept new socket: {}", addr, e); + error!("[TCP/{addr}] Failed to accept new socket: {e}"); } } } diff --git a/src/udp.rs b/src/udp.rs index 28a1837..35fe623 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -21,7 +21,7 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { let socket = Arc::new( UdpSocket::bind(addr) .await - .expect(&format!("bind TCP server on {addr}")), + .unwrap_or_else(|e| panic!("failed to bind UDP server on {addr}: {e}")), ); loop { @@ -30,10 +30,10 @@ pub async fn serve(addr: SocketAddr) -> Result<()> { Ok((n, remote_addr)) => { handle(socket.clone(), remote_addr, &buf[0..n]) .await - .expect(&format!("echo data from UDP server {addr}")); + .unwrap_or_else(|e| panic!("failed to echo data from UDP server {addr}: {e}")); } Err(e) => { - error!("Failed to receive data: {}", e); + error!("[UDP/{addr}] Failed to receive data: {e}"); } } }