Skip to content

Commit

Permalink
feat(xtask): Added 'buf' xtask subcommand
Browse files Browse the repository at this point in the history
This subcommand checks that you have the tool `buf` installed, and
then uses it to lint against our protobuf definition files. This is
intended to make it easier to lint these definitions in the future.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored and patrickjcasey committed Sep 17, 2024
1 parent 32ae9d0 commit b49ef7b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .buf.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: v2
lint:
use:
- DEFAULT
- STANDARD
rpc_allow_same_request_response: true
3 changes: 3 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn main() -> ExitCode {
.init();

let result = match args.command {
Commands::Buf => task::buf::run(),
Commands::Check => task::check::run(),
Commands::Ci => task::ci::run(),
Commands::Changelog(args) => task::changelog::run(args),
Expand Down Expand Up @@ -60,6 +61,8 @@ enum Commands {
Rfd(RfdArgs),
/// Work with the Hipcheck website.
Site(SiteArgs),
/// Lint the Hipcheck plugin gRPC definition.
Buf,
}

#[derive(Debug, clap::Args)]
Expand Down
19 changes: 19 additions & 0 deletions xtask/src/task/buf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::workspace;
use anyhow::{Context, Result};
use pathbuf::pathbuf;
use which::which;
use xshell::{cmd, Shell};

/// Run the `buf lint` command
pub fn run() -> Result<()> {
let sh = Shell::new().context("could not init shell")?;
which("buf").context("could not find 'buf'")?;

let root = workspace::root()?;
let config = pathbuf![&root, ".buf.yaml"];
let target = pathbuf![&root, "hipcheck", "proto"];

cmd!(sh, "buf lint --config {config} {target}").run()?;

Ok(())
}
1 change: 1 addition & 0 deletions xtask/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//! Commands supported by 'xtask'

pub mod buf;
pub mod changelog;
pub mod check;
pub mod ci;
Expand Down

0 comments on commit b49ef7b

Please sign in to comment.