Skip to content

Commit

Permalink
Merge pull request #4 from bheylin/expand-workflow
Browse files Browse the repository at this point in the history
Expand workflow & add cargo deny
  • Loading branch information
charlesvdv authored Oct 30, 2024
2 parents 464fe8c + 5c24146 commit 43ef3f8
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 23 deletions.
73 changes: 67 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,74 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build-test:
name: Build and test (${{ matrix.os }})

strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--verbose
- name: Run tests (without coverage)
run: >
cargo test
--verbose
check-clippy-and-format:
name: Check clippy and format

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2

- name: Set up nightly toolchain
# Cannot be `minimal` profile, need `rustfmt` and `clippy`:
# https://rust-lang.github.io/rustup/concepts/profiles.html#profiles
run: >
rustup toolchain install nightly
&& rustup component add --toolchain nightly rustfmt
- name: Check formatting
run: >
cargo +nightly fmt
--all
-- --check
- name: Check clippy
run: >
cargo clippy
--workspace
--all-targets
--all-features
-- --deny warnings
cargo-deny:
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources

# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- uses: EmbarkStudios/cargo-deny-action@8371184bd11e21dcf8ac82ebf8c9c9f74ebf7268
with:
command: check ${{ matrix.checks }}
10 changes: 10 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
23 changes: 23 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# configuration for https://github.com/EmbarkStudios/cargo-deny
[graph]
all-features = true

[licenses]
confidence-threshold = 0.8
allow = [
"Apache-2.0",
"MIT",
"Unicode-DFS-2016",
]

[advisories]
yanked = "deny"

[bans]
multiple-versions = "deny"
wildcards = 'deny'

[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group_imports = "StdExternalCrate" # Unstable
imports_granularity = "Module" # Unstable
14 changes: 14 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -e

start=$(date -Iseconds -u)
host_name=$(hostname)
echo "Starting build at: ${start} on ${host_name}"

export RUST_BACKTRACE="full"

cargo deny check
cargo build --verbose
cargo test --verbose --all-features
cargo clippy --workspace --all-targets --all-features -- --deny warnings
5 changes: 5 additions & 0 deletions scripts/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

cargo +nightly fmt --all
11 changes: 6 additions & 5 deletions src/macros_utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::BTreeMap;
use std::ops::Range;

use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term;
use codespan_reporting::term::termcolor;

use crate::validators;
use crate::{Error, Validator, Value};
use std::collections::BTreeMap;
use std::ops::Range;
use crate::{validators, Error, Validator, Value};

pub struct Input(Value);

Expand Down Expand Up @@ -176,9 +176,10 @@ impl SpanSerializer {

#[cfg(test)]
mod tests {
use indoc::indoc;

use super::SpanSerializer;
use crate::Value;
use indoc::indoc;

#[test]
fn serializer_primitive() {
Expand Down
11 changes: 5 additions & 6 deletions src/validators/array.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::validators;
use crate::{Error, Validator, Value};
use std::collections::HashSet;

use crate::{validators, Error, Validator, Value};

/// Match each array element to a specific validator.
pub fn array(array_validators: Vec<Box<dyn Validator>>) -> impl Validator {
ArrayValidator {
Expand Down Expand Up @@ -111,8 +111,7 @@ where

#[cfg(test)]
mod tests {
use crate::validators;
use crate::{Error, Validator};
use crate::{validators, Error, Validator};

#[test]
fn non_array() {
Expand Down Expand Up @@ -190,7 +189,7 @@ mod tests {

assert!(matches!(
validator.validate(&serde_json::json!([3, 1])),
Err(Error::UnmatchedValidator(_, _)),
Err(Error::UnmatchedValidator(_, _)),
));
}

Expand All @@ -203,7 +202,7 @@ mod tests {

assert!(matches!(
validator.validate(&serde_json::json!([3, 1])),
Err(Error::UnmatchedValidator(_, _)),
Err(Error::UnmatchedValidator(_, _)),
));
}

Expand Down
3 changes: 2 additions & 1 deletion src/validators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{get_value_type_id, Error, Validator, Value};
use std::fmt::Debug;

use crate::{get_value_type_id, Error, Validator, Value};

mod array;
mod object;
mod primitive;
Expand Down
6 changes: 3 additions & 3 deletions src/validators/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Error, Validator, Value};
use std::collections::HashMap;

use crate::{Error, Validator, Value};

/// Match if each key/value pair matches
///
/// Ignore key that are not specified. Use [object_strict] if you want to
Expand Down Expand Up @@ -66,8 +67,7 @@ impl Validator for ObjectValidator {
mod tests {
use std::collections::HashMap;

use crate::validators;
use crate::{Error, Validator};
use crate::{validators, Error, Validator};

#[test]
fn valid() {
Expand Down
3 changes: 1 addition & 2 deletions tests/error_msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use assert_json::assert_json;
use assert_json::validators;
use assert_json::{assert_json, validators};
use indoc::indoc;

macro_rules! assert_panic_output {
Expand Down

0 comments on commit 43ef3f8

Please sign in to comment.