diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e549eb6 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,41 @@ +name: Rust lint & build + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./controller + + steps: + - uses: actions/checkout@v4 + - name: Format + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy -- -D warnings + build: + + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./controller + + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose + diff --git a/controller/src/config.rs b/controller/src/config.rs index f79a4ad..2175cdc 100644 --- a/controller/src/config.rs +++ b/controller/src/config.rs @@ -1,7 +1,7 @@ use clap::{Parser, ValueEnum}; #[derive(Debug, Parser, PartialEq)] -pub struct Config{ +pub struct Config { #[arg(long, env)] pub github_repository_url: String, #[arg(long, env)] @@ -23,16 +23,16 @@ pub struct Config{ } #[derive(Debug, Clone, ValueEnum, PartialEq)] -pub enum ServerType{ +pub enum ServerType { Paper, Velocity, } #[cfg(test)] -mod test{ +mod test { use super::*; #[test] - fn parse_arguments(){ + fn parse_arguments() { let configs = Config::try_parse_from(&[ "mdcs-controller", "--github-repository-url", @@ -53,11 +53,12 @@ mod test{ "./start.sh", "--stop-command", "./stop.sh", - ]).unwrap(); + ]) + .unwrap(); assert_eq!( configs, - Config{ + Config { github_repository_url: "https://github.com/example_user/example_repo".to_string(), github_username: "example_user".to_string(), github_password: "example_password".to_string(), diff --git a/controller/src/main.rs b/controller/src/main.rs index 50250bb..d84270c 100644 --- a/controller/src/main.rs +++ b/controller/src/main.rs @@ -14,5 +14,5 @@ async fn main() { let config = Config::parse(); // デバッグ用 Configを表示する - debug!("{:?}",config); + debug!("{:?}", config); }