CI/CD for an Actix Web Service with GitHub Actions
Format-check, clippy, test, and build your Actix Web service.
Actix Web is a high-performance Rust web framework. Its CI is the standard Rust trio: fmt, clippy, test, plus a release build. This recipe runs all of them and produces a deployable binary.
What the pipeline does
- install the Rust toolchain
- check formatting with cargo fmt --check
- lint with cargo clippy -D warnings
- run tests with cargo test
- build a release binary
The workflow
Swatinem/rust-cache caches the Cargo registry and target directory. clippy with -D warnings turns lints into errors.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all --check
- run: cargo clippy --all-targets -- -D warnings
- run: cargo test --all
- run: cargo build --release
- uses: actions/upload-artifact@v4
with:
name: server
path: target/release/Caching and speed
Swatinem/rust-cache is essential: it caches the registry, git deps, and target directory so incremental builds skip already-compiled crates. Rust release builds are CPU-heavy; cheaper managed runners such as Latchkey (around 69% cheaper than GitHub-hosted) cut compile time and auto-retry transient crates.io fetches.
Deploying
The release binary is statically-ish linked; build a slim container (FROM debian:stable-slim) around it and deploy to ECS, Cloud Run, Fly.io, or Kubernetes. For a smaller image, target x86_64-unknown-linux-musl and use a scratch base.
Key takeaways
- Run fmt, clippy -D warnings, and test as gates.
- Swatinem/rust-cache is essential for build speed.
- A musl target yields a tiny scratch-based image.