Skip to content

Commit a729da9

Browse files
chore: adds contributing.md to xtask prep
1 parent 481bb29 commit a729da9

File tree

4 files changed

+234
-68
lines changed

4 files changed

+234
-68
lines changed

CONTRIBUTING.md

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to rover
1+
# Contributing to Rover
22

33
> Rover is a project by [Apollo GraphQL] and is not currently ready for
44
> external feature contributors, though some documentation contributions may be
@@ -12,27 +12,55 @@ Rust installed. To install Rust, visit [https://www.rust-lang.org/tools/install]
1212
Rust has a build tool and package manager called [`cargo`] that you'll use to
1313
interact with Rover's code.
1414

15+
## Workflows
16+
1517
To build the CLI:
1618
```bash
1719
cargo build
1820
```
1921

20-
To run the CLI:
22+
To build and run the CLI with a set of arguments:
2123
```bash
2224
cargo run -- <args>
23-
# e.g. 'cargo run -- help' will run the rover help command
2425
```
2526

26-
You can also install Rover to your local PATH from source with cargo by first
27-
cloning this repository, and then building the CLI:
27+
e.g. To build and run `rover supergraph compose`:
28+
2829
```bash
29-
cargo build
30+
cargo run -- supergraph compose --config config.yaml
3031
```
3132

32-
And then running cargo with `install` argument:
33+
You can also install Rover to your local PATH from source with cargo by first
34+
cloning this repository, and then running:
3335
```bash
3436
cargo run -- install
3537
```
38+
39+
To run tests:
40+
```bash
41+
cargo test --workspace
42+
```
43+
44+
To format your code:
45+
```bash
46+
cargo fmt --all
47+
```
48+
49+
To lint your code:
50+
```bash
51+
cargo clippy
52+
```
53+
54+
To run the lint checker that is run in CI:
55+
```bash
56+
cargo xtask lint
57+
```
58+
59+
To run the tests that are run in CI:
60+
```bash
61+
cargo xtask test
62+
```
63+
3664
[Apollo GraphQL]: https://www.apollographql.com
3765
[Rust]: https://www.rust-lang.org/
3866
[`cargo`]: https://doc.rust-lang.org/cargo/index.html
@@ -73,9 +101,7 @@ npm start
73101

74102
This will start up a development server with live reload enabled. You can see the docs by opening [localhost:8000](http://localhost:8000) in your browser.
75103

76-
To see how the sidebar is built and how pages are grouped and named, see [this section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#sidebarcategories) of the gatsby-theme-apollo-docs docs. There is also a [creating pages section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#creating-pages) if you're interesed in adding new pages.
77-
=======
78-
For info on how to contribute to Rover, see the [docs](https://go.apollo.dev/r/contributing).
104+
To see how the sidebar is built and how pages are grouped and named, see [this section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#sidebarcategories) of the gatsby-theme-apollo-docs docs. There is also a [creating pages section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#creating-pages) if you're interested in adding new pages.
79105

80106
## Code of Conduct
81107
The project has a [Code of Conduct] that *all* contributors are expected to

crates/xtask/src/commands/prep/docs.rs

+96-50
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,111 @@ use std::{convert::TryFrom, fs};
55

66
use crate::utils;
77

8-
pub(crate) fn build_error_code_reference() -> Result<()> {
9-
utils::info("updating error reference material.");
10-
let project_root = utils::project_root()?;
11-
let docs_path = project_root.join("docs").join("source").join("errors.md");
12-
let codes_dir = project_root
13-
.join("src")
14-
.join("error")
15-
.join("metadata")
16-
.join("codes");
17-
18-
// sort code files alphabetically
19-
let raw_code_files = fs::read_dir(&codes_dir)?;
20-
21-
let mut code_files = Vec::new();
22-
for raw_code_file in raw_code_files {
23-
let raw_code_file = raw_code_file?;
24-
if raw_code_file.file_type()?.is_dir() {
25-
return Err(anyhow!("Error code directory {} contains a directory {:?}. It must only contain markdown files.", &codes_dir, raw_code_file.file_name()));
26-
} else {
27-
code_files.push(raw_code_file);
28-
}
8+
pub(crate) struct DocsRunner {
9+
pub(crate) project_root: Utf8PathBuf,
10+
pub(crate) docs_root: Utf8PathBuf,
11+
}
12+
13+
impl DocsRunner {
14+
pub(crate) fn new() -> Result<Self> {
15+
let project_root = utils::project_root()?;
16+
let docs_root = project_root.join("docs");
17+
Ok(Self {
18+
project_root,
19+
docs_root,
20+
})
2921
}
30-
code_files.sort_by_key(|f| f.path());
3122

32-
let mut all_descriptions = String::new();
23+
pub(crate) fn build_error_code_reference(&self) -> Result<()> {
24+
utils::info("updating error reference material.");
25+
let docs_path = &self.docs_root.join("source").join("errors.md");
26+
let codes_dir = &self
27+
.project_root
28+
.join("src")
29+
.join("error")
30+
.join("metadata")
31+
.join("codes");
3332

34-
// for each code description, get the name of the code from the filename,
35-
// and add it as a header. Then push the header and description to the
36-
// all_descriptions string
37-
for code in code_files {
38-
let path = Utf8PathBuf::try_from(code.path())?;
33+
// sort code files alphabetically
34+
let raw_code_files = fs::read_dir(&codes_dir)?;
3935

40-
let contents = fs::read_to_string(&path)?;
41-
let code_name = path
42-
.file_name()
43-
.ok_or_else(|| anyhow!("Path {} doesn't have a file name", &path))?
44-
.replace(".md", "");
36+
let mut code_files = Vec::new();
37+
for raw_code_file in raw_code_files {
38+
let raw_code_file = raw_code_file?;
39+
if raw_code_file.file_type()?.is_dir() {
40+
return Err(anyhow!("Error code directory {} contains a directory {:?}. It must only contain markdown files.", &codes_dir, raw_code_file.file_name()));
41+
} else {
42+
code_files.push(raw_code_file);
43+
}
44+
}
45+
code_files.sort_by_key(|f| f.path());
4546

46-
let description = format!("### {}\n\n{}\n\n", code_name, contents);
47+
let mut all_descriptions = String::new();
4748

48-
all_descriptions.push_str(&description);
49-
}
49+
// for each code description, get the name of the code from the filename,
50+
// and add it as a header. Then push the header and description to the
51+
// all_descriptions string
52+
for code in code_files {
53+
let path = Utf8PathBuf::try_from(code.path())?;
54+
55+
let contents = fs::read_to_string(&path)?;
56+
let code_name = path
57+
.file_name()
58+
.ok_or_else(|| anyhow!("Path {} doesn't have a file name", &path))?
59+
.replace(".md", "");
60+
61+
let description = format!("### {}\n\n{}\n\n", code_name, contents);
5062

51-
let docs_content = fs::read_to_string(&docs_path)
52-
.with_context(|| format!("Could not read contents of {} to a String", &docs_path))?;
53-
54-
// build up a new docs page with existing content line-by-line
55-
// and then concat the loaded code descriptions after
56-
let mut new_content = String::new();
57-
for line in docs_content.lines() {
58-
new_content.push_str(line);
59-
new_content.push('\n');
60-
if line.contains("<!-- BUILD_CODES -->") {
61-
break;
63+
all_descriptions.push_str(&description);
6264
}
65+
66+
self.replace_content_after_token("<!-- BUILD_CODES -->", &all_descriptions, &docs_path)
6367
}
64-
new_content.push_str(&all_descriptions);
6568

66-
fs::write(&docs_path, new_content)?;
69+
pub(crate) fn copy_contributing(&self) -> Result<()> {
70+
utils::info("updating contributing.md");
71+
72+
let source_path = self.project_root.join("CONTRIBUTING.md");
73+
let destination_path = self.docs_root.join("source").join("contributing.md");
74+
75+
let source_content_with_header = fs::read_to_string(&source_path)
76+
.with_context(|| format!("Could not read contents of {} to a String", &source_path))?;
77+
// Don't include the first header and the empty newline after it.
78+
let source_content = source_content_with_header
79+
.splitn(3, '\n')
80+
.collect::<Vec<&str>>()[2];
81+
self.replace_content_after_token(
82+
"<!-- CONTRIBUTING -->",
83+
&source_content,
84+
&destination_path,
85+
)
86+
}
6787

68-
Ok(())
88+
fn replace_content_after_token(
89+
&self,
90+
html_comment_token: &str,
91+
source_content: &str,
92+
destination_path: &Utf8PathBuf,
93+
) -> Result<()> {
94+
// build up a new docs page with existing content line-by-line
95+
// and then concat the replacement content
96+
let destination_content = fs::read_to_string(&destination_path).with_context(|| {
97+
format!(
98+
"Could not read contents of {} to a String",
99+
&destination_path
100+
)
101+
})?;
102+
let mut new_content = String::new();
103+
for line in destination_content.lines() {
104+
new_content.push_str(line);
105+
new_content.push('\n');
106+
if line.contains(html_comment_token) {
107+
break;
108+
}
109+
}
110+
new_content.push_str(&source_content);
111+
112+
fs::write(&destination_path, new_content)?;
113+
Ok(())
114+
}
69115
}

crates/xtask/src/commands/prep/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ mod docs;
22
mod installers;
33
mod npm;
44

5-
use anyhow::Result;
5+
use anyhow::{Context, Result};
66
use structopt::StructOpt;
77

8+
use crate::commands::prep::docs::DocsRunner;
9+
810
#[derive(Debug, StructOpt)]
911
pub struct Prep {}
1012

1113
impl Prep {
1214
pub fn run(&self, verbose: bool) -> Result<()> {
1315
npm::prepare_package(verbose)?;
1416
installers::update_versions()?;
15-
docs::build_error_code_reference()
17+
let docs_runner = DocsRunner::new()?;
18+
docs_runner
19+
.build_error_code_reference()
20+
.with_context(|| "Could not build error code reference")?;
21+
docs_runner
22+
.copy_contributing()
23+
.with_context(|| "Could not update contributing.md in the docs.")?;
24+
Ok(())
1625
}
1726
}

docs/source/contributing.md

+91-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ title: "Contributing to Rover"
33
sidebar_title: "Contributing"
44
---
55

6-
> Rover is not yet ready for external feature contributors, but [documentation contributions](#documentation) are welcome. At this time, this article is intended primarily for internal contributors and partners.
6+
<!-- DO NOT EDIT BELOW THIS LINE. THE FOLLOWING IS ALL AUTOGENERATED IN `cargo xtask prep` -->
7+
<!-- CONTRIBUTING -->
8+
> Rover is a project by [Apollo GraphQL] and is not currently ready for
9+
> external feature contributors, though some documentation contributions may be
10+
> accepted.
711
812
## Prerequisites
913

@@ -13,17 +17,56 @@ Rust installed. To install Rust, visit [https://www.rust-lang.org/tools/install]
1317
Rust has a build tool and package manager called [`cargo`] that you'll use to
1418
interact with Rover's code.
1519

20+
## Workflows
21+
1622
To build the CLI:
17-
```
23+
```bash
1824
cargo build
1925
```
2026

21-
To run the CLI:
22-
```
27+
To build and run the CLI with a set of arguments:
28+
```bash
2329
cargo run -- <args>
24-
# e.g. cargo run -- help will run the rover help command
2530
```
2631

32+
e.g. To build and run `rover supergraph compose`:
33+
34+
```bash
35+
cargo run -- supergraph compose --config config.yaml
36+
```
37+
38+
You can also install Rover to your local PATH from source with cargo by first
39+
cloning this repository, and then running:
40+
```bash
41+
cargo run -- install
42+
```
43+
44+
To run tests:
45+
```bash
46+
cargo test --workspace
47+
```
48+
49+
To format your code:
50+
```bash
51+
cargo fmt --all
52+
```
53+
54+
To lint your code:
55+
```bash
56+
cargo clippy
57+
```
58+
59+
To run the lint checker that is run in CI:
60+
```bash
61+
cargo xtask lint
62+
```
63+
64+
To run the tests that are run in CI:
65+
```bash
66+
cargo xtask test
67+
```
68+
69+
[Apollo GraphQL]: https://www.apollographql.com
2770
[Rust]: https://www.rust-lang.org/
2871
[`cargo`]: https://doc.rust-lang.org/cargo/index.html
2972
[https://www.rust-lang.org/tools/install]: https://www.rust-lang.org/tools/install
@@ -63,4 +106,46 @@ npm start
63106

64107
This will start up a development server with live reload enabled. You can see the docs by opening [localhost:8000](http://localhost:8000) in your browser.
65108

66-
To see how the sidebar is built and how pages are grouped and named, see [this section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#sidebarcategories) of the gatsby-theme-apollo-docs docs. There is also a [creating pages section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#creating-pages) if you're interesed in adding new pages.
109+
To see how the sidebar is built and how pages are grouped and named, see [this section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#sidebarcategories) of the gatsby-theme-apollo-docs docs. There is also a [creating pages section](https://github.com/apollographql/gatsby-theme-apollo/tree/master/packages/gatsby-theme-apollo-docs#creating-pages) if you're interested in adding new pages.
110+
111+
## Code of Conduct
112+
The project has a [Code of Conduct] that *all* contributors are expected to
113+
follow. This code describes the *minimum* behavior expectations for all
114+
contributors.
115+
116+
As a contributor, how you choose to act and interact towards your fellow
117+
contributors, as well as to the community, will reflect back not only on
118+
yourself but on the project as a whole. The Code of Conduct is designed and
119+
intended, above all else, to help establish a culture within the project that
120+
allows anyone and everyone who wants to contribute to feel safe doing so.
121+
122+
Should any individual act in any way that is considered in violation of the
123+
[Code of Conduct], corrective actions will be taken. It is possible, however,
124+
for any individual to *act* in such a manner that is not in violation of the
125+
strict letter of the Code of Conduct guidelines while still going completely
126+
against the spirit of what that Code is intended to accomplish.
127+
128+
Open, diverse, and inclusive communities live and die on the basis of trust.
129+
Contributors can disagree with one another so long as they trust that those
130+
disagreements are in good faith and everyone is working towards a common goal.
131+
132+
## Bad Actors
133+
All contributors to tacitly agree to abide by both the letter and spirit of the
134+
[Code of Conduct]. Failure, or unwillingness, to do so will result in
135+
contributions being respectfully declined.
136+
137+
A *bad actor* is someone who repeatedly violates the *spirit* of the Code of
138+
Conduct through consistent failure to self-regulate the way in which they
139+
interact with other contributors in the project. In doing so, bad actors
140+
alienate other contributors, discourage collaboration, and generally reflect
141+
poorly on the project as a whole.
142+
143+
Being a bad actor may be intentional or unintentional. Typically, unintentional
144+
bad behavior can be easily corrected by being quick to apologize and correct
145+
course *even if you are not entirely convinced you need to*. Giving other
146+
contributors the benefit of the doubt and having a sincere willingness to admit
147+
that you *might* be wrong is critical for any successful open collaboration.
148+
149+
Don't be a bad actor.
150+
151+
[Code of Conduct]: https://github.com/apollographql/.github/blob/main/CODE_OF_CONDUCT.md

0 commit comments

Comments
 (0)