name: CI
on:
push:
branches: [main, develop, "release/*"]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
jobs:
check-default:
name: Check (default = backend-embedded)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1 rustfmt,clippy
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-default-deps
lookup-only: true
- name: Check (default features)
run: cargo check --locked
- name: Build (default features)
run: cargo build --locked
check-full:
name: Check (full features)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1 rustfmt,clippy
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-full-deps
lookup-only: true
- name: Check (full)
run: cargo check --features "full" --locked
- name: Build (full)
run: cargo build --features "full" --locked
check-production:
name: Check (production + examples)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1 rustfmt,clippy
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-prod-deps
lookup-only: true
- name: Check (production features)
run: cargo check --features "production" --locked
- name: Check (examples, all features)
run: cargo check -p garrison-examples --all-features --locked
fmt:
name: Rustfmt
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1 rustfmt
shell: bash
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1 clippy
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-full-deps
lookup-only: true
- name: Clippy (default)
run: cargo clippy --no-default-features --features "default" -- -D warnings
- name: Clippy (full)
run: cargo clippy --features "full" -- -D warnings
test:
name: Test (${{ matrix.os }} / Rust ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ matrix.os == 'windows-latest' && 45 || 25 }}
env:
GARRISON_TEST_SQLITE_MEMORY: ${{ matrix.os == 'ubuntu-latest' && '1' || '0' }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [1.97.1, stable, beta]
exclude:
- os: windows-latest
rust: beta
- os: macos-latest
rust: beta
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain
env:
RUST_TOOLCHAIN: ${{ matrix.rust }}
run: bash scripts/setup_rust.sh "$RUST_TOOLCHAIN" rustfmt,clippy
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- name: "Install OpenSSL (Windows: webauthn attestation-ca)"
if: runner.os == 'Windows'
shell: pwsh
run: |
if (-not $env:VCPKG_ROOT) { $env:VCPKG_ROOT = 'C:\vcpkg' }
& "$env:VCPKG_ROOT\vcpkg.exe" install openssl:x64-windows-static-md --disable-metrics
if ($LASTEXITCODE -ne 0) { throw "vcpkg install openssl failed" }
"VCPKG_ROOT=$env:VCPKG_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
"VCPKGRS_TRIPLET=x64-windows-static-md" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-test-deps-${{ matrix.rust }}
lookup-only: true
- name: Test (default)
run: cargo test --no-default-features --features "default" --lib --locked
- name: Test (full)
run: cargo test --features "full" --lib --locked
- name: garrison cli-ops lib tests (ops command combo)
run: cargo test --features "cli-ops,account-credential,protocol-zeroize,db-sqlite,protocol-jwt,config-yaml,field-encryption,dao-key-index" --lib --locked
- name: Test (ban-sync)
if: matrix.os == 'ubuntu-latest' && matrix.rust == '1.97.1'
run: cargo test --no-default-features --features "ban-sync" --lib --locked
- name: Doctests (full)
if: matrix.os == 'ubuntu-latest' && matrix.rust == '1.97.1'
run: cargo test --features "full" --doc --locked
- name: Check (production)
if: matrix.os == 'ubuntu-latest' && matrix.rust == '1.97.1'
run: cargo check --features production --locked
- name: Test (db-sqlite)
if: matrix.os == 'ubuntu-latest' && matrix.rust == '1.97.1'
run: cargo test --no-default-features --features "db-sqlite" --lib --locked
test-compile-guard:
name: Test compile (${{ matrix.name }})
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- name: default
flags: --no-default-features --features default
- name: minimal
flags: --no-default-features
- name: db-web-policy-listener
flags: --no-default-features --features db-sqlite,web-axum,account-policy,listener
- name: email-credential-authflow
flags: --no-default-features --features email-verification,email-verification-smtp,account-credential,account-authflow
- name: jwt-ct-eq
flags: --no-default-features --features protocol-jwt,secure-ct-eq
- name: tenant-bruteforce
flags: --no-default-features --features tenant-isolation,firewall-bruteforce
- name: oauth2-redis
flags: --no-default-features --features oauth2-server,cache-redis
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/lib/jvm \
/usr/local/share/boost /usr/share/swift || true
sudo docker image prune --all --force > /dev/null 2>&1 || true
df -h /
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-guard-deps
lookup-only: true
- name: Compile tests (lib + integration, no run)
env:
TEST_FLAGS: ${{ matrix.flags }}
run: cargo test --no-run $TEST_FLAGS --locked
- name: Clean target before workspace compile
if: matrix.name == 'default'
run: cargo clean
- name: Compile workspace tests (examples/macros under full)
if: matrix.name == 'default'
env:
CARGO_PROFILE_DEV_DEBUG: 0
run: cargo test --workspace --no-run --features full --locked
doc:
name: Documentation
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-full-deps
lookup-only: true
- name: Build docs
run: cargo doc --no-deps --features "full"
- name: Install cargo-deadlinks
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: cargo-deadlinks
- name: Check broken links
run: |
set -euo pipefail
OUTPUT=$(cargo deadlinks --dir target/doc/garrison 2>&1 || true)
echo "$OUTPUT"
# 过滤已知外部 crate 死链(opentelemetry Context / tracing-subscriber dispatcher / warp Response)
# 精确匹配路径片段边界(/ 或 . 分隔),避免误过滤 TenantContext/GarrisonResponse 等自身类型
# - `config/Context does not exist` ← opentelemetry::FutureExt blanket impl
# - `config/dispatcher does not exist` ← tracing_subscriber::WithSubscriber blanket impl
# - `error/type.Response.html does not exist` ← warp::Reply::into_response blanket impl
NEW_DEADLINKS=$(echo "$OUTPUT" | grep "does not exist" | grep -vE "[/.](Context|dispatcher|Response)(\.html)? does not exist" || true)
if [ -n "$NEW_DEADLINKS" ]; then
echo "❌ Found new deadlinks (not from external crate trait impls):"
echo "$NEW_DEADLINKS"
exit 1
else
echo "✅ No new deadlinks. Known external-crate deadlinks (Context/dispatcher/Response) filtered."
fi
deny:
name: Cargo Deny
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: cargo-deny
- name: Generate Cargo.lock (library crate, not committed)
run: cargo generate-lockfile
- name: Run cargo deny
run: cargo deny --all-features --locked check
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
env:
GARRISON_TEST_SQLITE_MEMORY: "1"
GARRISON_TEST_REDIS: "1"
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres:16-alpine
ports:
- 5432:5432
env:
POSTGRES_USER: garrison
POSTGRES_PASSWORD: garrison
POSTGRES_DB: garrison_test
options: >-
--health-cmd "pg_isready -U garrison"
--health-interval 10s
--health-timeout 5s
--health-retries 5
timeout-minutes: 25
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-full-deps
lookup-only: true
- name: Integration tests (full features)
run: cargo test --features "full" --tests --no-fail-fast
coverage:
name: Coverage
runs-on: ubuntu-latest
env:
GARRISON_TEST_SQLITE_MEMORY: "1"
GARRISON_TEST_REDIS: "1"
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres:16-alpine
ports:
- 5432:5432
env:
POSTGRES_USER: garrison
POSTGRES_PASSWORD: garrison
POSTGRES_DB: garrison_test
options: >-
--health-cmd "pg_isready -U garrison"
--health-interval 10s
--health-timeout 5s
--health-retries 5
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Setup Rust toolchain (1.97.1)
run: bash scripts/setup_rust.sh 1.97.1
shell: bash
- name: Install protoc (sdforge build dep)
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: protoc
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 with:
shared-key: ci-coverage-deps
lookup-only: true
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@b80e2bb2635f28eb98b9fce1e2f0887e1535c6b2 with:
tool: cargo-llvm-cov
- name: Run coverage (fail under 95% lines)
run: cargo llvm-cov --features "full" --fail-under-lines 95 --lcov --output-path lcov.info
- name: Coverage summary
if: always()
run: cargo llvm-cov report --summary-only
- name: Upload coverage
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov.info
docker-build:
name: Docker build & smoke
runs-on: ubuntu-latest
timeout-minutes: 50
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/lib/jvm \
/usr/local/share/boost /usr/share/swift || true
sudo docker image prune --all --force > /dev/null 2>&1 || true
df -h /
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 - name: Build debian-slim image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc with:
context: .
file: ./docker/Dockerfile
push: false
load: true
tags: garrison-auth:ci
cache-from: type=gha,scope=garrison-docker
cache-to: type=gha,mode=max,scope=garrison-docker
build-args: |
VERSION=0.0.0-ci
GIT_SHA=${{ github.sha }}
- name: Validate compose example
run: GARRISON_INTERNAL_API_KEY=ci-smoke-key.000000000000000000000000000000000000000000000000000000 docker compose -f docker/docker-compose.example.yml config -q
- name: Smoke test (debian-slim)
run: |
set -euo pipefail
docker run -d --name smoke-debian \
-e GARRISON_INTERNAL_API_KEY=ci-smoke-key.000000000000000000000000000000000000000000000000000000 \
-p 127.0.0.1:8080:8080 garrison-auth:ci
status=""
for _ in $(seq 1 30); do
status="$(docker inspect -f '{{.State.Health.Status}}' smoke-debian)"
if [ "$status" = "healthy" ]; then break; fi
curl -sf http://127.0.0.1:8080/healthz > /dev/null 2>&1 || true
sleep 3
done
echo "final Health.Status: ${status:-<inspect-failed>}"
[ "$status" = "healthy" ]
- name: Dump smoke-debian diagnostics
if: failure()
run: |
docker logs smoke-debian || true
docker inspect --format '{{json .State.Health}}' smoke-debian || true
- name: Remove smoke-debian container
if: always()
run: docker rm -f smoke-debian || true
- name: Build distroless image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc with:
context: .
file: ./docker/Dockerfile.distroless
push: false
load: true
tags: garrison-auth:ci-distroless
cache-from: type=gha,scope=garrison-docker
cache-to: type=gha,mode=max,scope=garrison-docker
build-args: |
VERSION=0.0.0-ci
GIT_SHA=${{ github.sha }}
- name: Smoke test (distroless)
run: |
set -euo pipefail
docker run -d --name smoke-distroless \
-e GARRISON_INTERNAL_API_KEY=ci-smoke-key.000000000000000000000000000000000000000000000000000000 garrison-auth:ci-distroless
status=""
for _ in $(seq 1 30); do
status="$(docker inspect -f '{{.State.Health.Status}}' smoke-distroless)"
if [ "$status" = "healthy" ]; then break; fi
docker exec smoke-distroless /app/garrison healthcheck || true
sleep 3
done
echo "final Health.Status: ${status:-<inspect-failed>}"
[ "$status" = "healthy" ]
- name: Dump smoke-distroless diagnostics
if: failure()
run: |
docker logs smoke-distroless || true
docker inspect --format '{{json .State.Health}}' smoke-distroless || true
- name: Remove smoke-distroless container
if: always()
run: docker rm -f smoke-distroless || true