Skip to content

Commit 578bbbf

Browse files
Initial commit
0 parents  commit 578bbbf

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed

.deepsource.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version = 1
2+
3+
[[analyzers]]
4+
name = 'python'
5+
enabled = true
6+
7+
[analyzers.meta]
8+
max_line_length = 100
9+
skip_doc_coverage = ["module", "magic", "class"]
10+
runtime_version = '3.x.x'
11+
12+
[[analyzers]]
13+
name = "docker"
14+
enabled = true
15+
16+
[[transformers]]
17+
name = 'black'
18+
enabled = true

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.py]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[Makefile]
16+
indent_style = tab
17+
18+
[*.md]
19+
trim_trailing_whitespace = false

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.8.5-slim-buster
2+
ENV PYTHONPATH /app
3+
ENV PYTHONUNBUFFERED 1
4+
ENV PYTHONDONTWRITEBYTECODE 1
5+
6+
ADD . /app
7+
WORKDIR /app
8+
9+
# install curl
10+
RUN apt-get update
11+
RUN apt-get install -y curl git
12+
13+
# download the DeepSource CLI binary
14+
RUN curl https://deepsource.io/cli | sh
15+
RUN ["chmod", "777", "/app/main.py"]
16+
17+
CMD ["/app/main.py"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 DeepSource Corp.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# DeepSource Test Coverage Action
2+
3+
[![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/deepsourcelabs/test-coverage-action/?ref=repository-badge)
4+
5+
GitHub Action that enables you to upload your test coverage data to DeepSource easily.
6+
7+
## License
8+
9+
This project is released under the [MIT License](LICENSE).

action.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'DeepSource Test Coverage Action'
2+
description: 'GitHub Action that uploads test coverage reports to DeepSource for the Test Coverage analyzer.'
3+
author: 'Sanket Saurav <[email protected]>'
4+
inputs:
5+
key:
6+
description: 'Programming language shortcode for which coverage is reported. Allowed values are — python, go'
7+
required: true
8+
coverage-file:
9+
description: 'Path to the coverage data file. e.g. ./coverage.xml'
10+
required: true
11+
dsn:
12+
description: 'DeepSource DSN of this repository. It is available under Settings → Reporting tab of the repository page on DeepSource.'
13+
required: true
14+
fail-ci-on-error:
15+
description: 'Should the CI build fail if there is an error while uploading the report to DeepSource? Allowed values are — true, false'
16+
default: false
17+
branding:
18+
color: 'green'
19+
icon: 'umbrella'
20+
runs:
21+
using: 'docker'
22+
image: 'Dockerfile'

main.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import os
4+
import subprocess
5+
import sys
6+
7+
# input for the actions are converted to names of a specific format by GitHub
8+
INPUT_KEYS_MAP = {
9+
"key": "INPUT_KEY",
10+
"coverage_file": "INPUT_COVERAGE-FILE",
11+
"dsn": "INPUT_DSN",
12+
"fail_ci_on_error": "INPUT_FAIL-CI-ON-ERROR",
13+
}
14+
15+
DEEPSOURCE_CLI_PATH = "/app/bin/deepsource"
16+
17+
DEEPSOURCE_TEST_COVERAGE_ANALYZER_SHORTCODE = "test-coverage"
18+
19+
GITHUB_WORKSPACE_PATH = os.environ.get('GITHUB_WORKSPACE')
20+
21+
def main() -> None:
22+
"""
23+
Get the metadata required for invoking DeepSource CLI from the environment
24+
and invoke the CLI to report the test coverage.
25+
Optionally, fail with a non-zero exit code if the user has configured so.
26+
"""
27+
28+
input_data = {key: os.getenv(value) for key, value in INPUT_KEYS_MAP.items()}
29+
30+
command = [
31+
DEEPSOURCE_CLI_PATH,
32+
"report",
33+
"--analyzer",
34+
DEEPSOURCE_TEST_COVERAGE_ANALYZER_SHORTCODE,
35+
"--key",
36+
input_data["key"],
37+
"--value-file",
38+
input_data["coverage_file"],
39+
]
40+
41+
# change the current working directory to the GitHub repository's context
42+
os.chdir(GITHUB_WORKSPACE_PATH)
43+
44+
process = subprocess.run(
45+
command,
46+
env=dict(os.environ, DEEPSOURCE_DSN=input_data["dsn"]),
47+
capture_output=True,
48+
)
49+
50+
if process.returncode != 0:
51+
if input_data["fail_ci_on_error"] == "true":
52+
print(f"::error file:main.py::{process.stdout}")
53+
sys.exit(1)
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)