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

Added GitHub Actions CI detection. #265

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions codecov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,33 @@ def main(*argv, **kwargs):

write(" Gitlab CI Detected")

# --------------
# GitHub Actions
# --------------
elif os.getenv("GITHUB_ACTION"):
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
query.update(
dict(
service="github",
build=os.getenv("GITHUB_RUN_ID"),
commit=os.getenv("GITHUB_SHA"),
slug=os.getenv("GITHUB_REPOSITORY"),
build_url="http://github.com/"
+ os.getenv("GITHUB_REPOSITORY")
+ "/actions/runs/"
+ os.getenv("GITHUB_RUN_ID"),
)
)

if os.getenv("GITHUB_REF"):
query["branch"] = os.getenv("GITHUB_REF").split("/", 3)[-1]
if os.getenv("GITHUB_HEAD_REF"):
# PR refs are in the format: refs/pull/7/merge
query["pr"] = os.getenv("GITHUB_REF").split("/")[-2]
query["branch"] = os.getenv("GITHUB_HEAD_REF")

write(" GitHub Actions CI Detected")

else:
query.update(
dict(
Expand Down
28 changes: 28 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ def test_ci_gitlab(self):
HOME="/",
CI_PROJECT_DIR=os.getcwd().strip("/"),
CODECOV_TOKEN="token",
CODECOV_NAME="name",
)
self.fake_report()
res = self.run_cli()
Expand All @@ -869,6 +870,33 @@ def test_ci_gitlab(self):
self.assertEqual(res["query"]["build"], "1399372237")
self.assertEqual(res["query"]["slug"], "owner/repo")
self.assertEqual(res["codecov"].token, "token")
self.assertEqual(res["codecov"].name, "name")

@unittest.skipUnless(
os.getenv("CI") == "true" and os.getenv("GITHUB_ACTION"),
"Skip GitHub Actions CI test",
)
def test_ci_github(self):
self.set_env(
GITHUB_REF="master",
GITHUB_RUN_ID="1399372237",
GITHUB_REPOSITORY="owner/repo",
GITHUB_ACTION="6de813bb999760c81f96f3cf5dbdcd51cead172f",
GITHUB_SHA="d653b934ed59c1a785cc1cc79d08c9aaa4eba73b",
HOME="/",
CODECOV_TOKEN="token",
CODECOV_NAME="name",
)
self.fake_report()
res = self.run_cli()
self.assertEqual(res["query"]["service"], "github")
self.assertEqual(
res["query"]["commit"], "d653b934ed59c1a785cc1cc79d08c9aaa4eba73b"
)
self.assertEqual(res["query"]["build"], "1399372237")
self.assertEqual(res["query"]["slug"], "owner/repo")
self.assertEqual(res["codecov"].token, "token")
self.assertEqual(res["codecov"].name, "name")

@unittest.skip("Skip CI None")
def test_ci_none(self):
Expand Down