fabaccess-bffh/.gitlab-ci.yml

176 lines
4.5 KiB
YAML
Raw Normal View History

2022-05-05 19:13:23 +02:00
# 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
2020-09-16 12:41:05 +02:00
variables:
GIT_SUBMODULE_STRATEGY: recursive
2022-05-05 19:13:23 +02:00
CARGO_HOME: $CI_PROJECT_DIR/cargo
2020-09-16 12:41:05 +02:00
APT_CACHE_DIR: $CI_PROJECT_DIR/apt
2022-05-05 19:13:23 +02:00
# cache dependencies and build environment to speed up setup
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- apt/
- cargo/
- target/
2020-09-16 12:41:05 +02:00
# install build dependencies
before_script:
- apt-get update -yqq
2022-05-05 19:13:23 +02:00
- apt-get install -o dir::cache::archives="$APT_CACHE_DIR" -yqq --no-install-recommends capnproto build-essential cmake clang libclang-dev jq
2020-09-16 12:41:05 +02:00
2022-05-05 19:25:06 +02:00
.lints:
2022-05-05 19:13:23 +02:00
stage: lint
2020-09-16 12:41:05 +02:00
allow_failure: true
only:
- merge_requests
2020-09-16 12:41:05 +02:00
2022-05-05 19:13:23 +02:00
# Use clippy lints
lint:clippy:
extends: .lints
script:
- rustup component add clippy
2022-05-05 21:17:52 +02:00
- cargo clippy -V
2022-05-05 22:07:21 +02:00
- echo -e "\e[0Ksection_start:`date +%s`:clippy_output\r\e[0Kcargo clippy output"
2022-05-05 21:17:52 +02:00
- cargo clippy -- --no-deps
2022-05-05 19:13:23 +02:00
- echo -e "\e[0Ksection_end:`date +%s`:clippy_output\r\e[0K"
# Use rustfmt to check formating
2020-09-16 12:41:05 +02:00
lint:fmt:
2022-05-05 19:13:23 +02:00
extends: .lints
2020-09-16 12:41:05 +02:00
script:
- rustup component add rustfmt
2022-05-05 21:17:52 +02:00
- cargo fmt --version
2022-05-05 19:13:23 +02:00
- echo -e "\e[0Ksection_start:`date +%s`:rustfmt_output\r\e[0KChanges suggested by rustfmt"
2022-05-05 21:17:52 +02:00
- cargo fmt --check -- -v
2022-05-05 19:13:23 +02:00
- echo -e "\e[0Ksection_end:`date +%s`:rustfmt_output\r\e[0K"
2022-05-05 19:37:35 +02:00
# Check if the code builds on rust stable
stable:build:
2022-05-05 19:13:23 +02:00
stage: build
2022-05-05 21:09:12 +02:00
only:
- main
- development
- merge_requests
2020-09-16 12:41:05 +02:00
script:
2022-05-05 21:17:52 +02:00
- rustc +stable --version && cargo --version
2022-05-05 22:07:21 +02:00
- echo -e "\e[0Ksection_start:`date +%s`:build_output\r\e[0KOutput of cargo check"
2022-05-05 21:17:52 +02:00
- cargo check --verbose
2022-05-05 19:13:23 +02:00
- 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:
2022-05-05 22:07:21 +02:00
- echo -e "\e[0Ksection_start:`date +%s`:build_output\r\e[0KOutput of cargo test --no-run"
2022-05-05 21:17:52 +02:00
- cargo test --verbose --no-run --workspace
2022-05-05 19:13:23 +02:00
- echo -e "\e[0Ksection_end:`date +%s`:build_output\r\e[0K"
2022-05-05 22:15:58 +02:00
- cargo install --root $CARGO_HOME cargo2junit
2022-05-05 19:13:23 +02:00
.tests:
stage: test
needs: ["stable:test"]
2022-05-05 19:13:23 +02:00
script:
2022-05-05 22:15:58 +02:00
- cargo test --workspace $TEST_TARGET -- -Z unstable-options --format json --report-time | $CARGO_HOME/bin/cargo2junit > report.xml
2022-05-05 19:13:23 +02:00
artifacts:
when: always
reports:
junit:
- report.xml
only:
- main
- development
- merge_requests
2022-05-05 19:13:23 +02:00
# Run unit tests
unit test 1:3:
2022-05-05 19:13:23 +02:00
variables:
TEST_TARGET: "--lib"
extends: .tests
unit test 2:3:
2022-05-05 19:13:23 +02:00
variables:
TEST_TARGET: "--bins"
extends: .tests
unit test 3:3:
2022-05-05 19:13:23 +02:00
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"
2020-10-06 14:43:40 +02:00
build:docker-releases:
2022-05-05 19:13:23 +02:00
stage: dockerify
2020-10-06 14:43:40 +02:00
image:
2021-09-19 18:30:14 +02:00
name: gcr.io/kaniko-project/executor:v1.6.0-debug
2020-10-06 14:43:40 +02:00
entrypoint: [""]
2020-10-06 15:28:10 +02:00
before_script:
- ''
2020-10-06 14:43:40 +02:00
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
2021-09-19 18:30:14 +02:00
- /kaniko/executor --force --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
2022-05-05 19:13:23 +02:00
rules:
- if: $CI_COMMIT_TAG =~ "release/.*"
when: never
2020-10-06 14:43:40 +02:00
build:docker-development:
2022-05-05 19:13:23 +02:00
stage: dockerify
2020-10-06 14:43:40 +02:00
image:
2021-09-19 18:30:14 +02:00
name: gcr.io/kaniko-project/executor:v1.6.0-debug
2020-10-06 14:43:40 +02:00
entrypoint: [""]
2020-10-06 15:28:10 +02:00
before_script:
- ''
2020-10-06 14:43:40 +02:00
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
2021-09-19 18:30:14 +02:00
- /kaniko/executor --force --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:dev-latest
2020-10-06 14:43:40 +02:00
only:
- development