From 804c8e6c433d342964d6e45d533915281abd676e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 3 Mar 2022 18:40:05 +0100 Subject: [PATCH] ci: Add test and test-features xtask commands --- .github/workflows/ci.yml | 47 +++++++--------------------- xtask/src/ci.rs | 67 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0f6aa657..88fd21fd1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: args: -p xtask -- ci clippy test-features: - name: ${{ matrix.name }} + name: linux / features-${{ matrix.name }} if: github.event_name == 'push' || !github.event.pull_request.draft runs-on: ubuntu-latest @@ -88,39 +88,14 @@ jobs: fail-fast: true matrix: name: - - linux / features-no-encryption - - linux / features-no-sled - - linux / features-no-encryption-and-sled - - linux / features-sled_cryptostore - - linux / features-rustls-tls - - linux / features-markdown - - linux / features-socks - - linux / features-sso_login - - include: - - name: linux / features-no-encryption - cargo_args: --no-default-features --features "sled_state_store, native-tls" - - - name: linux / features-no-sled - cargo_args: --no-default-features --features "encryption, native-tls" - - - name: linux / features-no-encryption-and-sled - cargo_args: --no-default-features --features "native-tls" - - - name: linux / features-sled_cryptostore - cargo_args: --no-default-features --features "encryption, sled_cryptostore, native-tls" - - - name: linux / features-rustls-tls - cargo_args: --no-default-features --features rustls-tls - - - name: linux / features-markdown - cargo_args: --features markdown - - - name: linux / features-socks - cargo_args: --features socks - - - name: linux / features-sso_login - cargo_args: --features sso_login + - no-encryption + - no-sled + - no-encryption-and-sled + - sled-cryptostore + - rustls-tls + - markdown + - socks + - sso-login steps: - name: Checkout @@ -139,8 +114,8 @@ jobs: - name: Test uses: actions-rs/cargo@v1 with: - command: test - args: --manifest-path crates/matrix-sdk/Cargo.toml ${{ matrix.cargo_args }} + command: run + args: -p xtask -- ci test-features ${{ matrix.name }} test: name: ${{ matrix.name }} diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index e227f4c42..b1b7375d1 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -1,4 +1,4 @@ -use std::{env, path::PathBuf}; +use std::{collections::BTreeMap, env, path::PathBuf}; use clap::{Args, Subcommand}; use serde::Deserialize; @@ -22,6 +22,26 @@ enum CiCommand { Clippy, /// Check documentation Docs, + /// Run default tests + Test, + /// Run tests with a specific feature set + TestFeatures { + #[clap(subcommand)] + cmd: Option, + }, +} + +#[derive(Subcommand, PartialEq, Eq, PartialOrd, Ord)] +enum FeatureSet { + Default, + NoEncryption, + NoSled, + NoEncryptionAndSled, + SledCryptostore, + RustlsTls, + Markdown, + Socks, + SsoLogin, } impl CiArgs { @@ -34,12 +54,16 @@ impl CiArgs { CiCommand::Typos => check_typos(), CiCommand::Clippy => check_clippy(), CiCommand::Docs => check_docs(), + CiCommand::Test => run_tests(), + CiCommand::TestFeatures { cmd } => run_feature_tests(cmd), }, None => { check_style()?; check_clippy()?; check_typos()?; check_docs()?; + run_tests()?; + run_feature_tests(None)?; Ok(()) } @@ -74,6 +98,47 @@ fn check_docs() -> Result<()> { build_docs([], DenyWarnings::Yes) } +fn run_tests() -> Result<()> { + cmd!("rustup run stable cargo test").run()?; + cmd!("rustup run beta cargo test").run()?; + Ok(()) +} + +fn run_feature_tests(cmd: Option) -> Result<()> { + let args = BTreeMap::from([ + (FeatureSet::NoEncryption, "--no-default-features --features sled_state_store,native-tls"), + (FeatureSet::NoSled, "--no-default-features --features encryption,native-tls"), + (FeatureSet::NoEncryptionAndSled, "--no-default-features --features native-tls"), + ( + FeatureSet::SledCryptostore, + "--no-default-features --features encryption,sled_cryptostore,native-tls", + ), + (FeatureSet::RustlsTls, "--no-default-features --features rustls-tls"), + (FeatureSet::Markdown, "--features markdown"), + (FeatureSet::Socks, "--features socks"), + (FeatureSet::SsoLogin, "--features sso_login"), + ]); + + let run = |arg_set: &str| { + cmd!("rustup run stable cargo test --manifest-path crates/matrix-sdk/Cargo.toml") + .args(arg_set.split_whitespace()) + .run() + }; + + match cmd { + Some(cmd) => { + run(args[&cmd])?; + } + None => { + for &arg_set in args.values() { + run(arg_set)?; + } + } + } + + Ok(()) +} + fn workspace_root() -> Result { #[derive(Deserialize)] struct Metadata {