Skip to content

Commit

Permalink
CLI: add CI for lint, security, reformat with nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-onelson committed Dec 23, 2024
1 parent 9c0b41e commit 3fa47ef
Show file tree
Hide file tree
Showing 24 changed files with 205 additions and 69 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/cli-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CLI Lint

on:
push:
branches:
- main
paths:
- 'svix-cli/**'
- '.github/workflows/cli-lint.yml'
pull_request:
paths:
- 'svix-cli/**'
- '.github/workflows/cli-lint.yml'
- 'openapi.json'

# When pushing to a PR, cancel any jobs still running for the previous head commit of the PR
concurrency:
# head_ref is only defined for pull requests, run_id is always unique and defined so if this
# workflow was not triggered by a pull request, nothing gets cancelled.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
check-fmt:
name: Check formatting
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: rustfmt
run: cargo fmt -- --check
working-directory: svix-cli

test-versions:
name: CLI Lint
runs-on: ubuntu-24.04
strategy:
matrix:
rust: [stable, beta]
steps:
- uses: actions/checkout@v4

- name: Regen openapi libs
run: |
yarn
./regen_openapi.sh
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy

- uses: Swatinem/rust-cache@v2
with:
workspaces: "svix-cli -> target"
# only save the cache on the main branch
# cf https://github.com/Swatinem/rust-cache/issues/95
save-if: ${{ github.ref == 'refs/heads/main' }}
# include relevant information in the cache name
prefix-key: "cli-${{ matrix.rust }}"

- uses: taiki-e/install-action@nextest

- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: svix-cli

- name: Run tests
run: cargo nextest run
working-directory: svix-cli
24 changes: 24 additions & 0 deletions .github/workflows/cli-security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CLI Security

on:
push:
branches:
- main
paths:
- 'svix-cli/**/Cargo.toml'
- 'svix-cli/**/Cargo.lock'
- '.github/workflows/cli-security.yml'
pull_request:
paths:
- 'rust/**/Cargo.toml'
- 'rust/**/Cargo.lock'
- '.github/workflows/cli-security.yml'

jobs:
security_audit:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2
with:
manifest-path: svix-cli/Cargo.toml
2 changes: 2 additions & 0 deletions svix-cli/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
2 changes: 1 addition & 1 deletion svix-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions svix-cli/src/cli_types/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::Args;
use svix::api;
use svix::api::Ordering;
use svix::{api, api::Ordering};

#[derive(Args, Clone)]
pub struct ApplicationListOptions {
Expand Down
3 changes: 1 addition & 2 deletions svix-cli/src/cli_types/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chrono::{DateTime, Utc};
use clap::Args;
use svix::api;
use svix::api::Ordering;
use svix::{api, api::Ordering};

#[derive(Args, Clone)]
pub struct EndpointListOptions {
Expand Down
3 changes: 1 addition & 2 deletions svix-cli/src/cli_types/event_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::Args;
use svix::api;
use svix::api::Ordering;
use svix::{api, api::Ordering};

#[derive(Args, Clone)]
pub struct EventTypeListOptions {
Expand Down
3 changes: 1 addition & 2 deletions svix-cli/src/cli_types/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::Args;
use svix::api;
use svix::api::Ordering;
use svix::{api, api::Ordering};

#[derive(Args, Clone)]
pub struct IntegrationListOptions {
Expand Down
6 changes: 4 additions & 2 deletions svix-cli/src/cli_types/message_attempt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use chrono::{DateTime, Utc};
use clap::Args;
use svix::api;
use svix::api::{MessageStatus, StatusCodeClass};
use svix::{
api,
api::{MessageStatus, StatusCodeClass},
};

#[derive(Args, Clone)]
pub struct MessageAttemptListByEndpointOptions {
Expand Down
8 changes: 5 additions & 3 deletions svix-cli/src/cmds/api/application.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::cli_types::application::ApplicationListOptions;
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{ApplicationIn, ApplicationPatch};

use crate::{
cli_types::{application::ApplicationListOptions, PostOptions},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
4 changes: 2 additions & 2 deletions svix-cli/src/cmds/api/authentication.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{AppPortalAccessIn, ApplicationTokenExpireIn};

use crate::{cli_types::PostOptions, json::JsonOf};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
11 changes: 8 additions & 3 deletions svix-cli/src/cmds/api/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use crate::cli_types::endpoint::{EndpointListOptions, EndpointStatsOptions};
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{
EndpointHeadersIn, EndpointHeadersPatchIn, EndpointIn, EndpointPatch, EndpointSecretRotateIn,
EndpointTransformationIn, EndpointUpdate, EventExampleIn, RecoverIn, ReplayIn,
};

use crate::{
cli_types::{
endpoint::{EndpointListOptions, EndpointStatsOptions},
PostOptions,
},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
8 changes: 5 additions & 3 deletions svix-cli/src/cmds/api/event_type.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::cli_types::event_type::EventTypeListOptions;
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{EventTypeImportOpenApiIn, EventTypeIn, EventTypePatch, EventTypeUpdate};

use crate::{
cli_types::{event_type::EventTypeListOptions, PostOptions},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
8 changes: 5 additions & 3 deletions svix-cli/src/cmds/api/integration.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::cli_types::integration::IntegrationListOptions;
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{IntegrationIn, IntegrationUpdate};

use crate::{
cli_types::{integration::IntegrationListOptions, PostOptions},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
8 changes: 5 additions & 3 deletions svix-cli/src/cmds/api/message.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::cli_types::message::MessageListOptions;
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::MessageIn;

use crate::{
cli_types::{message::MessageListOptions, PostOptions},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
5 changes: 3 additions & 2 deletions svix-cli/src/cmds/api/message_attempt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use clap::{Args, Subcommand};
use colored_json::ColorMode;

use crate::cli_types::message_attempt::{
MessageAttemptListAttemptedDestinationsOptions, MessageAttemptListAttemptedMessagesOptions,
MessageAttemptListByEndpointOptions, MessageAttemptListByMsgOptions,
};
use clap::{Args, Subcommand};
use colored_json::ColorMode;

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
Expand Down
6 changes: 3 additions & 3 deletions svix-cli/src/cmds/completion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::BIN_NAME;
use anyhow::Result;
use clap::CommandFactory;
use clap_complete::shells;
use clap_complete::{generate as generate_, Shell};
use clap_complete::{generate as generate_, shells, Shell};

use crate::BIN_NAME;

pub fn generate(shell: &Shell) -> Result<()> {
let mut writer = std::io::stdout().lock();
Expand Down
3 changes: 2 additions & 1 deletion svix-cli/src/cmds/listen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::config::{get_config_file_path, Config};
use anyhow::{Context, Result};
use clap::Args;

use crate::config::{get_config_file_path, Config};

#[derive(Args)]
pub struct ListenArgs {
/// The local URL to forward webhooks to
Expand Down
4 changes: 2 additions & 2 deletions svix-cli/src/cmds/login.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::config;
use crate::config::Config;
use anyhow::Result;
use dialoguer::Input;

use crate::{config, config::Config};

pub fn prompt() -> Result<()> {
print!("Welcome to the Svix CLI!\n\n");

Expand Down
9 changes: 6 additions & 3 deletions svix-cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::{
io::Write,
os::unix::fs::OpenOptionsExt,
path::{Path, PathBuf},
};

use anyhow::Result;
use figment::{
providers::{Env, Format, Toml},
Figment,
};
use serde::{Deserialize, Serialize};
use std::io::Write;
use std::os::unix::fs::OpenOptionsExt;
use std::path::{Path, PathBuf};

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Config {
Expand Down
6 changes: 3 additions & 3 deletions svix-cli/src/json.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::str::FromStr;

use anyhow::{Error, Result};
use colored_json::{Color, ColorMode, ToColoredJson};
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::str::FromStr;
use serde::{de::DeserializeOwned, Serialize};

#[derive(Clone, Debug, PartialEq)]
pub struct JsonOf<T: DeserializeOwned>(T);
Expand Down
24 changes: 14 additions & 10 deletions svix-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use crate::cmds::api::authentication::AuthenticationArgs;
use crate::cmds::api::endpoint::EndpointArgs;
use crate::cmds::api::event_type::EventTypeArgs;
use crate::cmds::api::integration::IntegrationArgs;
use crate::cmds::api::message::MessageArgs;
use crate::cmds::api::message_attempt::MessageAttemptArgs;
use crate::cmds::listen::ListenArgs;
use crate::cmds::open::OpenArgs;
use crate::cmds::signature::SignatureArgs;
use crate::config::Config;
use anyhow::Result;
use clap::{Parser, Subcommand};
use clap_complete::Shell;
use cmds::api::application::ApplicationArgs;
use colored_json::{ColorMode, Output};
use concolor_clap::{Color, ColorChoice};

use crate::{
cmds::{
api::{
authentication::AuthenticationArgs, endpoint::EndpointArgs, event_type::EventTypeArgs,
integration::IntegrationArgs, message::MessageArgs,
message_attempt::MessageAttemptArgs,
},
listen::ListenArgs,
open::OpenArgs,
signature::SignatureArgs,
},
config::Config,
};

mod cli_types;
mod cmds;
mod config;
Expand Down
3 changes: 2 additions & 1 deletion svix-cli/src/relay/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
//! The main difference between the two is the `-In` has an HTTP method on it (needed so we can
//! recreate the request properly to the local server, whereas the `-Out` has a status code.
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

pub const VERSION: u16 = 1;

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit 3fa47ef

Please sign in to comment.