From e781736ffa83e17984172fc0873864cc2dae7e43 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 22 Aug 2024 07:51:16 +0200 Subject: [PATCH] feat: single stage ci with tests, clippy and fmt check all in one --- .gitlab-ci.yml | 47 +-------------------------------- dist/appimage/build_appimage.sh | 1 + src/main.rs | 1 + src/meson.build | 23 +++++++++++++++- 4 files changed, 25 insertions(+), 47 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6eb8f0f..f947193 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,52 +13,6 @@ commitcheck: # only run for merge requests - if [ -z "$CI_MERGE_REQUEST_TITLTE" ]; then true; else python ./dist/tagging/check_conventional_commit.py "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"; fi -cargo:fmtcheck: - image: "rust:slim" - stage: check - script: - - rustup component add rustfmt - # Create blank versions of our configured files - # so rustfmt does not yell about non-existent files or completely empty files - - echo -e "" >> src/constants.rs - - rustc -Vv && cargo -Vv - - cargo fmt --version - - cargo fmt --all -- --check - -cargo:clippy: - stage: check - variables: - RUSTFLAGS: "-Dwarnings" - script: - - apt-get update - - apt-get install libgtk-4-dev libadwaita-1-dev libssl-dev libjxl-dev libvte-2.91-gtk4-dev meson ninja-build git desktop-file-utils gettext file libusb-dev libusb-1.0-0-dev libopenxr-dev curl -y - - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup.sh - - chmod +x /tmp/rustup.sh - - /tmp/rustup.sh -y - - source "$HOME/.cargo/env" - - rustup component add clippy - - rustc -Vv && cargo -Vv - - cp src/constants.rs.in src/constants.rs - - cargo clippy --version - - cargo clippy --all-targets --all-features - -cargo:test: - stage: check - script: - - apt-get update - - apt-get install libgtk-4-dev libadwaita-1-dev libssl-dev libjxl-dev libvte-2.91-gtk4-dev meson ninja-build git desktop-file-utils gettext file libusb-dev libusb-1.0-0-dev libopenxr-dev curl -y - - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup.sh - - chmod +x /tmp/rustup.sh - - /tmp/rustup.sh -y - - source "$HOME/.cargo/env" - - rustc --version && cargo --version # Print version info for debugging - - meson setup build -Dprefix="$PWD/build/localprefix" -Dprofile=development - - ninja -C build - - cargo test --workspace --verbose - cache: - paths: - - /var/cache/apt - appimage: stage: deploy script: @@ -68,6 +22,7 @@ appimage: - chmod +x /tmp/rustup.sh - /tmp/rustup.sh -y - source "$HOME/.cargo/env" + - rustup component add clippy - bash ./dist/appimage/build_appimage.sh artifacts: paths: diff --git a/dist/appimage/build_appimage.sh b/dist/appimage/build_appimage.sh index 510cd7d..14dcbf7 100755 --- a/dist/appimage/build_appimage.sh +++ b/dist/appimage/build_appimage.sh @@ -8,6 +8,7 @@ if [[ ! -f Cargo.toml ]]; then fi meson setup appimage_build -Dprefix=/usr -Dprofile=default +meson test -C appimage_build --print-errorlogs DESTDIR="$PWD/AppDir" ninja -C appimage_build install curl -SsLO https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage chmod +x linuxdeploy-x86_64.AppImage diff --git a/src/main.rs b/src/main.rs index 4453911..41494cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ pub mod build_tools; pub mod builders; pub mod cmd_runner; pub mod config; +#[rustfmt::skip] pub mod constants; pub mod depcheck; pub mod device_prober; diff --git a/src/meson.build b/src/meson.build index 133b83f..9d4cce9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,7 +3,7 @@ config = configure_file( output: 'constants.rs', configuration: global_conf ) -# Copy the config.rs output to the source directory. +# Copy the constants.rs output to the source directory. run_command( 'cp', meson.project_build_root() / 'src' / 'constants.rs', @@ -43,3 +43,24 @@ cargo_build = custom_target( 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@', ] ) + +test( + 'cargo-fmt-check', + cargo, + args: ['fmt', '--all', '--check'] +) + +test( + 'cargo-clippy', + cargo, + env: ['RUSTFLAGS=-Dwarnings'], + args: ['clippy', '--all-targets', '--all-features'], + timeout: 0, +) + +test( + 'cargo-test', + cargo, + args: ['test'], + timeout: 0, +)