1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
extern crate proc_macro;
use proc_macro::TokenStream;
static CHECK_EXISTENCE: &[&str] = &[
"CODEBUILD_CI",
"BUILD_DEFINITIONVERSION",
"bamboo_buildKey",
"BITBUCKET_COMMIT",
"BUDDY",
"CIRCLECI",
"GITHUB_ACTIONS",
"GITLAB_CI",
"JENKINS_URL",
"TEAMCITY_VERSION",
"TRAVIS",
];
static CHECK_VALUE: &[(&str, &str)] = &[
("APPVEYOR", "True"),
("CI_NAME", "codeship"),
("CI", "drone"),
("WERCKER", "true"),
];
fn is_ci() -> bool {
CHECK_EXISTENCE.iter().map(std::env::var).flatten().count() > 0
|| CHECK_VALUE
.iter()
.filter(|(name, value)| &std::env::var(name).unwrap_or_default() == value)
.count()
> 0
}
#[proc_macro]
pub fn fail_on_ci(item: TokenStream) -> TokenStream {
if is_ci() {
panic!("Code is not allowed to compile on CI Servers!");
}
item
}