Skip to content

Commit

Permalink
fixup! feat: add Google Cloud Build CI support
Browse files Browse the repository at this point in the history
  • Loading branch information
escarls committed Apr 22, 2024
1 parent 33642b9 commit 2ab9ece
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion codecov_cli/helpers/ci_adapters/cloudbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GoogleCloudBuildAdapter(CIAdapterBase):
- 'PROJECT_NUMBER=$PROJECT_NUMBER'
- 'REF_NAME=$REF_NAME'
- 'REPO_FULL_NAME=$REPO_FULL_NAME'
- 'TRIGGER_NAME=$TRIGGER_NAME'
Read more about manual substitution mapping here:
https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values#map_substitutions_manually
"""
Expand Down Expand Up @@ -59,7 +60,8 @@ def _get_pull_request_number(self):
return pr_num if pr_num != "" else None

def _get_job_code(self):
return None
job_code = os.getenv("TRIGGER_NAME")
return job_code if job_code != "" else None

def _get_service(self):
return "google_cloud_build"
Expand Down
19 changes: 15 additions & 4 deletions tests/ci_adapters/test_cloudbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CloudBuildEnvEnum(str, Enum):
PROJECT_NUMBER = "PROJECT_NUMBER"
REPO_FULL_NAME = "REPO_FULL_NAME"
_PR_NUMBER = "_PR_NUMBER"
TRIGGER_NAME = "TRIGGER_NAME"


class TestCloudBuild(object):
Expand Down Expand Up @@ -160,12 +161,22 @@ def test_commit_sha(self, env_dict, expected, mocker):

assert actual == expected

def test_job_code(self):
assert (
GoogleCloudBuildAdapter().get_fallback_value(FallbackFieldEnum.job_code)
is None
@pytest.mark.parametrize(
"env_dict,expected",
[
({}, None),
({CloudBuildEnvEnum.TRIGGER_NAME: ""}, None),
({CloudBuildEnvEnum.TRIGGER_NAME: "build-job-name"}, "build-job-name"),
],
)
def test_job_code(self, env_dict, expected, mocker):
mocker.patch.dict(os.environ, env_dict)
actual = GoogleCloudBuildAdapter().get_fallback_value(
FallbackFieldEnum.job_code
)

assert actual == expected

@pytest.mark.parametrize(
"env_dict,expected",
[
Expand Down

0 comments on commit 2ab9ece

Please sign in to comment.