name: Rust CI
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
CARGO_INCREMENTAL: 0
jobs:
check:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Update to latest Rust
run: rustup update
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Check build
run: cargo build --locked --all-targets --all-features
- name: Check build with no default features
run: cargo build --locked --all-targets --no-default-features
env:
RUSTFLAGS: "-D warnings -A unused"
- name: Check with Clippy
run: cargo clippy --locked --all-targets --all-features -- -D warnings
- name: Run publish dry-run first run
run: cargo publish --locked --dry-run
- name: Run publish dry-run second run
if: runner.os == 'Linux'
run: |
rm -r target/
mkdir -p ${{ runner.temp }}
sha256sum target/package/*.crate > ${{ runner.temp }}/SHA256SUMS.txt
cat ${{ runner.temp }}/SHA256SUMS.txt
rm -r target/
cargo publish --locked --dry-run
cat ${{ runner.temp }}/SHA256SUMS.txt
sha256sum -c ${{ runner.temp }}/SHA256SUMS.txt
- name: Archive artifacts
uses: actions/upload-artifact@v4
if: runner.os == 'Linux'
with:
name: cargo-proxy
path: target/package/ollama-proxy-*.crate
if-no-files-found: error
- name: Run tests
run: cargo test --locked --release --all-features
docs:
name: Build Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update to latest Rust
run: rustup update
- name: Build documentation
run: cargo doc --locked --no-deps --all-features --document-private-items
env:
RUSTDOCFLAGS: "-D warnings"
msrv:
name: Test Minimum Supported Rust Version (MSRV)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract MSRV from Cargo.toml
id: msrv
run: |
MSRV=$(grep -E '^rust-version\s*=' Cargo.toml | head -n1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
if [ -z "$MSRV" ]; then
echo "MSRV not found in Cargo.toml"
exit 1
fi
echo "msrv=$MSRV" >> $GITHUB_OUTPUT
- name: Install MSRV toolchain
run: |
rustup install ${{ steps.msrv.outputs.msrv }}
rustup default ${{ steps.msrv.outputs.msrv }}
- name: Check with MSRV
run: cargo +${{ steps.msrv.outputs.msrv }} check --locked
- name: Test with MSRV
run: cargo +${{ steps.msrv.outputs.msrv }} test --locked --release