From 477ed170b802b33452ad3d924bf89ed731d8f811 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Tue, 30 Jan 2024 11:23:07 +1100 Subject: [PATCH] Fix+augment testsuite, tighten up implementation --- src/lib.rs | 10 ++++++-- test/003_successful_globs/glob.yml | 2 +- test/004a_failing_negative_glob/exitcode | 1 + test/004a_failing_negative_glob/glob.yml | 24 +++++++++++++++++++ test/004a_failing_negative_glob/stderr | 18 ++++++++++++++ test/004a_failing_negative_glob/stdout | 1 + .../validation_state.snap.json | 4 ++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 test/004a_failing_negative_glob/exitcode create mode 100644 test/004a_failing_negative_glob/glob.yml create mode 100644 test/004a_failing_negative_glob/stderr create mode 100644 test/004a_failing_negative_glob/stdout create mode 100644 test/004a_failing_negative_glob/validation_state.snap.json diff --git a/src/lib.rs b/src/lib.rs index 4f8ab08..782461c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,6 @@ use validation_state::ValidationState; pub use crate::config::CliConfig; use crate::schemas::{validate_as_action, validate_as_workflow}; #[cfg(not(feature = "js"))] -use glob::glob; use serde_json::{Map, Value}; #[cfg(feature = "js")] @@ -196,7 +195,14 @@ fn validate_globs(globs: &serde_json::Value, path: &str, state: &mut ValidationS if let Some(globs) = globs.as_array() { for g in globs { - match glob(&g.as_str().unwrap().replace("!", "")) { + let glob = g.as_str().expect("glob to be a string"); + let pattern = if glob.starts_with('!') { + glob.chars().skip(1).collect() + } else { + glob.to_string() + }; + + match glob::glob(&pattern) { Ok(res) => { if res.count() == 0 { state.errors.push(ValidationError::NoFilesMatchingGlob { diff --git a/test/003_successful_globs/glob.yml b/test/003_successful_globs/glob.yml index fd7d49b..2ba9749 100644 --- a/test/003_successful_globs/glob.yml +++ b/test/003_successful_globs/glob.yml @@ -4,7 +4,7 @@ on: push: paths: - 003_successful_globs/* - - !003_successful_globs/* + - '!003_successful_globs/*.json' defaults: run: diff --git a/test/004a_failing_negative_glob/exitcode b/test/004a_failing_negative_glob/exitcode new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/004a_failing_negative_glob/exitcode @@ -0,0 +1 @@ +1 diff --git a/test/004a_failing_negative_glob/glob.yml b/test/004a_failing_negative_glob/glob.yml new file mode 100644 index 0000000..4cf6acc --- /dev/null +++ b/test/004a_failing_negative_glob/glob.yml @@ -0,0 +1,24 @@ +name: Bad globs, no biscuit + +on: + push: + paths: + - '!004a_failing_negative_glob/*.txt' + +defaults: + run: + shell: bash + +jobs: + glob: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup + uses: something/setup@v1 + + - name: Build + uses: something/build@v1 diff --git a/test/004a_failing_negative_glob/stderr b/test/004a_failing_negative_glob/stderr new file mode 100644 index 0000000..029517a --- /dev/null +++ b/test/004a_failing_negative_glob/stderr @@ -0,0 +1,18 @@ +Validation failed: ValidationState { + action_type: Some( + Workflow, + ), + file_path: Some( + "004a_failing_negative_glob/glob.yml", + ), + errors: [ + NoFilesMatchingGlob { + code: "glob_not_matched", + detail: Some( + "Glob \"!004a_failing_negative_glob/*.txt\" in /on/push/paths does not match any files", + ), + path: "/on/push/paths", + title: "Glob does not match any files", + }, + ], +} diff --git a/test/004a_failing_negative_glob/stdout b/test/004a_failing_negative_glob/stdout new file mode 100644 index 0000000..8c3b53a --- /dev/null +++ b/test/004a_failing_negative_glob/stdout @@ -0,0 +1 @@ +Fatal error validating 004a_failing_negative_glob/glob.yml diff --git a/test/004a_failing_negative_glob/validation_state.snap.json b/test/004a_failing_negative_glob/validation_state.snap.json new file mode 100644 index 0000000..c313801 --- /dev/null +++ b/test/004a_failing_negative_glob/validation_state.snap.json @@ -0,0 +1,4 @@ +{ + "actionType": "workflow", + "errors": [] +}