Skip to main content

nerdbank_gitversioning/cloud_build_services/
travis.rs

1// Copyright (c) .NET Foundation and Contributors. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4//! [Travis CI](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables) support.
5
6use std::io::{self, Write};
7
8use crate::cloud::{
9    CloudBuild, EnvironmentVariables, empty_variables, env, is_nonempty, should_start_with,
10};
11
12/// Travis CI cloud-build integration.
13pub struct Travis;
14
15impl CloudBuild for Travis {
16    fn name(&self) -> &'static str {
17        "Travis"
18    }
19
20    fn is_applicable(&self) -> bool {
21        is_nonempty(env("TRAVIS").as_deref())
22    }
23
24    fn is_pull_request(&self) -> bool {
25        is_nonempty(env("TRAVIS_PULL_REQUEST_BRANCH").as_deref())
26    }
27
28    fn building_branch(&self) -> Option<String> {
29        should_start_with(env("TRAVIS_BRANCH"), "refs/heads/")
30    }
31
32    fn building_tag(&self) -> Option<String> {
33        env("TRAVIS_TAG")
34    }
35
36    fn git_commit_id(&self) -> Option<String> {
37        env("TRAVIS_COMMIT")
38    }
39
40    fn set_cloud_build_number(
41        &self,
42        _build_number: &str,
43        _stdout: &mut dyn Write,
44        _stderr: &mut dyn Write,
45    ) -> io::Result<EnvironmentVariables> {
46        Ok(empty_variables())
47    }
48
49    fn set_cloud_build_variable(
50        &self,
51        _name: &str,
52        _value: &str,
53        _stdout: &mut dyn Write,
54        _stderr: &mut dyn Write,
55    ) -> io::Result<EnvironmentVariables> {
56        Ok(empty_variables())
57    }
58}