stages:
- check
- publish
image: rust:latest
cache:
paths:
- target/
- ~/.cargo/
lint:
stage: check
script:
- rustup component add rustfmt clippy
- cargo fmt -- --check
- cargo clippy -- -D warnings
rules:
- when: always
publish:
stage: publish
script:
- TAG_VERSION=${CI_COMMIT_TAG#v}
- CARGO_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml)
- |
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- echo "Publishing crate version $CARGO_VERSION to crates.io"
- cargo publish --no-verify
rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+.*$/
environment:
name: crates-io