Skip to content

Commit

Permalink
new: Add --report support to moon check. (#377)
Browse files Browse the repository at this point in the history
* Add report arg.

* Add tests.
  • Loading branch information
milesj committed Oct 20, 2022
1 parent 29be2fd commit 3e4355e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
3 changes: 3 additions & 0 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ pub enum Commands {
Check {
#[arg(help = "List of project IDs to explicitly check")]
ids: Vec<ProjectID>,

#[arg(long, help = "Generate a run report for the current actions")]
report: bool,
},

// moon ci
Expand Down
20 changes: 18 additions & 2 deletions crates/cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ use crate::helpers::load_workspace;
use moon_project::Project;
use std::env;

pub async fn check(project_ids: &Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
#[derive(Default)]
pub struct CheckOptions {
pub report: bool,
}

pub async fn check(
project_ids: &Vec<String>,
options: CheckOptions,
) -> Result<(), Box<dyn std::error::Error>> {
let workspace = load_workspace().await?;
let mut projects: Vec<Project> = vec![];

Expand All @@ -28,7 +36,15 @@ pub async fn check(project_ids: &Vec<String>) -> Result<(), Box<dyn std::error::
}

// Run targets using our run command
run(&targets, RunOptions::default(), Some(workspace)).await?;
run(
&targets,
RunOptions {
report: options.report,
..RunOptions::default()
},
Some(workspace),
)
.await?;

Ok(())
}
4 changes: 2 additions & 2 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod helpers;
pub mod queries;

use crate::commands::bin::bin;
use crate::commands::check::check;
use crate::commands::check::{check, CheckOptions};
use crate::commands::ci::{ci, CiOptions};
use crate::commands::clean::{clean, CleanOptions};
use crate::commands::dep_graph::dep_graph;
Expand Down Expand Up @@ -80,7 +80,7 @@ pub async fn run_cli() {
})
.await
}
Commands::Check { ids } => check(ids).await,
Commands::Check { ids, report } => check(ids, CheckOptions { report: *report }).await,
Commands::Clean { lifetime } => {
clean(CleanOptions {
cache_liftime: lifetime.to_owned(),
Expand Down
29 changes: 29 additions & 0 deletions crates/cli/tests/check_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,32 @@ fn runs_tasks_from_multiple_project() {
assert!(predicate::str::contains("noop:noopWithDeps").eval(&output));
assert!(predicate::str::contains("depsA:dependencyOrder").eval(&output)); // dep of noop
}

mod reports {
use super::*;

#[test]
fn doesnt_create_a_report_by_default() {
let fixture = create_sandbox_with_git("cases");

create_moon_command(fixture.path())
.arg("check")
.arg("base")
.assert();

assert!(!fixture.path().join(".moon/cache/runReport.json").exists());
}

#[test]
fn creates_report_when_option_passed() {
let fixture = create_sandbox_with_git("cases");

create_moon_command(fixture.path())
.arg("check")
.arg("base")
.arg("--report")
.assert();

assert!(fixture.path().join(".moon/cache/runReport.json").exists());
}
}
1 change: 1 addition & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- All YAML configuration files can now use
[aliases and anchors](https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/)!
- The `moon check` command can now use the `--report` option.

##### Tasks

Expand Down
1 change: 1 addition & 0 deletions website/blog/2022-10-21_v0.17.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ full list of changes.
- Template enum variables can now define objects for their
[`values`](../docs/config/template#values).
- Task `deps` can now omit the `~:` prefix for tasks within the current project.
- The `moon check` command can now use the `--report` option.

## What's next?

Expand Down
5 changes: 5 additions & 0 deletions website/docs/commands/check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ $ moon check client server

- `[...names]` - List of project names or aliases to explicitly check, as defined in
[`projects`](../config/workspace#projects).

### Options

- `--report` - Generate a report of the ran actions. Report is written to
`.moon/cache/runReport.json`.

0 comments on commit 3e4355e

Please sign in to comment.