-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Allow actions to be skipped using env vars. (#1105)
* Start on. * Update tests. * Update types.
- Loading branch information
Showing
17 changed files
with
172 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,74 @@ | ||
use std::env; | ||
|
||
pub mod install_deps; | ||
pub mod run_target; | ||
pub mod run_task; | ||
pub mod setup_tool; | ||
pub mod sync_project; | ||
pub mod sync_workspace; | ||
|
||
pub fn should_skip_action(key: &str) -> bool { | ||
env::var(key).is_ok_and(|v| matches_pattern(&v, "")) | ||
} | ||
|
||
pub fn should_skip_action_matching<V: AsRef<str>>(key: &str, pattern: V) -> bool { | ||
env::var(key).is_ok_and(|v| matches_pattern(&v, pattern.as_ref())) | ||
} | ||
|
||
fn matches_pattern(value: &str, pattern: &str) -> bool { | ||
if value.contains(',') { | ||
return value.split(',').any(|v| matches_pattern(v, pattern)); | ||
} | ||
|
||
let pattern = pattern.to_lowercase(); | ||
|
||
if value == "*" || value == "*:*" || value == "true" || value == pattern { | ||
return true; | ||
} | ||
|
||
if pattern.contains(':') { | ||
let mut left = pattern.split(':'); | ||
let mut right = value.split(':'); | ||
|
||
return match ((left.next(), left.next()), (right.next(), right.next())) { | ||
#[allow(clippy::nonminimal_bool)] | ||
((Some(a1), Some(a2)), (Some(b1), Some(b2))) => { | ||
// foo:bar == foo:bar | ||
a1 == b1 && a2 == b2 || | ||
// foo:bar == foo:* | ||
a1 == b1 && b2 == "*" || | ||
// foo:bar == *:bar | ||
a2 == b2 && b1 == "*" | ||
} | ||
((Some(a1), Some(_)), (Some(b1), None)) => { | ||
// foo:bar == foo | ||
a1 == b1 | ||
} | ||
_ => false, | ||
}; | ||
} | ||
|
||
false | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn patterns() { | ||
assert!(matches_pattern("*", "")); | ||
assert!(matches_pattern("*:*", "")); | ||
assert!(matches_pattern("true", "")); | ||
|
||
assert!(matches_pattern("*", "node:20.0.0")); | ||
assert!(matches_pattern("node:*", "node:20.0.0")); | ||
assert!(matches_pattern("node", "node:20.0.0")); | ||
assert!(matches_pattern("node:20.0.0", "node:20.0.0")); | ||
assert!(!matches_pattern("rust", "node:20.0.0")); | ||
assert!(!matches_pattern("node:19.0.0", "node:20.0.0")); | ||
|
||
assert!(matches_pattern("foo,bar", "foo")); | ||
assert!(matches_pattern("foo,bar", "bar")); | ||
assert!(!matches_pattern("foo,bar", "baz")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters