Skip to content

Commit

Permalink
new: Support custom project metadata. (#1573)
Browse files Browse the repository at this point in the history
* Add field.

* Add tests.

* Update docs.

* Bump version.

* Bump version.
  • Loading branch information
milesj authored Jul 21, 2024
1 parent f9c985c commit fd4e488
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 24 deletions.
23 changes: 15 additions & 8 deletions .yarn/versions/879a5309.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
releases:
"@moonrepo/cli": patch
"@moonrepo/core-linux-arm64-gnu": patch
"@moonrepo/core-linux-arm64-musl": patch
"@moonrepo/core-linux-x64-gnu": patch
"@moonrepo/core-linux-x64-musl": patch
"@moonrepo/core-macos-arm64": patch
"@moonrepo/core-macos-x64": patch
"@moonrepo/core-windows-x64-msvc": patch
'@moonrepo/cli': patch
'@moonrepo/core-linux-arm64-gnu': patch
'@moonrepo/core-linux-arm64-musl': patch
'@moonrepo/core-linux-x64-gnu': patch
'@moonrepo/core-linux-x64-musl': patch
'@moonrepo/core-macos-arm64': patch
'@moonrepo/core-macos-x64': patch
'@moonrepo/core-windows-x64-msvc': patch
'@moonrepo/types': patch

declined:
- '@moonrepo/nx-compat'
- '@moonrepo/report'
- '@moonrepo/runtime'
- website
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

#### 🚀 Updates

- Added `project.metadata` to `moon.yml` so that custom fields can be defined.

#### 🐞 Fixes

- Fixed an issue where the new action pipeline wouldn't wait for in-flight moonbase (remote caching)
Expand Down
15 changes: 0 additions & 15 deletions crates/cli/tests/run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,6 @@ mod configs {

assert!(predicate::str::contains("tasks: invalid type: integer `123`").eval(&output));
}

#[test]
fn bubbles_up_invalid_project_config() {
let sandbox = cases_sandbox();

sandbox.create_file("base/moon.yml", "project:\n type: library");

let assert = sandbox.run_moon(|cmd| {
cmd.arg("run").arg("base:noop");
});

let output = assert.output();

assert!(predicate::str::contains("project.type: unknown field `type`").eval(&output));
}
}

mod logs {
Expand Down
3 changes: 3 additions & 0 deletions crates/config/src/project_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ cacheable!(
/// Must start with a `#`.
#[setting(validate = validate_channel)]
pub channel: Option<String>,

/// Custom metadata fields.
pub metadata: FxHashMap<String, serde_json::Value>,
}
);

Expand Down
26 changes: 26 additions & 0 deletions crates/config/tests/project_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ owners:

mod project {
use super::*;
use serde_json::Value;

#[test]
#[should_panic(expected = "must not be empty")]
Expand Down Expand Up @@ -472,6 +473,31 @@ project:
assert_eq!(meta.channel.unwrap(), "#abc");
}

#[test]
fn can_set_custom_fields() {
let config = test_load_config(
CONFIG_PROJECT_FILENAME,
r"
project:
description: 'Test'
metadata:
bool: true
string: 'abc'
",
|path| ProjectConfig::load_from(path, "."),
);

let meta = config.project.unwrap();

assert_eq!(
meta.metadata,
FxHashMap::from_iter([
("bool".into(), Value::Bool(true)),
("string".into(), Value::String("abc".into())),
])
);
}

#[test]
#[should_panic(expected = "must start with a `#`")]
fn errors_if_channel_no_hash() {
Expand Down
6 changes: 5 additions & 1 deletion packages/types/src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

/* eslint-disable */

import type { PartialTaskConfig, PlatformType, TaskConfig } from './tasks-config';
import type { UnresolvedVersionSpec } from './toolchain-config';
import type { PartialTaskConfig, PlatformType, TaskConfig } from './tasks-config';

/** The scope and or relationship of the dependency. */
export type DependencyScope = 'build' | 'development' | 'peer' | 'production' | 'root';
Expand Down Expand Up @@ -120,6 +120,8 @@ export interface ProjectMetadataConfig {
description: string;
/** The individual maintainers of the project. The format is unspecified. */
maintainers: string[];
/** Custom metadata fields. */
metadata: Record<string, unknown>;
/** A human-readable name of the project. */
name: string | null;
/**
Expand Down Expand Up @@ -361,6 +363,8 @@ export interface PartialProjectMetadataConfig {
description?: string | null;
/** The individual maintainers of the project. The format is unspecified. */
maintainers?: string[] | null;
/** Custom metadata fields. */
metadata?: Record<string, unknown> | null;
/** A human-readable name of the project. */
name?: string | null;
/**
Expand Down
13 changes: 13 additions & 0 deletions website/docs/config/project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ is the kind of information search engines would index on.
A list of people/developers that maintain the project, review code changes, and can provide support.
Can be a name, email, LDAP name, GitHub username, etc, the choice is yours.

### `metadata`<VersionLabel version="1.27.0" />

<HeadingApiLink to="/api/types/interface/ProjectMetadataConfig#metadata" />

A map of custom metadata to associate to this project. Supports all value types that are valid JSON.

```yaml title="moon.yml"
project:
# ...
metadata:
deprecated: true
```

### `name`

<HeadingApiLink to="/api/types/interface/ProjectMetadataConfig#name" />
Expand Down
18 changes: 18 additions & 0 deletions website/static/schemas/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,24 @@
"type": "string"
}
},
"metadata": {
"title": "metadata",
"description": "Custom metadata fields.",
"type": "object",
"additionalProperties": {
"type": [
"boolean",
"object",
"array",
"number",
"string",
"integer"
]
},
"propertyNames": {
"type": "string"
}
},
"name": {
"title": "name",
"description": "A human-readable name of the project.",
Expand Down

0 comments on commit fd4e488

Please sign in to comment.