check formatting

This commit is contained in:
nora 2022-03-06 17:05:19 +01:00
parent 1172ce0709
commit 1ef7b906ad
6 changed files with 52 additions and 15 deletions

View file

@ -14,17 +14,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Check dashboard frontend formatting
uses: creyD/prettier_action@v4.2
with:
dry: true
prettier_options: --check amqp_dashboard/assets/* --ignore-path .gitignore
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
- name: Run clippy -D clippy::all - name: Run clippy -D clippy::all
run: cargo clippy --verbose -- -D clippy::all run: cargo clippy --verbose -- -D clippy::all
- name: Check format - name: Check format
run: cargo +nightly fmt --verbose --all -- --check run: cargo xtask check-fmt
- name: Run tests - name: Run tests
run: cargo test --verbose --all run: cargo test --verbose --all
- name: Run client integration tests - name: Run client integration tests

View file

@ -6,7 +6,9 @@
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject",
"fmt": "prettier -w .",
"check-fmt": "prettier -c ."
}, },
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.14.1", "@testing-library/jest-dom": "^5.14.1",

View file

@ -6,7 +6,8 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"fmt": "prettier -w .", "fmt": "prettier -w .",
"test": "prettier -c . && node test-all.js" "check-fmt": "prettier -c .",
"test": "node test-all.js"
}, },
"dependencies": { "dependencies": {
"@types/amqplib": "^0.8.2", "@types/amqplib": "^0.8.2",

35
xtask/src/check_fmt.rs Normal file
View file

@ -0,0 +1,35 @@
use crate::project_root;
use anyhow::ensure;
use std::process::Command;
pub fn main() -> anyhow::Result<()> {
println!("$ cargo +nightly fmt --check");
let status = Command::new("cargo")
.arg("+nightly")
.arg("fmt")
.arg("--check")
.current_dir(project_root())
.status()?;
ensure!(
status.success(),
"`cargo +nightly fmt --check` did not exit successfully"
);
println!("$ yarn");
let status = Command::new("yarn")
.arg("check-fmt")
.current_dir(project_root().join("test-js"))
.status()?;
ensure!(status.success(), "`yarn fmt` did not exist successfully");
println!("$ yarn");
let status = Command::new("yarn")
.arg("check-fmt")
.current_dir(project_root().join("amqp_dashboard/frontend"))
.status()?;
ensure!(status.success(), "`yarn fmt` did not exist successfully");
ensure!(status.success(), "`prettier .` did not exist successfully");
Ok(())
}

View file

@ -3,8 +3,9 @@ use anyhow::ensure;
use std::process::Command; use std::process::Command;
pub fn main() -> anyhow::Result<()> { pub fn main() -> anyhow::Result<()> {
println!("$ cargo fmt"); println!("$ cargo +nightly fmt");
let status = Command::new("cargo") let status = Command::new("cargo")
.arg("+nightly")
.arg("fmt") .arg("fmt")
.current_dir(project_root()) .current_dir(project_root())
.status()?; .status()?;
@ -17,13 +18,12 @@ pub fn main() -> anyhow::Result<()> {
.status()?; .status()?;
ensure!(status.success(), "`yarn fmt` did not exist successfully"); ensure!(status.success(), "`yarn fmt` did not exist successfully");
println!("$ prettier -w ."); println!("$ yarn fmt");
let status = Command::new("prettier") let status = Command::new("yarn")
.arg("-w") .arg("fmt")
.arg(".") .current_dir(project_root().join("amqp_dashboard/frontend"))
.current_dir(project_root().join("amqp_dashboard/assets"))
.status()?; .status()?;
ensure!(status.success(), "`prettier .` did not exist successfully"); ensure!(status.success(), "`yarn fmt` did not exist successfully");
Ok(()) Ok(())
} }

View file

@ -1,5 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
mod check_fmt;
mod codegen; mod codegen;
mod fmt; mod fmt;
mod test_js; mod test_js;
@ -21,6 +22,8 @@ enum Commands {
TestJs, TestJs,
/// Format all code /// Format all code
Fmt, Fmt,
/// Check the formatting
CheckFmt,
} }
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
@ -30,6 +33,7 @@ fn main() -> anyhow::Result<()> {
Commands::Generate => codegen::main(), Commands::Generate => codegen::main(),
Commands::TestJs => test_js::main(), Commands::TestJs => test_js::main(),
Commands::Fmt => fmt::main(), Commands::Fmt => fmt::main(),
Commands::CheckFmt => check_fmt::main(),
} }
} }