1
0
mirror of https://gitlab.com/MisterBiggs/aoc_2015-rust.git synced 2025-06-15 22:46:43 +00:00

adding ci lint, check, and test

This commit is contained in:
Anson 2022-11-05 22:54:28 -06:00
parent 2e7336b959
commit 40727010d9

126
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,126 @@
image: 'rust:latest'
stages:
- check
- lint
- test
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
script:
- cargo check --workspace
fmt:
stage: lint
extends: .common
needs:
- job: check
artifacts: false
before_script:
- rustup component add rustfmt
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
artifacts:
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: 'rustlang/rust:nightly-bullseye'
stage: test
extends: .common
needs:
- job: check
artifacts: false
variables:
RUSTFLAGS: "-Zinstrument-coverage"
LLVM_PROFILE_FILE: "coverage-%p-%m.profraw"
before_script:
- rustup component add llvm-tools-preview
- curl -L https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf -
script:
- cargo +nightly test
- ./grcov . --binary-path ./target/debug/ -s . -t cobertura --branch --ignore-not-existing --ignore "*cargo*" -o coverage.xml
- grep -Eo 'line-rate="[^"]+"' coverage.xml | head -n 1 | grep -Eo '[0-9.]+' | awk '{ print "Coverage:", $1 * 100 }'
coverage: '/Coverage: \d+\.\d+/'
artifacts:
name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
expire_in: 2 days
reports:
cobertura: coverage.xml