stages:
- validate
- publish
default:
image: rust:slim
cache:
key:
files:
- Cargo.lock
paths:
- .cargo-cache/
- target/
before_script:
- apt-get update -qq && apt-get install -y -qq pkg-config libssl-dev ca-certificates
- export CARGO_HOME="${CI_PROJECT_DIR}/.cargo-cache"
- rustc --version
- cargo --version
build:
stage: validate
interruptible: true
script:
- cargo build --locked --all-features --verbose
test:
stage: validate
interruptible: true
script:
- cargo test --locked --all-features --verbose
test-native-tls:
stage: validate
interruptible: true
script:
- cargo test --locked --no-default-features --features native-tls --verbose
clippy:
stage: validate
interruptible: true
before_script:
- apt-get update -qq && apt-get install -y -qq pkg-config libssl-dev ca-certificates
- export CARGO_HOME="${CI_PROJECT_DIR}/.cargo-cache"
- rustup component add clippy
script:
- cargo clippy --locked --all-features --tests --examples -- -D warnings
fmt:
stage: validate
interruptible: true
before_script:
- export CARGO_HOME="${CI_PROJECT_DIR}/.cargo-cache"
- rustup component add rustfmt
script:
- cargo fmt --all -- --check
doc:
stage: validate
interruptible: true
variables:
RUSTDOCFLAGS: "-D warnings"
script:
- cargo doc --locked --all-features --no-deps
publish-dry-run:
stage: validate
interruptible: true
script:
- cargo publish --locked --dry-run --all-features --allow-dirty
publish:
stage: publish
script:
- |
if [ -z "${CARGO_REGISTRY_TOKEN:-}" ]; then
echo "Error: CARGO_REGISTRY_TOKEN is not set. Check GitLab CI/CD variable settings (ensure 'Protected' is unchecked or the tag is protected)."
exit 1
fi
- |
TAG="${CI_COMMIT_TAG#v}"
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
if [ "$TAG" != "$CARGO_VERSION" ]; then
echo "Error: tag $TAG does not match Cargo.toml version $CARGO_VERSION"
exit 1
fi
- cargo test --locked --all-features
- cargo publish --locked --all-features --token "${CARGO_REGISTRY_TOKEN}"
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
needs:
- build
- test
- clippy
- fmt
- doc
- publish-dry-run