Skip to content

Commit 5e8d8eb

Browse files
committed
chore: Add CI checks (#5)
* add CI workflow with `rustfmt` job * envoy-types: skip `rustfmt` on generated code * envoy-proto-collect: incorporate `clippy`'s suggestions * envoy-types: incorporate `clippy`'s suggestions * envoy-types: skip `clippy` for generated code * examples: incorporate `clippy`'s suggestions * adjust CI workflow: add `clippy` job * adjust CI workflow: add `build_and_test` job
1 parent 5a35b4a commit 5e8d8eb

File tree

7 files changed

+77
-22
lines changed

7 files changed

+77
-22
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request: {}
7+
merge_group:
8+
branches: [ "main" ]
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
RUSTFLAGS: "-D warnings"
13+
14+
jobs:
15+
16+
rustfmt:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: hecrj/setup-rust-action@v2
21+
with:
22+
components: rustfmt
23+
- run: cargo fmt --all --check
24+
25+
clippy:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: hecrj/setup-rust-action@v2
30+
with:
31+
components: clippy
32+
- uses: Swatinem/rust-cache@v2
33+
- run: cargo clippy --workspace --all-features --all-targets
34+
35+
build_and_test:
36+
runs-on: ${{ matrix.os }}
37+
strategy:
38+
matrix:
39+
os: [ubuntu-latest, macOS-latest, windows-latest]
40+
toolchain: [stable, beta, nightly]
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: hecrj/setup-rust-action@v2
44+
- uses: taiki-e/install-action@protoc
45+
- uses: Swatinem/rust-cache@v2
46+
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
47+
- run: cargo build --verbose
48+
- run: cargo test --doc --all-features --verbose

envoy-proto-collect/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use glob::glob;
22
use std::{
33
fs::{self, File},
44
io::{self, Write},
5-
path::PathBuf,
5+
path::{Path, PathBuf},
66
process,
77
};
88

@@ -29,24 +29,23 @@ fn apache_v2(year: u32, owner: &str) -> String {
2929
}
3030

3131
fn collect_protos(
32-
out_dir: &PathBuf,
32+
out_dir: &Path,
3333
repo: &str,
3434
glob_patterns: Vec<&str>,
3535
add_license: Option<&String>,
3636
) {
37-
let repo = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
38-
.join("submodules")
39-
.join(repo);
37+
let manifest_dir = std::env!("CARGO_MANIFEST_DIR");
38+
let repo_dir = Path::new(manifest_dir).join("submodules").join(repo);
4039

41-
if !repo.is_dir() {
40+
if !repo_dir.is_dir() {
4241
eprintln!("Error: submodule repo {:?} not found.", repo);
4342
process::exit(1);
4443
}
4544

4645
let mut source_protos: Vec<PathBuf> = Vec::new();
4746

4847
for pattern in glob_patterns {
49-
let mut matches: Vec<PathBuf> = glob(repo.join(pattern).to_str().unwrap())
48+
let mut matches: Vec<PathBuf> = glob(repo_dir.join(pattern).to_str().unwrap())
5049
.unwrap()
5150
.filter_map(Result::ok)
5251
.collect();
@@ -59,7 +58,7 @@ fn collect_protos(
5958

6059
let target_name = out_dir.join(
6160
proto
62-
.strip_prefix(repo.parent().expect("repo has parent"))
61+
.strip_prefix(repo_dir.parent().expect("repo has parent"))
6362
.expect("base is a prefix of proto"),
6463
);
6564

@@ -84,7 +83,8 @@ fn collect_protos(
8483
}
8584

8685
fn main() {
87-
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
86+
let manifest_dir = std::env!("CARGO_MANIFEST_DIR");
87+
let out_dir = Path::new(manifest_dir)
8888
.parent()
8989
.expect("envoy-proto-collect is inside a workspace")
9090
.join("envoy-types")

envoy-types/src/ext_authz/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ pub mod v3 {
133133
}
134134

135135
fn with_status(status: tonic::Status) -> Self {
136-
let mut check_response = CheckResponse::default();
137-
check_response.status = Some(rpc::Status {
136+
let status = Some(rpc::Status {
138137
code: status.code().into(),
139138
message: status.message().into(),
140139
// `tonic::Status`'s details are not considered
141140
details: Vec::new(),
142141
});
143-
check_response
142+
143+
CheckResponse {
144+
status,
145+
..Default::default()
146+
}
144147
}
145148

146149
fn set_status(&mut self, status: tonic::Status) -> &mut Self {
@@ -336,9 +339,9 @@ pub mod v3 {
336339
}
337340
}
338341

339-
impl Into<OkHttpResponse> for OkHttpResponseBuilder {
340-
fn into(self) -> OkHttpResponse {
341-
self.build()
342+
impl From<OkHttpResponseBuilder> for OkHttpResponse {
343+
fn from(val: OkHttpResponseBuilder) -> Self {
344+
val.build()
342345
}
343346
}
344347

@@ -437,9 +440,9 @@ pub mod v3 {
437440
}
438441
}
439442

440-
impl Into<DeniedHttpResponse> for DeniedHttpResponseBuilder {
441-
fn into(self) -> DeniedHttpResponse {
442-
self.build()
443+
impl From<DeniedHttpResponseBuilder> for DeniedHttpResponse {
444+
fn from(val: DeniedHttpResponseBuilder) -> Self {
445+
val.build()
443446
}
444447
}
445448

envoy-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ using a [previous version of `envoy-types`].
9696
#![warn(missing_debug_implementations, rust_2018_idioms)]
9797
#![allow(missing_docs, rustdoc::invalid_html_tags, rustdoc::bare_urls)]
9898

99+
#[rustfmt::skip]
100+
#[allow(clippy::all)]
99101
mod generated;
100102

101103
/// Compiled protobuf types

examples/src/ext_authz/authorization_server_basic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use tonic::{transport::Server, Request, Response, Status};
23

34
use envoy_types::ext_authz::v3::pb::{
@@ -34,8 +35,9 @@ impl Authorization for MyServer {
3435

3536
#[tokio::main]
3637
async fn main() -> Result<(), Box<dyn std::error::Error>> {
37-
let addr = format!("0.0.0.0:50051").parse().unwrap();
38-
let server = MyServer::default();
38+
let server_port = env::var("SERVER_PORT").unwrap_or("50051".into());
39+
let addr = format!("0.0.0.0:{server_port}").parse().unwrap();
40+
let server = MyServer;
3941

4042
println!("AuthorizationServer listening on {addr}");
4143

examples/src/ext_authz/authorization_server_full.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Authorization for MyServer {
9090
async fn main() -> Result<(), Box<dyn std::error::Error>> {
9191
let server_port = env::var("SERVER_PORT").unwrap_or("50051".into());
9292
let addr = format!("0.0.0.0:{server_port}").parse().unwrap();
93-
let server = MyServer::default();
93+
let server = MyServer;
9494

9595
println!("AuthorizationServer listening on {}", addr);
9696

examples/src/ext_authz/authorization_server_pb_only.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Authorization for MyServer {
147147
async fn main() -> Result<(), Box<dyn std::error::Error>> {
148148
let server_port = env::var("SERVER_PORT").unwrap_or("50051".into());
149149
let addr = format!("0.0.0.0:{server_port}").parse().unwrap();
150-
let server = MyServer::default();
150+
let server = MyServer;
151151

152152
println!("AuthorizationServer listening on {}", addr);
153153

0 commit comments

Comments
 (0)