Skip to content

Commit

Permalink
Merge pull request #10 from mkatychev/chore/ci-update
Browse files Browse the repository at this point in the history
Update CI setup
  • Loading branch information
mkatychev authored Mar 26, 2024
2 parents 89276ba + d794d4b commit 0960e38
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 212 deletions.
69 changes: 33 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ on:
branches:
- master
- dev

# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
GRPCURLV: "1.8.1"

jobs:
rustfmt:
lint:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with: # use nightly rustfmt rules
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
override: true
profile: minimal
components: rustfmt
# from stable toolchain:
# cargo +nightly fmt --all
- run: cargo fmt --all -- --check
- run: cargo +nightly fmt -- --config-path ./fmt/rustfmt.toml
- run: cargo clippy --all
test:
name: test
env:
Expand All @@ -32,15 +39,17 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: cargo test --verbose --workspace
- name: install nextest
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C /usr/local/bin
- run: cargo nextest run
examples:
name: examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
Expand All @@ -50,30 +59,18 @@ jobs:
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: install grpcurl
run: sudo curl -sL "${{ env.GRPCURL_URL }}" | sudo tar xvz -C /usr/local/bin/
env:
GRPCURL_URL: "https://github.com/fullstorydev/grpcurl/releases/download/\
v${{ env.GRPCURLV }}/grpcurl_${{ env.GRPCURLV }}_linux_x86_64.tar.gz"
- name: record
run: |
sudo curl -sL https://github.com/fullstorydev/grpcurl/releases/download/v1.8.1/grpcurl_1.8.1_linux_x86_64.tar.gz | sudo tar xvz -C /usr/local/bin/
sudo chmod +x /usr/local/bin/grpcurl
- name: httpbin post
run: cargo run -- record ./test_data post
- name: httpbin take
run: cargo run -- take ./test_data/post.01s.body.fr.json
- name: httpbin vrecord
run: cargo run -- vrecord ./test_data/post.vr.json
- name: httpbin vrecord alt
run: cargo run -- vrecord ./test_data/alt_post.vr.json
- name: grpcbin headers
run: cargo run -- record ./test_data grpc
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: clippy
- run: cargo clippy --all
cargo run -- record ./test_data post
cargo run -- record ./test_data grpc
- name: take
run: |
cargo run -- take ./test_data/post.01s.body.fr.json
- name: vrecord
run: |
cargo run -- vrecord ./test_data/post.vr.json
cargo run -- vrecord ./test_data/alt_post.vr.json
4 changes: 2 additions & 2 deletions filmreel/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Register {
Some((k, v)) => {
// push valid match onto Match vec
matches.push(Match::Variable {
name: k,
name: k,
value: v.clone(),
range: full_match.range(),
});
Expand Down Expand Up @@ -329,7 +329,7 @@ impl TryFrom<Vec<PathBuf>> for Register {
pub enum Match<'a> {
Escape(Range<usize>),
Variable {
name: &'a str,
name: &'a str,
value: Value,
range: Range<usize>,
},
Expand Down
52 changes: 26 additions & 26 deletions filmreel/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::{
/// [Frame spec](https://github.com/mkatychev/filmReel/blob/master/frame.md#frame)
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Frame<'a> {
pub protocol: Protocol,
pub protocol: Protocol,
#[serde(default, skip_serializing_if = "InstructionSet::is_empty")]
pub cut: InstructionSet<'a>, // Both the reads and writes can be optional
pub cut: InstructionSet<'a>, // Both the reads and writes can be optional
pub(crate) request: Request,
pub response: Response<'a>,
pub response: Response<'a>,
}

const MISSING_VAR_ERR: &str = "Variable is not present in InstructionSet";
Expand Down Expand Up @@ -217,13 +217,13 @@ pub struct InstructionSet<'a> {
skip_serializing_if = "HashSet::is_empty",
serialize_with = "ordered_set"
)]
pub(crate) reads: HashSet<Cow<'a, str>>,
pub(crate) reads: HashSet<Cow<'a, str>>,
#[serde(
rename(serialize = "to", deserialize = "to"),
skip_serializing_if = "HashMap::is_empty",
serialize_with = "ordered_str_map"
)]
pub(crate) writes: HashMap<Cow<'a, str>, Cow<'a, str>>,
pub(crate) writes: HashMap<Cow<'a, str>, Cow<'a, str>>,
#[serde(skip_serializing, default)]
pub hydrate_writes: bool,
}
Expand Down Expand Up @@ -259,12 +259,12 @@ impl<'a> InstructionSet<'a> {
pub struct Request {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) body: Option<Value>,
pub(crate) uri: Value,
pub(crate) uri: Value,
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub(crate) etc: Option<Value>,
pub(crate) etc: Option<Value>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) header: Option<Value>,
pub(crate) header: Option<Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) entrypoint: Option<Value>,
}
Expand Down Expand Up @@ -304,10 +304,10 @@ impl Request {
impl Default for Request {
fn default() -> Self {
Self {
body: None,
uri: Value::Null,
etc: Some(json!({})),
header: None,
body: None,
uri: Value::Null,
etc: Some(json!({})),
header: None,
entrypoint: None,
}
}
Expand Down Expand Up @@ -419,8 +419,8 @@ mod tests {
assert_eq!(
Frame {
protocol: Protocol::GRPC,
cut: InstructionSet {
reads: from![
cut: InstructionSet {
reads: from![
"EMAIL",
"FIRST",
"HOST",
Expand All @@ -430,19 +430,19 @@ mod tests {
"PORT",
"USER_TOKEN"
],
writes: HashMap::new(),
writes: HashMap::new(),
hydrate_writes: false,
},
request: Request {
body: Some(json!({
request: Request {
body: Some(json!({
"name": "Mario Rossi",
"email": "new_user@humanmail.com",
"object": json!({ "key": "value"})
})),
header: Some(json!({"Authorization": "Bearer jWt"})),
header: Some(json!({"Authorization": "Bearer jWt"})),
entrypoint: Some(json!("localhost:8080")),
uri: json!("user_api.User/CreateUser"),
etc: Some(json!({})),
uri: json!("user_api.User/CreateUser"),
etc: Some(json!({})),
},

response: Response {
Expand Down Expand Up @@ -490,12 +490,12 @@ mod tests {
assert_eq!(
Frame {
protocol: Protocol::GRPC,
cut: InstructionSet {
reads: from!["KEY", "KEY_2"],
writes: HashMap::new(),
cut: InstructionSet {
reads: from!["KEY", "KEY_2"],
writes: HashMap::new(),
hydrate_writes: false,
},
request: Request {
request: Request {
body: Some(json!({})),
uri: "".into(),
..Default::default()
Expand All @@ -518,8 +518,8 @@ mod tests {
#[test]
fn test_instruction_set_validate() {
let set = InstructionSet {
reads: from!["USER_ID"],
writes: to! ({"USER_ID"=> "'response'.'body'.'id'"}),
reads: from!["USER_ID"],
writes: to! ({"USER_ID"=> "'response'.'body'.'id'"}),
hydrate_writes: false,
};
assert!(set.validate().is_err());
Expand Down
33 changes: 16 additions & 17 deletions filmreel/src/reel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ use std::{
iter::FromIterator,
ops::Range,
path::{Path, PathBuf},
result::Result,
};

/// Represents the sequence of Frames to execute.
///
/// [Reel spec](https://github.com/mkatychev/filmReel/blob/master/Reel.md#reel)
#[derive(Debug)]
pub struct Reel {
dir: PathBuf,
dir: PathBuf,
frames: Vec<MetaFrame>,
}

Expand Down Expand Up @@ -53,7 +52,7 @@ impl Reel {
/// Return only successful frames
pub fn success_only(self) -> Self {
Self {
dir: self.dir,
dir: self.dir,
frames: self.frames.into_iter().filter(|x| x.is_success()).collect(),
}
}
Expand Down Expand Up @@ -147,13 +146,13 @@ impl IntoIterator for Reel {
///
#[derive(Clone, PartialEq, Debug)]
pub struct MetaFrame {
pub reel_name: String,
pub reel_name: String,
pub frame_type: FrameType,
pub alt_name: Option<String>,
pub name: String,
pub path: PathBuf,
pub step_f32: f32,
step: String,
pub alt_name: Option<String>,
pub name: String,
pub path: PathBuf,
pub step_f32: f32,
step: String,
}

impl TryFrom<&PathBuf> for MetaFrame {
Expand Down Expand Up @@ -302,12 +301,12 @@ mod tests {
assert_eq!(
MetaFrame {
frame_type: FrameType::Success,
name: "frame_name".to_string(),
alt_name: None,
path: PathBuf::from("./reel_name.01s.frame_name.fr.json"),
reel_name: "reel_name".to_string(),
step: "01s".to_string(),
step_f32: 1.0,
name: "frame_name".to_string(),
alt_name: None,
path: PathBuf::from("./reel_name.01s.frame_name.fr.json"),
reel_name: "reel_name".to_string(),
step: "01s".to_string(),
step_f32: 1.0,
},
try_path
);
Expand All @@ -316,7 +315,7 @@ mod tests {
#[test]
fn test_validate() {
let reel = Reel {
dir: ".".into(),
dir: ".".into(),
frames: vec![
MetaFrame::try_from(&PathBuf::from("./reel.01s.frame1.fr.json")).unwrap(),
MetaFrame::try_from(&PathBuf::from("./reel.01e.frame2.fr.json")).unwrap(),
Expand All @@ -327,7 +326,7 @@ mod tests {
#[test]
fn test_validate_err() {
let reel = Reel {
dir: ".".into(),
dir: ".".into(),
frames: vec![
MetaFrame::try_from(&PathBuf::from("./reel.01s.frame1.fr.json")).unwrap(),
MetaFrame::try_from(&PathBuf::from("./reel.01s.frame2.fr.json")).unwrap(),
Expand Down
Loading

0 comments on commit 0960e38

Please sign in to comment.