|
3 | 3 |
|
4 | 4 | use std::process::Command;
|
5 | 5 |
|
| 6 | +use build_helper::ci::CiEnv; |
| 7 | +use build_helper::git::get_rust_lang_rust_remote; |
| 8 | + |
6 | 9 | macro_rules! try_unwrap_in_ci {
|
7 | 10 | ($expr:expr) => {
|
8 | 11 | match $expr {
|
@@ -36,38 +39,6 @@ If you're doing a subtree sync, add your tool to the list in the code that emitt
|
36 | 39 | }
|
37 | 40 | }
|
38 | 41 |
|
39 |
| -/// Finds the remote for rust-lang/rust. |
40 |
| -/// For example for these remotes it will return `upstream`. |
41 |
| -/// ```text |
42 |
| -/// origin https://github.com/Nilstrieb/rust.git (fetch) |
43 |
| -/// origin https://github.com/Nilstrieb/rust.git (push) |
44 |
| -/// upstream https://github.com/rust-lang/rust (fetch) |
45 |
| -/// upstream https://github.com/rust-lang/rust (push) |
46 |
| -/// ``` |
47 |
| -fn get_rust_lang_rust_remote() -> Result<String, String> { |
48 |
| - let mut git = Command::new("git"); |
49 |
| - git.args(["config", "--local", "--get-regex", "remote\\..*\\.url"]); |
50 |
| - |
51 |
| - let output = git.output().map_err(|err| format!("{err:?}"))?; |
52 |
| - if !output.status.success() { |
53 |
| - return Err(format!( |
54 |
| - "failed to execute git config command: {}", |
55 |
| - String::from_utf8_lossy(&output.stderr) |
56 |
| - )); |
57 |
| - } |
58 |
| - |
59 |
| - let stdout = String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?; |
60 |
| - |
61 |
| - let rust_lang_remote = stdout |
62 |
| - .lines() |
63 |
| - .find(|remote| remote.contains("rust-lang")) |
64 |
| - .ok_or_else(|| "rust-lang/rust remote not found".to_owned())?; |
65 |
| - |
66 |
| - let remote_name = |
67 |
| - rust_lang_remote.split('.').nth(1).ok_or_else(|| "remote name not found".to_owned())?; |
68 |
| - Ok(remote_name.into()) |
69 |
| -} |
70 |
| - |
71 | 42 | /// Runs `git log --merges --format=%s $REMOTE/master..HEAD` and returns all commits
|
72 | 43 | fn find_merge_commits(remote: &str) -> Result<String, String> {
|
73 | 44 | let mut git = Command::new("git");
|
@@ -99,30 +70,3 @@ fn find_merge_commits(remote: &str) -> Result<String, String> {
|
99 | 70 |
|
100 | 71 | Ok(stdout)
|
101 | 72 | }
|
102 |
| - |
103 |
| -#[derive(Copy, Clone, PartialEq, Eq, Debug)] |
104 |
| -pub enum CiEnv { |
105 |
| - /// Not a CI environment. |
106 |
| - None, |
107 |
| - /// The Azure Pipelines environment, for Linux (including Docker), Windows, and macOS builds. |
108 |
| - AzurePipelines, |
109 |
| - /// The GitHub Actions environment, for Linux (including Docker), Windows and macOS builds. |
110 |
| - GitHubActions, |
111 |
| -} |
112 |
| - |
113 |
| -impl CiEnv { |
114 |
| - /// Obtains the current CI environment. |
115 |
| - pub fn current() -> CiEnv { |
116 |
| - if std::env::var("TF_BUILD").map_or(false, |e| e == "True") { |
117 |
| - CiEnv::AzurePipelines |
118 |
| - } else if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") { |
119 |
| - CiEnv::GitHubActions |
120 |
| - } else { |
121 |
| - CiEnv::None |
122 |
| - } |
123 |
| - } |
124 |
| - |
125 |
| - pub fn is_ci() -> bool { |
126 |
| - Self::current() != CiEnv::None |
127 |
| - } |
128 |
| -} |
0 commit comments