Skip to content

Commit

Permalink
support app specific build directives for mobile: verifiable matcher
Browse files Browse the repository at this point in the history
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
Aaron Ho authored and facebook-github-bot committed Mar 15, 2024
1 parent 77a38fc commit 9d4c0f6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
93 changes: 93 additions & 0 deletions td_util/src/directives.rs
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()
));
}
}
1 change: 1 addition & 0 deletions td_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![forbid(unsafe_code)]

pub mod cli;
pub mod directives;
pub mod json;
pub mod no_hash;
pub mod prelude;
Expand Down

0 comments on commit 9d4c0f6

Please sign in to comment.