From 9eb65b9669a20ceb901de825c2da5f51cb91c447 Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 13 Apr 2025 19:13:24 -0400 Subject: [PATCH] feat: add a WIP ci/cd pipeline --- .gitlab-ci.yml | 217 ++++++++++++++++++----- {.forgejo => .gitlab}/workflows/rust.yml | 0 2 files changed, 173 insertions(+), 44 deletions(-) rename {.forgejo => .gitlab}/workflows/rust.yml (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c09a24d..b5a47a6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,49 +1,178 @@ -# This file is a template, and might need editing before it works on your project. -# This is a sample GitLab CI/CD configuration file that should run without any modifications. -# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, -# it uses echo commands to simulate the pipeline execution. -# -# A pipeline is composed of independent jobs that run scripts, grouped into stages. -# Stages run in sequential order, but jobs within stages run in parallel. -# -# For more information, see: https://docs.gitlab.com/ee/ci/yaml/#stages -# -# You can copy and paste this template into a new `.gitlab-ci.yml` file. -# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. -# -# To contribute improvements to CI/CD templates, please follow the Development guide at: -# https://docs.gitlab.com/development/cicd/templates/ -# This specific template is located at: -# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml +stages: + - check + - build + - test + - docker + - test-2 + - release + - deploy -stages: # List of stages for jobs, and their order of execution - - build - - test - - deploy +workflow: + rules: + - if: $CI_PIPELINE_SOURCE != 'push' || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG + when: always + - when: never -build-job: # This job runs in the build stage, which runs first. - stage: build - script: - - echo "Compiling the code..." - - echo "Compile complete." +.rust-default: + image: registry.gitlab.com/tobip64/rust-gitlab-ci:latest + cache: + - key: $CI_COMMIT_REF + paths: [ target/ ] + - key: cargo + paths: [ cargo/ ] + interruptible: true + timeout: 30m + variables: + CARGO_HOME: $CI_PROJECT_DIR/cargo + CACHE_FALLBACK_KEY: $CI_DEFAULT_BRANCH + parallel: + matrix: + - CHANNEL: [ stable ] + rules: + - if: $CHANNEL == "stable" + allow_failure: false + - allow_failure: true + before_script: + - rustup --version && rustc --version && cargo --version && echo $RUSTFLAGS && echo $CARGO_OPTS -unit-test-job: # This job runs in the test stage. - stage: test # It only starts when the job in the build stage completes successfully. - script: - - echo "Running unit tests... This will take about 60 seconds." - - sleep 60 - - echo "Code coverage is 90%" +check:clippy: + extends: .rust-default + stage: check + script: + - 'cargo +$CHANNEL clippy + --color always + --verbose + --all-targets + --all-features + --message-format=json + $CARGO_OPTS + | gitlab-report -p clippy > gl-code-quality-report.json' + artifacts: + when: always + reports: + codequality: gl-code-quality-report.json -lint-test-job: # This job also runs in the test stage. - stage: test # It can run at the same time as unit-test-job (in parallel). - script: - - echo "Linting code... This will take about 10 seconds." - - sleep 10 - - echo "No lint issues found." +check:fmt: + extends: .rust-default + stage: check + parallel: + rules: + - if: $RUN_RUST_FMT + script: + - cargo +stable fmt $CARGO_OPTS -- --check + allow_failure: true + + +build: + extends: .rust-default + stage: build + needs: [ "check:clippy" ] + timeout: 1h + parallel: + matrix: + - CHANNEL: [ stable, beta, nightly ] + PROFILE: [ debug, release ] + TARGET: + - x86_64-unknown-linux-musl + - aarch64-unknown-linux-musl + - mips64el-unknown-linux-muslabi64 + - wasm32-wasi + CARGO_OPTS: [ "--workspace --all-targets --all-features" ] + script: + - cargo +$CHANNEL build --verbose --color always --target $TARGET $([[ $PROFILE == "release" ]] && echo "--release" || echo "") $CARGO_OPTS + artifacts: + paths: + - target/$TARGET/$PROFILE/* + - Dockerfile + +# requires nightly +.build:multiarch: + extends: .rust-default + stage: build + needs: [ "check:clippy" ] + timeout: 1h + parallel: + matrix: + - CHANNEL: [ nightly ] + PROFILE: [ debug, release ] + CARGO_OPTS: [ "--workspace --all-targets --all-features" ] + script: + - '[[ $PROFILE == "debug" ]] && export RUSTFLAGS="$RUSTFLAGS -Zinstrument-coverage" || true' + - 'cargo +$CHANNEL build + $([[ $PROFILE == "release" ]] && echo "--release" || echo "") + --verbose + --color=always + --target x86_64-unknown-linux-musl + --target powerpc64le-unknown-linux-musl + --target aarch64-unknown-linux-musl + --target riscv64gc-unknown-linux-musl + --target wasm32-wasi + -Z multitarget + -Z build-std + $CARGO_OPTS' + artifacts: + paths: + - target/*/$PROFILE/* + - Dockerfile + + +test:test: + extends: .rust-default + stage: test + needs: [ build ] + script: + - 'LLVM_PROFILE_FILE="$CI_PROJECT_NAME-%p-%m.profraw" cargo +$CHANNEL test + --verbose + --color always + --workspace + --all-targets + --all-features + --no-fail-fast + -- + -Z unstable-options + --format json + $CARGO_OPTS + | gitlab-report -p test > results.xml' + after_script: + - 'grcov . + --binary-path ./target/x86_64-unknown-linux-musl/debug/ + --source-dir . + --output-type cobertura + --output-path coverage.xml + --branch + --ignore-not-existing + --ignore "/*"' + - mkdir results/ + - cp results.xml results/results.xml + - allure generate -c results/ + artifacts: + when: always + paths: + - allure-report/ + reports: + junit: results.xml +# - echo '' > public/index.html + artifacts: + paths: + - public/ +# test:bench: +# extends: .rust-default +# stage: test +# needs: [ build ] +# script: +# - 'cargo +$CHANNEL bench +# --verbose +# --color always +# --workspace +# --all-targets +# --all-features +# $CARGO_OPTS +# -- +# -Z unstable-options +# --format json +# | gitlab-report -p bench > metrics.txt' +# artifacts: +# when: always +# reports: +# metrics: metrics.txt -deploy-job: # This job runs in the deploy stage. - stage: deploy # It only runs when *both* jobs in the test stage complete successfully. - environment: production - script: - - echo "Deploying application..." - - echo "Application successfully deployed." diff --git a/.forgejo/workflows/rust.yml b/.gitlab/workflows/rust.yml similarity index 100% rename from .forgejo/workflows/rust.yml rename to .gitlab/workflows/rust.yml