Skip to content

Commit

Permalink
Fix+augment testsuite, tighten up implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalmer committed Jan 30, 2024
1 parent 91ad200 commit 477ed17
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/003_successful_globs/glob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
paths:
- 003_successful_globs/*
- !003_successful_globs/*
- '!003_successful_globs/*.json'

defaults:
run:
Expand Down
1 change: 1 addition & 0 deletions test/004a_failing_negative_glob/exitcode
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
24 changes: 24 additions & 0 deletions test/004a_failing_negative_glob/glob.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions test/004a_failing_negative_glob/stderr
Original file line number Diff line number Diff line change
@@ -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",
},
],
}
1 change: 1 addition & 0 deletions test/004a_failing_negative_glob/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fatal error validating 004a_failing_negative_glob/glob.yml
4 changes: 4 additions & 0 deletions test/004a_failing_negative_glob/validation_state.snap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"actionType": "workflow",
"errors": []
}

0 comments on commit 477ed17

Please sign in to comment.