Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Add Cirrus CI (#322)
Browse files Browse the repository at this point in the history
* Add Cirrus CI

This is a follow up of the discussion in:

https://community.codecov.com/t/add-support-of-uploading-from-cirrus-ci-without-token/1028/34

and uses the bash uploader as a reference:

https://github.com/codecov/codecov-bash/blob/master/codecov#L959

* Add test case for Cirrus CI
  • Loading branch information
abravalheri authored Jul 6, 2021
1 parent 51469b0 commit 27a9833
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ after_success:
## CI Providers
| Company | Supported | Token Required |
| Company | Supported | Token Required |
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| [AppVeyor](https://www.appveyor.com/) | Yes [![Build status](https://ci.appveyor.com/api/projects/status/sw18lsj7786bw806/branch/master?svg=true)](https://ci.appveyor.com/project/stevepeak/codecov-python/branch/master) | Private only |
| [Bamboo](https://www.atlassian.com/software/bamboo) | `coming soon` | |
Expand All @@ -96,6 +96,7 @@ after_success:
| [Solano Labs](https://www.solanolabs.com/) | `coming soon` | |
| [Travis CI](https://travis-ci.org/) | Yes [![Build Status](https://secure.travis-ci.org/codecov/codecov-python.svg?branch=master)](https://travis-ci.org/codecov/codecov-python) | Private only |
| [Wercker](http://wercker.com/) | Yes | Public & Private |
| [Cirrus CI](https://cirrus-ci.org/) | Yes | Private only |
| Git / Mercurial | Yes (as a fallback) | Public & Private |


Expand Down
21 changes: 20 additions & 1 deletion codecov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def main(*argv, **kwargs):
"--token",
"-t",
default=os.getenv("CODECOV_TOKEN"),
help="Private repository token or @filename for file containing the token. Defaults to $CODECOV_TOKEN. Not required for public repositories on Travis CI, CircleCI and AppVeyor",
help="Private repository token or @filename for file containing the token. Defaults to $CODECOV_TOKEN. Not required for public repositories on Travis CI, CircleCI, AppVeyor and CirrusCI",
)
basics.add_argument(
"--file",
Expand Down Expand Up @@ -845,6 +845,25 @@ def main(*argv, **kwargs):

write(" GitHub Actions CI Detected")

# ---------
# Cirrus CI
# ---------
elif os.getenv("CIRRUS_CI"):
# https://cirrus-ci.org/guide/writing-tasks/#environment-variables
query.update(
dict(
service="cirrus-ci",
slug=os.getenv("CIRRUS_REPO_FULL_NAME"),
branch=os.getenv("CIRRUS_BRANCH"),
pr=os.getenv("CIRRUS_PR"),
commit=os.getenv("CIRRUS_CHANGE_IN_REPO"),
build=os.getenv("CIRRUS_BUILD_ID"),
build_url="https://cirrus-ci.com/task/" + os.getenv("CIRRUS_TASK_ID"),
job=os.getenv("CIRRUS_TASK_NAME"),
)
)
write(" Cirrus CI Detected")

else:
query.update(
dict(
Expand Down
31 changes: 31 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,37 @@ def test_ci_github(self):
self.assertEqual(res["codecov"].token, "token")
self.assertEqual(res["codecov"].name, "name")

@unittest.skipUnless(
os.getenv("CI") == "true" and os.getenv("CIRRUS_CI") == "true",
"Skip Cirrus CI",
)
def test_ci_cirrus(self):
# The data used in this test follows the test case data in
# https://github.com/codecov/codecov-bash/pull/127
# Discussion about using codecov without token for Cirrus CI can be seen in:
# https://community.codecov.com/t/add-support-of-uploading-from-cirrus-ci-without-token/1028/36
self.set_env(
HOME="/",
CIRRUS_CI="true",
CIRRUS_REPO_FULL_NAME="codecov/ci-repo",
CIRRUS_BRANCH="master",
CIRRUS_PR="1",
CIRRUS_CHANGE_IN_REPO="180c0d097354fc1a451da8a3be5aba255f2ffd9f",
CIRRUS_BUILD_ID="777",
CIRRUS_TASK_ID="239",
CIRRUS_TASK_NAME="test"
)
self.fake_report()
res = self.run_cli()
self.assertEqual(res["query"]["service"], "cirrus-ci")
self.assertEqual(res["query"]["slug"], "codecov/ci-repo")
self.assertEqual(res["query"]["branch"], "master")
self.assertEqual(res["query"]["pr"], "1")
self.assertEqual(res["query"]["commit"], os.getenv("CIRRUS_CHANGE_IN_REPO"))
self.assertEqual(res["query"]["build"], "777")
self.assertEqual(res["query"]["build_url"], "https://cirrus-ci.com/task/239")
self.assertEqual(res["query"]["job"], "test")

@unittest.skip("Skip CI None")
def test_ci_none(self):
self.set_env(CODECOV_TOKEN="token", CODECOV_NAME="name")
Expand Down

0 comments on commit 27a9833

Please sign in to comment.