-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support app specific build directives for mobile: verifiable matcher
Summary: Build directives provide an option to users to run builds or tests regardless if they were picked by the target determinators on their diffs. It’s useful for users/bots that want to always run certain jobs to avoid unexpected breakages. E.g. By declaring “” on the diff, we will always run the “automation_fbandroid_debug” at both diff and land time. # This diff Adds directives.rs for parsing and checking build directives across verifiable-matcher, ranker. Doesn't filter out verifiables as long as the schedule type matches Reviewed By: Acesine Differential Revision: D54504082 fbshipit-source-id: f9df4c7570f09c2ff04067b87e0320058f85ea59
- Loading branch information
1 parent
77a38fc
commit 9d4c0f6
Showing
2 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under both the MIT license found in the | ||
* LICENSE-MIT file in the root directory of this source tree and the Apache | ||
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory | ||
* of this source tree. | ||
*/ | ||
|
||
//! Parsing directives from skycastle | ||
pub fn get_app_specific_build_directives(directives: &Option<Vec<String>>) -> Option<Vec<String>> { | ||
directives.as_ref().map(|directives| { | ||
directives | ||
.iter() | ||
.filter_map(|directive| { | ||
if directive.starts_with("@build[") && directive.ends_with(']') { | ||
Some( | ||
directive[7..directive.len() - 1] | ||
.split(',') | ||
.map(|s| s.to_string()) | ||
.collect::<Vec<String>>(), | ||
) | ||
} else { | ||
None | ||
} | ||
}) | ||
.flatten() | ||
.collect::<Vec<String>>() | ||
}) | ||
} | ||
|
||
pub fn app_specific_build_directives_contains_name( | ||
app_specific_build_directives: &Option<Vec<String>>, | ||
name: &String, | ||
) -> bool { | ||
app_specific_build_directives | ||
.as_ref() | ||
.map_or(false, |app_specific_build_directives| { | ||
app_specific_build_directives.contains(name) | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
#[test] | ||
fn test_get_app_specific_build_directives() { | ||
let directives = Some(vec![ | ||
"@build[directive1,directive2]".to_string(), | ||
"@build[directive3]".to_string(), | ||
"not a directive".to_string(), | ||
]); | ||
let result = get_app_specific_build_directives(&directives); | ||
assert_eq!( | ||
result, | ||
Some(vec![ | ||
"directive1".to_string(), | ||
"directive2".to_string(), | ||
"directive3".to_string(), | ||
]) | ||
); | ||
} | ||
#[test] | ||
fn test_get_app_specific_build_directives_none() { | ||
let directives = None; | ||
let result = get_app_specific_build_directives(&directives); | ||
assert_eq!(result, None); | ||
} | ||
#[test] | ||
fn test_app_specific_build_directives_contains_name() { | ||
let app_specific_build_directives = Some(vec![ | ||
"directive1".to_string(), | ||
"directive2".to_string(), | ||
"directive3".to_string(), | ||
]); | ||
assert!(app_specific_build_directives_contains_name( | ||
&app_specific_build_directives, | ||
&"directive1".to_string() | ||
)); | ||
assert!(!app_specific_build_directives_contains_name( | ||
&app_specific_build_directives, | ||
&"directive4".to_string() | ||
)); | ||
} | ||
#[test] | ||
fn test_app_specific_build_directives_contains_name_none() { | ||
let app_specific_build_directives = None; | ||
assert!(!app_specific_build_directives_contains_name( | ||
&app_specific_build_directives, | ||
&"directive1".to_string() | ||
)); | ||
} | ||
} |
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