Skip to content

Commit

Permalink
docs: Add blog post and update docs. (#1035)
Browse files Browse the repository at this point in the history
* Rework query tasks affected.

* Add proto purge.

* Finish proto docs.

* Finish moon docs.

* Fix test.
  • Loading branch information
milesj committed Sep 4, 2023
1 parent 44dcd1b commit 8929970
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 94 deletions.
70 changes: 48 additions & 22 deletions crates/cli/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::enums::TouchedStatus;
pub use crate::queries::hash::query_hash;
pub use crate::queries::hash_diff::query_hash_diff;
pub use crate::queries::projects::{
query_projects, QueryProjectsOptions, QueryProjectsResult, QueryTasksResult,
load_touched_files, query_projects, QueryProjectsOptions, QueryProjectsResult, QueryTasksResult,
};
pub use crate::queries::touched_files::{
query_touched_files, QueryTouchedFilesOptions, QueryTouchedFilesResult,
Expand All @@ -12,9 +12,10 @@ use console::Term;
use miette::IntoDiagnostic;
use moon_terminal::ExtendedTerm;
use moon_workspace::Workspace;
use rustc_hash::FxHashMap;
use rustc_hash::{FxHashMap, FxHashSet};
use starbase::system;
use starbase_styles::color;
use std::collections::BTreeMap;
use std::io::{self, IsTerminal};

#[derive(Args, Clone, Debug)]
Expand Down Expand Up @@ -149,6 +150,11 @@ pub async fn projects(args: ArgsRef<QueryProjectsArgs>, workspace: ResourceMut<W
source: args.source,
tags: args.tags,
tasks: args.tasks,
touched_files: if args.affected {
load_touched_files(workspace).await?
} else {
FxHashSet::default()
},
type_of: args.type_of,
};

Expand Down Expand Up @@ -214,42 +220,62 @@ pub async fn tasks(args: ArgsRef<QueryTasksArgs>, workspace: ResourceMut<Workspa
let args = args.to_owned();
let options = QueryProjectsOptions {
alias: args.alias,
affected: args.affected,
id: args.id,
json: args.json,
language: args.language,
query: args.query,
source: args.source,
tags: None,
tasks: args.tasks,
type_of: args.type_of,
..QueryProjectsOptions::default()
};

let projects = query_projects(workspace, &options).await?;
let touched_files = if args.affected {
load_touched_files(workspace).await?
} else {
FxHashSet::default()
};

// Filter and group tasks
let mut grouped_tasks = FxHashMap::default();

for project in projects {
let filtered_tasks = project
.tasks
.iter()
.filter_map(|(task_id, task)| {
if !args.affected || task.is_affected(&touched_files).is_ok_and(|v| v) {
Some((task_id.to_owned(), task.to_owned()))
} else {
None
}
})
.collect::<BTreeMap<_, _>>();

if filtered_tasks.is_empty() {
continue;
}

grouped_tasks.insert(project.id.clone(), filtered_tasks);
}

// Write to stdout directly to avoid broken pipe panics
let term = Term::buffered_stdout();

if options.json {
let result = QueryTasksResult {
tasks: FxHashMap::from_iter(
projects
.into_iter()
.map(|p| (p.id.clone(), p.tasks.clone())),
),
options,
};

term.line(serde_json::to_string_pretty(&result).into_diagnostic()?)?;
} else if !projects.is_empty() {
for project in projects {
if project.tasks.is_empty() {
continue;
}

term.line(&project.id)?;
term.line(
serde_json::to_string_pretty(&QueryTasksResult {
tasks: grouped_tasks,
options,
})
.into_diagnostic()?,
)?;
} else if !grouped_tasks.is_empty() {
for (project_id, tasks) in grouped_tasks {
term.line(project_id)?;

for (task_id, task) in &project.tasks {
for (task_id, task) in tasks {
term.line(format!("\t:{} | {}", task_id, task.command))?;
}
}
Expand Down
12 changes: 4 additions & 8 deletions crates/cli/src/queries/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct QueryProjectsOptions {
pub source: Option<String>,
pub tags: Option<String>,
pub tasks: Option<String>,
pub touched_files: FxHashSet<WorkspaceRelativePathBuf>,
pub type_of: Option<String>,
}

Expand Down Expand Up @@ -60,7 +61,7 @@ fn convert_to_regex(field: &str, value: &Option<String>) -> AppResult<Option<reg
}
}

async fn load_touched_files(
pub async fn load_touched_files(
workspace: &Workspace,
) -> AppResult<FxHashSet<WorkspaceRelativePathBuf>> {
let mut buffer = String::new();
Expand Down Expand Up @@ -106,19 +107,14 @@ pub async fn query_projects(
debug!("Querying for projects");

let project_graph = generate_project_graph(workspace).await?;
let touched_files = if options.affected {
load_touched_files(workspace).await?
} else {
FxHashSet::default()
};

// When a MQL input is provided, it takes full precedence over option args
if let Some(query) = &options.query {
let projects = project_graph
.query(moon_query::build_query(query)?)?
.into_iter()
.filter_map(|project| {
if options.affected && !project.is_affected(&touched_files) {
if options.affected && !project.is_affected(&options.touched_files) {
return None;
}

Expand All @@ -139,7 +135,7 @@ pub async fn query_projects(
let mut projects = vec![];

for project in project_graph.get_all()? {
if options.affected && !project.is_affected(&touched_files) {
if options.affected && !project.is_affected(&options.touched_files) {
continue;
}

Expand Down
15 changes: 1 addition & 14 deletions crates/cli/tests/query_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,7 @@ mod tasks {
projects.sort();

assert_eq!(tasks, string_vec!["lint", "test"]);
assert_eq!(
projects,
string_vec![
"advanced",
"bar",
"basic",
"baz",
"emptyConfig",
"foo",
"noConfig",
"platforms",
"tasks",
]
);
assert_eq!(projects, string_vec!["platforms", "tasks"]);
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
- Tasks allowed to fail cannot be depended on.
- Added colors to command line `--help` menus.
- Updated `runner.archivableTargets` to support tag scoped targets.
- Updated proto integration from v0.13 to v0.16:
- Updated `moon query tasks` to filter out projects with no tasks.
- Updated `moon query tasks --affected` to filter based on affected task, instead of affected
project.
- Updated proto integration from v0.12 to v0.16:
- proto tools are now powered by WASM plugins, which will be downloaded by moon on-demand.
- Yarn v2+ will now download the requested version, and not downgrade to latest v1.
- Please report any issues or degradations from this migration.
- View entire [proto changelog](https://github.com/moonrepo/proto/blob/master/CHANGELOG.md#0150).
- View entire [proto changelog](https://github.com/moonrepo/proto/blob/master/CHANGELOG.md#0160).

#### 🐞 Fixes

Expand Down
46 changes: 0 additions & 46 deletions website/blog/2023-09-04_moon-v1.13.mdx

This file was deleted.

63 changes: 63 additions & 0 deletions website/blog/2023-09-04_proto-v0.16.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
slug: proto-v0.16
title: proto v0.16 - Add, remove, and purge plugins
authors: [milesj]
tags: [proto, plugin]
---

This release adds functionality for managing plugins and purging the proto store.

<!--truncate-->

## Add and remove plugins

Now that proto has fully embraced a plugin based architecture, we thought it'd be nice to support
the management of these plugins through the CLI. This release adds two new commands:
[`proto add-plugin`](/docs/proto/commands/add-plugin) and
[`proto remove-plugin`](/docs/proto/commands/remove-plugin).

Adding a plugin requires a unique ID and what we call a locator, which is a string that dictates
where to locate and download the plugin from. Here's an example for Node.js, but this isn't
necessary as it's built-in:

```shell
$ proto add-plugin node source:https://github.com/moonrepo/node-plugin/releases/latest/download/node_plugin.wasm
```

Additionally, removing a plugin is even easier.

```shell
$ proto remove-plugin node
```

## Purge tools and plugins

proto has supported cleaning for quite some time through the
[`proto clean`](/docs/proto/commands/clean) command (and the
[`auto-clean` setting](/docs/proto/config#user-configuration)), which would automatically delete
installed tool versions and temporary files that are older then a specific timeframe. This helps to
free up disk space for unused or rarely used tools.

In this release, we're expanding the `clean` command's functionality with a concept known as
purging, which will "delete entirely". The first being the new `--purge` option, which will delete a
tool, its manifest, _all_ installed versions, and the entire `~/.proto/tools/<id>` directory.

```shell
# Delete all traces of Node.js
$ proto clean --purge node
```

Additionaly, a new `--purge-plugins` option can be used to delete all downloaded plugins (the
`~/.proto/plugins` directory). Useful for house keeping or if you want to start fresh.

```shell
$ proto clean --purge-plugins
```

## Other changes

View the [official release](https://github.com/moonrepo/proto/releases/tag/v0.16.0) for a full list
of changes.

- Added folder locking during tool installation to avoid colliding processes.
- Renamed `PROTO_ROOT` to `PROTO_HOME`, but we'll support `PROTO_ROOT` for the time being.
84 changes: 84 additions & 0 deletions website/blog/2023-09-05_moon-v1.13.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
slug: moon-v1.13
title: moon v1.13 - Toolchain now uses WASM plugins
authors: [milesj]
tags: [tasks, proto, wasm]
image: ./img/moon/v1.13.png
---

This is a light release that focused primarily on upgrading to the WASM based proto implementation.

<!--truncate-->

## proto upgrade and WASM plugins

Over the last few months, we've made immense strides on [proto](/proto), our multi-language
toolchain. For those of you unaware, moon's toolchain is built on top of proto, and we accomplish
this by utilizing the same Rust code between both tools.

However, moon has been locked to [proto v0.12](/blog/proto-v0.12), which was a purely Rust based
implementation. With the release of [proto v0.13](/blog/proto-v0.13) and onward, proto has moved to
a WASM based plugin architecture (with the core still in Rust), which allows us to support more
languages, and enables developers to write plugins in non-Rust languages.

And since our WASM plugins have stabilized by [proto v0.16](/blog/proto-v0.16), we felt it was time
to finally upgrade moon's implementation to the latest and greatest. So what does this mean exactly?
A few things:

- If you're using moon's [toolchain](/docs/config/toolchain) (like `node`), we will now download the
[Node.js WASM plugins](https://github.com/moonrepo/node-plugin) in the background (to
`~/.proto/plugins`).
- These plugins are in charge of downloading and installing the Node.js, npm, pnpm, or yarn version
specified in your toolchain configuration.
- The entire plugin flow is now logged to the console, so you can see what's happening behind the
scenes.
- In the future (most likely moon v2), our platform and language integration will also be powered by
WASM plugins. This enables you to build your own custom plugins!

:::info

This entire process should be transparent to all users, and you should not notice any changes.
However, in case this upgrade causes issues, we wanted to isolate it from other changes, hence the
light release!

:::

## Allow tasks to fail

"Allow tasks to fail?" You ask yourself. "Doesn't that defeat the point of a task runner?" You
question further. "You're not wrong!" We reply. These questions assume a perfect repository state,
where all tasks either pass or fail, and there's no middle ground. In reality, very rarely is that
true, and we want to support those stuck in the middle, such as:

- In a heavy migration and it's known that a task is currently broken.
- The task is flaky but you've been unable to find the root cause.
- Upstream dependencies have published a backwards incompatible change, and you're waiting on a fix.
- And of course, in the middle of adopting moon!

For situations where a task consistently or sometimes fails, but you don't want it to fail the
entire pipeline (especially in CI), you can enable the new
[`allowFailure` task option](/docs/config/project#allowfailure).

```yaml title="moon.yml"
tasks:
typecheck:
command: 'tsc --build'
options:
allowFailure: true
```

When enabled, failing tasks will no longer bail [`moon run`](/docs/commands/run) early, nor will it
exit [`moon ci`](/docs/commands/ci) with a non-zero exit code. However, we still built guard rails
around this feature, as we don't want to encourage bad practices, and one of these guard rails is
that tasks that enable `allowFailure` _cannot_ be depended on by other tasks, as we cannot guarantee
that it's side-effect free.

## Other changes

View the [official release](https://github.com/moonrepo/moon/releases/tag/v1.13.0) for a full list
of changes.

- Added colors to command line `--help` menus.
- Updated `runner.archivableTargets` to support tag scoped targets.
- Updated `moon query tasks --affected` to filter based on affected task, instead of affected
project.
Binary file added website/blog/img/moon/v1.13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8929970

Please sign in to comment.