Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfm committed Dec 2, 2024
1 parent c1def16 commit 2decc1e
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 336 deletions.
1 change: 1 addition & 0 deletions .ci/cargo-ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anyhow = { workspace = true }
assert_fs = { workspace = true }
cargo_metadata = { workspace = true }
chrono = { workspace = true, default-features = true }
cicero = { workspace = true, features = ["commands"] }
clap = { workspace = true, features = ["derive", "string"] }
flate2 = { workspace = true }
fs-err = { workspace = true }
Expand Down
27 changes: 27 additions & 0 deletions .ci/cargo-ci/src/core/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use cicero::commands::{Cli, Crate};

pub static CARGO_BUNDLE_LICENSES: Cli = Crate::new("cargo-bundle-licenses").into_cli();

pub static CARGO_DENY: Cli = Crate::new("cargo-deny").into_cli();

pub static CARGO_SBOM: Cli = Crate::new("cargo-sbom").into_cli();

pub static CARGO_TARPAULIN: Cli = Crate::new("cargo-tarpaulin").into_cli();

pub static CROSS: Cli = Crate::new("cross")
.into_cli()
.with_base_command(&|mut command| {
command
.arg("build")
.arg("--release");
command
});

pub static DIESEL: Cli = Crate::new("diesel_cli").with_install_args(&["--no-default-features", "--features=postgres-bundled"]).into_cli();

pub static MDBOOK: Cli = Crate::new("mdbook").into_cli()
.with_crate_dependencies(&[
Crate::new("mdbook-plantuml"),
]);

pub static TRUNK: Cli = Crate::new("trunk").with_install_args(&["--locked"]).into_cli();
34 changes: 0 additions & 34 deletions .ci/cargo-ci/src/core/dependency.rs

This file was deleted.

2 changes: 1 addition & 1 deletion .ci/cargo-ci/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod commands;
pub mod constants;
pub mod dependency;
pub mod metadata;
pub mod types;
pub mod util;
37 changes: 0 additions & 37 deletions .ci/cargo-ci/src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,9 @@ use std::process::Command;
use anyhow::anyhow;

use assert_fs::assert::PathAssert;
use tracing_subscriber::fmt::format::FmtSpan;

use crate::core::dependency::Crate;
use crate::core::metadata;
use crate::core::types::Arch;

#[tracing::instrument(level = tracing::Level::TRACE)]
pub fn install_crate(install: Crate) -> crate::Result {
let cargo_metadata = metadata::cargo();

let version = cargo_metadata.workspace_metadata["ci"]["cargo-ci"][install.ident()]["version"].as_str()
.unwrap_or_else(|| panic!("No version information for crate '{}' in root Cargo.toml. Aborting installation.", install.ident()));

Command::new("cargo")
.arg("install")
.arg("--version").arg(version)
.args(install.install_command_args())
.arg(install.ident())
.run_requiring_success()
}

#[tracing::instrument]
pub fn install_toolchain(arch: Arch) -> crate::Result {
Command::new("rustup")
Expand Down Expand Up @@ -53,25 +35,6 @@ impl RunRequiringSuccess for Command {
}


pub fn init_tracing() -> crate::Result {
use tracing_subscriber::filter::{EnvFilter, LevelFilter};

let tracing_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
.from_env()?
.add_directive("h2=info".parse()?)
.add_directive("opendut=trace".parse()?);

tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_env_filter(tracing_filter)
.with_writer(std::io::stderr)
.init();
Ok(())
}


pub mod file {
use std::os::unix::fs::MetadataExt;

Expand Down
2 changes: 1 addition & 1 deletion .ci/cargo-ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum TaskCli {
}

fn main() -> crate::Result {
util::init_tracing()?;
cicero::init()?;

std::env::set_current_dir(constants::workspace_dir())?;

Expand Down
9 changes: 2 additions & 7 deletions .ci/cargo-ci/src/packages/carl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,8 @@ pub mod distribution {
}

pub mod diesel {
use std::process::Command;

use crate::core::dependency::Crate;
use crate::core::commands::DIESEL;
use crate::core::util::RunRequiringSuccess;
use crate::util;

use super::*;

Expand All @@ -363,16 +360,14 @@ pub mod diesel {
}
impl DieselCli {
pub fn handle(self) -> crate::Result {
util::install_crate(Crate::DieselCli)?;

let carl_database_dir = carl_database_dir();

assert!(
carl_database_dir.is_dir(),
"Could not find database directory in CARL, expected at {carl_database_dir:?}."
);

Command::new("diesel")
DIESEL.command()
.args(self.pass_through)
.current_dir(carl_database_dir)
.env("DATABASE_URL", "postgres://postgres:postgres@localhost/carl")
Expand Down
10 changes: 2 additions & 8 deletions .ci/cargo-ci/src/packages/edgar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ pub mod distribution {
pub mod rperf {
use crate::fs::File;
use std::path::Path;
use std::process::Command;
use flate2::read::GzDecoder;
use tar::Archive;
use crate::core::dependency::Crate;
use crate::core::util;
use crate::core::commands::CROSS;
use crate::core::util::RunRequiringSuccess;
use super::*;

Expand Down Expand Up @@ -276,11 +274,7 @@ pub mod distribution {
Ok(temp_dir_subpath)
}
fn build_rperf(target_directory: &Path, current_directory: &Path, target: Arch) -> Result<PathBuf, anyhow::Error> {
util::install_crate(Crate::Cross)?;

Command::new("cross")
.arg("build")
.arg("--release")
CROSS.command()
.arg("--all-features")
.arg("--target-dir").arg(target_directory)
.arg("--target").arg(target.triple())
Expand Down
13 changes: 5 additions & 8 deletions .ci/cargo-ci/src/packages/lea.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::core::commands::TRUNK;
use crate::fs;
use crate::Arch;
use std::path::PathBuf;
use std::process::Command;
use tracing::info;
use crate::Arch;
use crate::core::dependency::Crate;

use crate::core::types::parsing::package::PackageSelection;
use crate::Package;
use crate::util::RunRequiringSuccess;
use crate::Package;

const PACKAGE: Package = Package::Lea;

Expand Down Expand Up @@ -77,7 +76,7 @@ pub mod run {
pub fn run(pass_through: Vec<String>) -> crate::Result {
install_requirements()?;

Command::new("trunk")
TRUNK.command()
.args([
"watch",
"--release",
Expand All @@ -93,8 +92,6 @@ pub mod run {
fn install_requirements() -> crate::Result {
crate::util::install_toolchain(Arch::Wasm)?;

crate::util::install_crate(Crate::Trunk)?;

Ok(())
}

Expand All @@ -110,7 +107,7 @@ fn build_impl(out_dir: PathBuf) -> crate::Result {

fs::create_dir_all(&out_dir)?;

Command::new("trunk")
TRUNK.command()
.args([
"build",
"--release",
Expand Down
11 changes: 3 additions & 8 deletions .ci/cargo-ci/src/tasks/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::process::Command;
use std::path::PathBuf;

use crate::{constants, util, Package};
use crate::core::dependency::Crate;
use crate::{constants, Package};
use crate::core::commands::CROSS;
use crate::types::Arch;
use crate::core::types::parsing::target::TargetSelection;
use crate::util::RunRequiringSuccess;
Expand All @@ -18,12 +17,8 @@ pub struct DistributionBuildCli {

#[tracing::instrument(skip_all)]
pub fn distribution_build(package: Package, target: Arch) -> crate::Result {
util::install_crate(Crate::Cross)?;

Command::new("cross")
CROSS.command()
.args([
"build",
"--release",
"--package",
&package.ident(),
"--target-dir",
Expand Down
8 changes: 2 additions & 6 deletions .ci/cargo-ci/src/tasks/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::fs;
use std::path::PathBuf;
use std::process::Command;

use tracing::{debug, info, warn};

use crate::core::commands::CARGO_TARPAULIN;
use crate::core::constants;
use crate::core::dependency::Crate;
use crate::core::util::RunRequiringSuccess;

/// Generate a unit test coverage report
Expand All @@ -21,14 +19,12 @@ impl CoverageCli {

#[tracing::instrument]
pub fn coverage() -> crate::Result {
crate::util::install_crate(Crate::CargoTarpaulin)?;

clean()?;

let out_dir = out_dir();
fs::create_dir_all(&out_dir)?;

Command::new("cargo-tarpaulin")
CARGO_TARPAULIN.command()
.args([
"--verbose",
"--all-features",
Expand Down
14 changes: 3 additions & 11 deletions .ci/cargo-ci/src/tasks/doc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::fs;
use std::path::PathBuf;
use std::process::Command;

use tracing::info;

use crate::core::dependency::Crate;
use crate::util;
use crate::util::RunRequiringSuccess;

/// Access or build the documentation
Expand Down Expand Up @@ -63,14 +60,12 @@ impl DocCli {
}

pub mod book {
use crate::core::commands::MDBOOK;
use super::*;

#[tracing::instrument]
pub fn open() -> crate::Result {
util::install_crate(Crate::Mdbook)?;
util::install_crate(Crate::MdbookPlantuml)?;

Command::new("mdbook")
MDBOOK.command()
.arg("serve")
.arg("--open")
.arg("--port=4000")
Expand All @@ -82,12 +77,9 @@ pub mod book {

#[tracing::instrument]
pub fn build() -> crate::Result {
util::install_crate(Crate::Mdbook)?;
util::install_crate(Crate::MdbookPlantuml)?;

let out_dir = out_dir();

Command::new("mdbook")
MDBOOK.command()
.arg("build")
.arg("--dest-dir").arg(&out_dir)
.current_dir(doc_dir())
Expand Down
Loading

0 comments on commit 2decc1e

Please sign in to comment.