diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e303ae5..368644c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,124 +1,21 @@ -image: 'rust:latest' - -stages: - - check - - lint - - test +# Official language image. Look for the different tagged releases at: +# https://hub.docker.com/r/library/rust/tags/ +image: "rust:latest" -variables: - CARGO_HOME: $CI_PROJECT_DIR/cargo_cache - DEBIAN_BINARY: "debian-x86_64-${CI_COMMIT_TAG}.tar.bz2" - PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/gitlab-clippy/${CI_COMMIT_TAG}" - -.common: - interruptible: true - cache: - key: - files: - - Cargo.lock - paths: - # https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci - - cargo_cache/bin - - cargo_cache/registry/index - - cargo_cache/registry/cache - - cargo_cache/git/db - policy: pull - -.recreate_cache: - cache: - policy: pull-push - -check: - stage: check - needs: [] - extends: - - .common - - .recreate_cache +# Use cargo to test the project +test:cargo: script: - - cargo check --workspace + - rustc --version && cargo --version # Print version info for debugging + - cargo test --workspace --verbose -fmt: - stage: lint - extends: .common - needs: - - job: check - artifacts: false - before_script: - - rustup component add rustfmt +# Optional: Use a third party library to generate gitlab junit reports +test:junit-report: script: - - cargo fmt --all -- --check - -clippy-cli: - stage: lint - before_script: - - rustup component add clippy - - cargo install --path . - script: - - cargo clippy - after_script: - - cargo clippy --message-format=json | $CARGO_HOME/bin/gitlab-clippy > gl-code-quality-report.json + Should be specified in Cargo.toml + - cargo install junitify + - cargo test -- --format=json -Z unstable-options --report-time | junitify --out $CI_PROJECT_DIR/tests/ artifacts: + when: always reports: - codequality: gl-code-quality-report.json - expire_in: 1 week - rules: - - if: '$CODE_QUALITY_DISABLED' - when: never - - if: '$CI_PIPELINE_SOURCE == "push"' - -clippy-be: - stage: lint - extends: .common - needs: - - job: check - artifacts: false - before_script: - - rustup component add clippy - script: - - cargo clippy - after_script: - - cargo clippy --message-format=json &> clippy.txt || true - - curl -X POST "https://gitlab-cq-rust.herokuapp.com/clippy" --data-binary @clippy.txt --output report.json - artifacts: - reports: - codequality: report.json - expire_in: 1 week - rules: - - if: '$CODE_QUALITY_DISABLED' - when: never - - if: '$CI_PIPELINE_SOURCE == "push"' - -test: - stage: test - extends: .common - needs: - - job: check - artifacts: false - before_script: - - rustup component add clippy - script: - - cargo test --all - -coverage: - image: "rustdocker/rust:nightly" - stage: extras - variables: - RUSTFLAGS: "-Zinstrument-coverage" - LLVM_PROFILE_FILE: "coverage-%p-%m.profraw" - script: - - rustup component add llvm-tools-preview - - cargo test - # generate html report - - cargo install grcov - - grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing --ignore "*cargo*" -o ./coverage/ - # generate cobertura report for gitlab integration - - pip3 install lcov_cobertura - - grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "*cargo*" -o coverage.lcov - - python3 /usr/local/lib/python3.5/dist-packages/lcov_cobertura.py coverage.lcov - artifacts: - reports: - coverage_report: - coverage_format: cobertura - path: cobertura.xml - coverage: '/^\d+.\d+% coverage/' \ No newline at end of file + junit: $CI_PROJECT_DIR/tests/*.xml