mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
176 lines
4.5 KiB
YAML
176 lines
4.5 KiB
YAML
# 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
|
|
|
|
.lints:
|
|
stage: lint
|
|
allow_failure: true
|
|
only:
|
|
- merge_requests
|
|
|
|
# Use clippy lints
|
|
lint:clippy:
|
|
extends: .lints
|
|
script:
|
|
- rustup component add clippy
|
|
- cargo clippy -V
|
|
- echo -e "\e[0Ksection_start:`date +%s`:clippy_output\r\e[0Kcargo clippy output"
|
|
- cargo clippy -- --no-deps
|
|
- echo -e "\e[0Ksection_end:`date +%s`:clippy_output\r\e[0K"
|
|
|
|
# Use rustfmt to check formating
|
|
lint:fmt:
|
|
extends: .lints
|
|
script:
|
|
- rustup component add rustfmt
|
|
- cargo fmt --version
|
|
- echo -e "\e[0Ksection_start:`date +%s`:rustfmt_output\r\e[0KChanges suggested by rustfmt"
|
|
- cargo 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
|
|
only:
|
|
- main
|
|
- development
|
|
- merge_requests
|
|
script:
|
|
- rustc +stable --version && cargo --version
|
|
- echo -e "\e[0Ksection_start:`date +%s`:build_output\r\e[0KOutput of cargo check"
|
|
- cargo 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 test --verbose --no-run --workspace
|
|
- echo -e "\e[0Ksection_end:`date +%s`:build_output\r\e[0K"
|
|
- cargo install --root $CARGO_HOME cargo2junit
|
|
|
|
.tests:
|
|
stage: test
|
|
needs: ["stable:test"]
|
|
script:
|
|
- cargo test --workspace $TEST_TARGET -- -Z unstable-options --format json --report-time | $CARGO_HOME/bin/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
|