ci: Add test and test-features xtask commands

This commit is contained in:
Jonas Platte
2022-03-03 18:40:05 +01:00
parent b64d855b25
commit 804c8e6c43
2 changed files with 77 additions and 37 deletions

View File

@@ -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 }}

View File

@@ -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<FeatureSet>,
},
}
#[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<FeatureSet>) -> 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<PathBuf> {
#[derive(Deserialize)]
struct Metadata {