Skip to content

Commit

Permalink
Add user-docs to ci checks
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Jul 2, 2024
1 parent b3e944d commit 2c29827
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ To get quick help, use the cli like this:
``` :renku-cli
renku-cli --help
```


## Content

- [Clone a project](./project/clone)
8 changes: 8 additions & 0 deletions docs/project/clone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Clone a project

The `clone` sub command allows to clone a project to your local hard drive.

Available options are:
``` :renku-cli
renku-cli project clone --help
```
9 changes: 8 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
docSrc = ./docs;

fenixToolChain = fenix.packages.${system}.complete;

Expand Down Expand Up @@ -99,14 +100,20 @@
my-crate-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
cargoClippyExtraArgs = "--features user-doc --all-targets -- --deny warnings";
});

my-crate-doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});

my-user-docs = craneLib.mkCargoDerivation (commonArgs // {
inherit cargoArtifacts;
pnameSuffix = "-userdocs";
buildPhaseCargoCommand = "cargoWithProfile run --features user-doc -- user-doc ${docSrc}";
});

# Check formatting
my-crate-fmt = craneLib.cargoFmt {
inherit src;
Expand Down
3 changes: 3 additions & 0 deletions mkdocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cargo run --features user-doc -- user-doc --output-dir target/docs --overwrite docs/
23 changes: 10 additions & 13 deletions src/cli/cmd/userdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ impl Input {
None => myself.as_path(),
};
let walk = file_util::visit_entries(self.files.iter())
.try_filter(|p| future::ready(Self::path_match(&p.entry, &md_regex)));
.try_filter(|p| future::ready(Self::path_match(&p.entry, md_regex)));
walk.map_err(|source| Error::ListDir { source })
.try_for_each_concurrent(10, |entry| async move {
eprint!("Processing {} …\n", entry);
eprintln!("Processing {} …", entry);
let result = process_markdown_file(
&entry.entry,
&bin,
bin,
&self.result_marker,
&self.code_marker,
)
Expand All @@ -150,10 +150,10 @@ impl Input {
println!("{}", result);
}
OutputOption::OutFile(f) => {
write_to_file(&f, &result, self.overwrite)?;
write_to_file(f, &result, self.overwrite)?;
}
OutputOption::OutDir(f) => {
write_to_dir(&entry, &f, &result, self.overwrite)?;
write_to_dir(&entry, f, &result, self.overwrite)?;
}
}
Ok(())
Expand All @@ -162,7 +162,7 @@ impl Input {
Ok(())
}

fn path_match(p: &PathBuf, regex: &Regex) -> bool {
fn path_match(p: &Path, regex: &Regex) -> bool {
match p.file_name().and_then(|n| n.to_str()) {
Some(name) => regex.is_match(name),
None => false,
Expand All @@ -178,12 +178,9 @@ fn write_to_dir(
) -> Result<(), Error> {
let out = target.join(entry.sub_path().context(PathPrefixSnafu)?);
log::debug!("Writing {} docs to {}", entry, out.display());
match out.parent() {
Some(p) => {
log::debug!("Ensuring directory: {}", p.display());
std::fs::create_dir_all(p).context(CreateDirSnafu)?
}
None => (),
if let Some(p) = out.parent() {
log::debug!("Ensuring directory: {}", p.display());
std::fs::create_dir_all(p).context(CreateDirSnafu)?
}
write_to_file(&out, content, overwrite)?;
Ok(())
Expand Down Expand Up @@ -230,7 +227,7 @@ async fn process_markdown_file(
let cli_out = run_cli_command(cli_binary, command)?;
let nn = src_nodes.alloc(AstNode::new(RefCell::new(Ast::new(
make_code_block(result_marker, cli_out),
node_data.sourcepos.end.clone(),
node_data.sourcepos.end,
))));
node.insert_after(nn);
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl PathEntry {
/// Visits all entries of the given paths recursively using tokios
/// async read_dir while returning with every entry the root element
/// it was queried for (member of the initially passed in `paths`).
pub fn visit_entries<'a, I, P>(paths: I) -> impl Stream<Item = io::Result<PathEntry>>
pub fn visit_entries<I, P>(paths: I) -> impl Stream<Item = io::Result<PathEntry>>
where
P: Into<PathBuf>,
I: IntoIterator<Item = P>,
Expand All @@ -56,7 +56,7 @@ where
}

/// Visits all entries of the given paths recursively using tokios async read_dir.
pub fn visit_all<'a, I, P>(paths: I) -> impl Stream<Item = io::Result<PathBuf>> + Send + 'static
pub fn visit_all<I, P>(paths: I) -> impl Stream<Item = io::Result<PathBuf>> + Send + 'static
where
P: Into<PathBuf>,
I: IntoIterator<Item = P>,
Expand Down Expand Up @@ -84,7 +84,7 @@ where
paths.into_iter().map(Into::into).collect::<Vec<PathBuf>>(),
|mut to_visit| async {
let path = to_visit.pop()?;
let file_stream = match one_level(path.into(), &mut to_visit).await {
let file_stream = match one_level(path, &mut to_visit).await {
Ok(files) => stream::iter(files).map(Ok).left_stream(),
Err(e) => stream::once(async { Err(e) }).right_stream(),
};
Expand Down

0 comments on commit 2c29827

Please sign in to comment.