# Define slightly different stages. # Additionally, lint the code before anything else to fail more quickly stages: - lint - build - test - release - dockerify default: image: "rust:latest" tags: - linux - docker variables: GIT_SUBMODULE_STRATEGY: recursive CARGO_HOME: $CI_PROJECT_DIR/cargo APT_CACHE_DIR: $CI_PROJECT_DIR/apt # cache dependencies and build environment to speed up setup cache: key: "$CI_COMMIT_REF_SLUG" paths: - apt/ - cargo/ - target/ # install build dependencies before_script: - apt-get update -yqq - apt-get install -o dir::cache::archives="$APT_CACHE_DIR" -yqq --no-install-recommends capnproto build-essential cmake clang libclang-dev jq - rustup component add rustfmt - rustup component add clippy - cargo install cargo2junit .lints: stage: lint allow_failure: true only: - merge_requests # Use clippy lints lint:clippy: extends: .lints script: - cargo +stable clippy -V - echo -e "\e[0Ksection_start:`date +%s`:clippy_output\r\e[0K`cargo clippy` output" - cargo +stable clippy -- --no-deps - echo -e "\e[0Ksection_end:`date +%s`:clippy_output\r\e[0K" # Use rustfmt to check formating lint:fmt: extends: .lints allow_failure: false script: - cargo +stable fmt --version - echo -e "\e[0Ksection_start:`date +%s`:rustfmt_output\r\e[0KChanges suggested by rustfmt" - cargo +stable fmt --check -- -v - echo -e "\e[0Ksection_end:`date +%s`:rustfmt_output\r\e[0K" # Check if the code builds on rust stable stable:build: stage: build script: - rustc +stable --version && cargo +stable --version - echo -e "\e[0Ksection_start:`date +%s`:build_output\r\e[0KOutput of `cargo check`" - cargo +stable check --verbose - echo -e "\e[0Ksection_end:`date +%s`:build_output\r\e[0K" stable:test: stage: build needs: ["stable:build"] only: - main - development - merge_requests script: - echo -e "\e[0Ksection_start:`date +%s`:build_output\r\e[0KOutput of `cargo test --no-run`" - cargo +stable test --verbose --no-run --workspace - echo -e "\e[0Ksection_end:`date +%s`:build_output\r\e[0K" .tests: stage: test needs: ["stable:test"] script: - > cargo +stable test --workspace $TEST_TARGET -- -Z unstable-options --format json --report-time | cargo2junit > report.xml artifacts: when: always reports: junit: - report.xml only: - main - development - merge_requests # Run unit tests unit test 1:3: variables: TEST_TARGET: "--lib" extends: .tests unit test 2:3: variables: TEST_TARGET: "--bins" extends: .tests unit test 3:3: variables: TEST_TARGET: "--examples" extends: .tests release_prepare: stage: release rules: - if: $CI_COMMIT_TAG =~ "release/.*" when: never - if: $CI_COMMIT_BRANCH == "main" script: - VERSION="cargo metadata --format-version 1 | jq -C '.packages | .[] | select(.name == "diflouroborane") | .version' -r" - echo $VERSION > release.env artifacts: reports: dotenv: release.env release_job: stage: release needs: - job: release_prepare artifacts: true image: registry.gitlab.com/gitlab-org/release-cli:latest rules: - if: $CI_COMMIT_TAG =~ "release/.*" when: never - if: $CI_COMMIT_BRANCH == "main" script: - echo "Creating GitLab releaseā€¦" release: name: "BFFH $VERSION" description: "GitLab CI auto-created release" tag_name: "release/$VERSION" build:docker-releases: stage: dockerify image: name: gcr.io/kaniko-project/executor:v1.6.0-debug entrypoint: [""] before_script: - '' script: - mkdir -p /kaniko/.docker - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - /kaniko/executor --force --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG rules: - if: $CI_COMMIT_TAG =~ "release/.*" when: never build:docker-development: stage: dockerify image: name: gcr.io/kaniko-project/executor:v1.6.0-debug entrypoint: [""] before_script: - '' script: - mkdir -p /kaniko/.docker - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - /kaniko/executor --force --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:dev-latest only: - development