Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 27a9833

Browse files
authored
Add Cirrus CI (#322)
* 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
1 parent 51469b0 commit 27a9833

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ after_success:
7979
8080
8181
## CI Providers
82-
| Company | Supported | Token Required |
82+
| Company | Supported | Token Required |
8383
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
8484
| [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 |
8585
| [Bamboo](https://www.atlassian.com/software/bamboo) | `coming soon` | |
@@ -96,6 +96,7 @@ after_success:
9696
| [Solano Labs](https://www.solanolabs.com/) | `coming soon` | |
9797
| [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 |
9898
| [Wercker](http://wercker.com/) | Yes | Public & Private |
99+
| [Cirrus CI](https://cirrus-ci.org/) | Yes | Private only |
99100
| Git / Mercurial | Yes (as a fallback) | Public & Private |
100101

101102

codecov/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def main(*argv, **kwargs):
329329
"--token",
330330
"-t",
331331
default=os.getenv("CODECOV_TOKEN"),
332-
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",
332+
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",
333333
)
334334
basics.add_argument(
335335
"--file",
@@ -845,6 +845,25 @@ def main(*argv, **kwargs):
845845

846846
write(" GitHub Actions CI Detected")
847847

848+
# ---------
849+
# Cirrus CI
850+
# ---------
851+
elif os.getenv("CIRRUS_CI"):
852+
# https://cirrus-ci.org/guide/writing-tasks/#environment-variables
853+
query.update(
854+
dict(
855+
service="cirrus-ci",
856+
slug=os.getenv("CIRRUS_REPO_FULL_NAME"),
857+
branch=os.getenv("CIRRUS_BRANCH"),
858+
pr=os.getenv("CIRRUS_PR"),
859+
commit=os.getenv("CIRRUS_CHANGE_IN_REPO"),
860+
build=os.getenv("CIRRUS_BUILD_ID"),
861+
build_url="https://cirrus-ci.com/task/" + os.getenv("CIRRUS_TASK_ID"),
862+
job=os.getenv("CIRRUS_TASK_NAME"),
863+
)
864+
)
865+
write(" Cirrus CI Detected")
866+
848867
else:
849868
query.update(
850869
dict(

tests/test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,37 @@ def test_ci_github(self):
879879
self.assertEqual(res["codecov"].token, "token")
880880
self.assertEqual(res["codecov"].name, "name")
881881

882+
@unittest.skipUnless(
883+
os.getenv("CI") == "true" and os.getenv("CIRRUS_CI") == "true",
884+
"Skip Cirrus CI",
885+
)
886+
def test_ci_cirrus(self):
887+
# The data used in this test follows the test case data in
888+
# https://github.com/codecov/codecov-bash/pull/127
889+
# Discussion about using codecov without token for Cirrus CI can be seen in:
890+
# https://community.codecov.com/t/add-support-of-uploading-from-cirrus-ci-without-token/1028/36
891+
self.set_env(
892+
HOME="/",
893+
CIRRUS_CI="true",
894+
CIRRUS_REPO_FULL_NAME="codecov/ci-repo",
895+
CIRRUS_BRANCH="master",
896+
CIRRUS_PR="1",
897+
CIRRUS_CHANGE_IN_REPO="180c0d097354fc1a451da8a3be5aba255f2ffd9f",
898+
CIRRUS_BUILD_ID="777",
899+
CIRRUS_TASK_ID="239",
900+
CIRRUS_TASK_NAME="test"
901+
)
902+
self.fake_report()
903+
res = self.run_cli()
904+
self.assertEqual(res["query"]["service"], "cirrus-ci")
905+
self.assertEqual(res["query"]["slug"], "codecov/ci-repo")
906+
self.assertEqual(res["query"]["branch"], "master")
907+
self.assertEqual(res["query"]["pr"], "1")
908+
self.assertEqual(res["query"]["commit"], os.getenv("CIRRUS_CHANGE_IN_REPO"))
909+
self.assertEqual(res["query"]["build"], "777")
910+
self.assertEqual(res["query"]["build_url"], "https://cirrus-ci.com/task/239")
911+
self.assertEqual(res["query"]["job"], "test")
912+
882913
@unittest.skip("Skip CI None")
883914
def test_ci_none(self):
884915
self.set_env(CODECOV_TOKEN="token", CODECOV_NAME="name")

0 commit comments

Comments
 (0)