Skip to content

Commit 9147c08

Browse files
Use lowercase for outputs
1 parent dfb500d commit 9147c08

File tree

5 files changed

+95
-103
lines changed

5 files changed

+95
-103
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -352,35 +352,35 @@ The action makes available some data for downstream processing.
352352
353353
| Name | Description |
354354
| --- | --- |
355-
| `ACTIVITY_RUN` | The type of activity that was run. One of `process_pr`, `post_comment`, `save_coverage_data_files`. |
355+
| `activity_run` | The type of activity that was run. One of `process_pr`, `post_comment`, `save_coverage_data_files`. |
356356

357357
All the following outputs are only available when running in PR mode.
358358

359359
| Name | Description |
360360
| --- | --- |
361-
| `COMMENT_FILE_WRITTEN` | A boolean indicating whether a comment file was written to `COMMENT_FILENAME` or not. |
362-
| `NEW_COVERED_LINES` | The number of covered lines in the pull request. |
363-
| `NEW_NUM_STATEMENTS` | The number of statements in the pull request. |
364-
| `NEW_PERCENT_COVERED` | The coverage percentage of the pull request. |
365-
| `NEW_MISSING_LINES` | The number of lines with missing coverage in the pull request. |
366-
| `NEW_EXCLUDED_LINES` | The number of excluded lines in the pull request. |
367-
| `NEW_NUM_BRANCHES` | The number of branches in the pull request. |
368-
| `NEW_NUM_PARTIAL_BRANCHES` | The number of partial branches in the pull request. |
369-
| `NEW_COVERED_BRANCHES` | The number of covered branches in the pull request. |
370-
| `NEW_MISSING_BRANCHES` | The number of branches with missing coverage in the pull request. |
371-
| `REFERENCE_COVERED_LINES` | The number of covered lines in the base branch. |
372-
| `REFERENCE_NUM_STATEMENTS` | The number of statements in the base branch. |
373-
| `REFERENCE_PERCENT_COVERED` | The coverage percentage of the base branch. |
374-
| `REFERENCE_MISSING_LINES` | The number of lines with missing coverage in the base branch. |
375-
| `REFERENCE_EXCLUDED_LINES` | The number of excluded lines in the base branch. |
376-
| `REFERENCE_NUM_BRANCHES` | The number of branches in the base branch. |
377-
| `REFERENCE_NUM_PARTIAL_BRANCHES` | The number of partial branches in the base branch. |
378-
| `REFERENCE_COVERED_BRANCHES` | The number of covered branches in the base branch. |
379-
| `REFERENCE_MISSING_BRANCHES` | The number of branches with missing coverage in the base branch. |
380-
| `DIFF_TOTAL_NUM_LINES` | The total number of lines in the diff. |
381-
| `DIFF_TOTAL_NUM_VIOLATIONS` | The total number of lines with missing coverage in the diff. |
382-
| `DIFF_TOTAL_PERCENT_COVERED` | The coverage percentage of the diff. |
383-
| `DIFF_NUM_CHANGED_LINES` | The number of changed lines in the diff. |
361+
| `comment_file_written` | A boolean indicating whether a comment file was written to `COMMENT_FILENAME` or not. |
362+
| `new_covered_lines` | The number of covered lines in the pull request. |
363+
| `new_num_statements` | The number of statements in the pull request. |
364+
| `new_percent_covered` | The coverage percentage of the pull request. |
365+
| `new_missing_lines` | The number of lines with missing coverage in the pull request. |
366+
| `new_excluded_lines` | The number of excluded lines in the pull request. |
367+
| `new_num_branches` | The number of branches in the pull request. |
368+
| `new_num_partial_branches` | The number of partial branches in the pull request. |
369+
| `new_covered_branches` | The number of covered branches in the pull request. |
370+
| `new_missing_branches` | The number of branches with missing coverage in the pull request. |
371+
| `reference_covered_lines` | The number of covered lines in the base branch. |
372+
| `reference_num_statements` | The number of statements in the base branch. |
373+
| `reference_percent_covered` | The coverage percentage of the base branch. |
374+
| `reference_missing_lines` | The number of lines with missing coverage in the base branch. |
375+
| `reference_excluded_lines` | The number of excluded lines in the base branch. |
376+
| `reference_num_branches` | The number of branches in the base branch. |
377+
| `reference_num_partial_branches` | The number of partial branches in the base branch. |
378+
| `reference_covered_branches` | The number of covered branches in the base branch. |
379+
| `reference_missing_branches` | The number of branches with missing coverage in the base branch. |
380+
| `diff_total_num_lines` | The total number of lines in the diff. |
381+
| `diff_total_num_violations` | The total number of lines with missing coverage in the diff. |
382+
| `diff_total_percent_covered` | The coverage percentage of the diff. |
383+
| `diff_num_changed_lines` | The number of changed lines in the diff. |
384384

385385
Usage may look like this
386386

@@ -392,7 +392,7 @@ Usage may look like this
392392
GITHUB_TOKEN: ${{ github.token }}
393393
394394
- name: Enforce coverage
395-
if: ${{ steps.coverage_comment.outputs.NEW_PERCENT_COVERED < steps.coverage_comment.outputs.REFERENCE_PERCENT_COVERED }}
395+
if: ${{ steps.coverage_comment.outputs.new_percent_covered < steps.coverage_comment.outputs.reference_percent_covered }}
396396
run: echo "Coverage decreased." && exit 1
397397
```
398398

action.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,58 +111,58 @@ inputs:
111111
Deprecated, see https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
112112
default: false
113113
outputs:
114-
ACTIVITY_RUN:
114+
activity_run:
115115
description: >
116116
The type of activity that was run. One of `process_pr`, `post_comment`, `save_coverage_data_files`.
117-
COMMENT_FILE_WRITTEN:
117+
comment_file_written:
118118
description: >
119119
A boolean indicating whether a comment file was written to COMMENT_FILENAME or not.
120120
If so, you'll need to run the action in workflow_run mode to post it. If "false",
121121
no comment file was written (likely because the comment was already posted to the PR).
122122
Only available when running in PR mode.
123-
NEW_COVERED_LINES:
123+
new_covered_lines:
124124
description: The number of covered lines in the pull request. (Only available in PR mode)
125-
NEW_NUM_STATEMENTS:
125+
new_num_statements:
126126
description: The number of statements in the pull request. (Only available in PR mode)
127-
NEW_PERCENT_COVERED:
127+
new_percent_covered:
128128
description: The coverage percentage of the pull request. (Only available in PR mode)
129-
NEW_MISSING_LINES:
129+
new_missing_lines:
130130
description: The number of lines with missing coverage in the pull request. (Only available in PR mode)
131-
NEW_EXCLUDED_LINES:
131+
new_excluded_lines:
132132
description: The number of excluded lines in the pull request. (Only available in PR mode)
133-
NEW_NUM_BRANCHES:
133+
new_num_branches:
134134
description: The number of branches in the pull request. (Only available in PR mode)
135-
NEW_NUM_PARTIAL_BRANCHES:
135+
new_num_partial_branches:
136136
description: The number of partial branches in the pull request. (Only available in PR mode)
137-
NEW_COVERED_BRANCHES:
137+
new_covered_branches:
138138
description: The number of covered branches in the pull request. (Only available in PR mode)
139-
NEW_MISSING_BRANCHES:
139+
new_missing_branches:
140140
description: The number of branches with missing coverage in the pull request. (Only available in PR mode)
141-
REFERENCE_COVERED_LINES:
141+
reference_covered_lines:
142142
description: The number of covered lines in the base branch. (Only available in PR mode)
143-
REFERENCE_NUM_STATEMENTS:
143+
reference_num_statements:
144144
description: The number of statements in the base branch. (Only available in PR mode)
145-
REFERENCE_PERCENT_COVERED:
145+
reference_percent_covered:
146146
description: The coverage percentage of the base branch. (Only available in PR mode)
147-
REFERENCE_MISSING_LINES:
147+
reference_missing_lines:
148148
description: The number of lines with missing coverage in the base branch. (Only available in PR mode)
149-
REFERENCE_EXCLUDED_LINES:
149+
reference_excluded_lines:
150150
description: The number of excluded lines in the base branch. (Only available in PR mode)
151-
REFERENCE_NUM_BRANCHES:
151+
reference_num_branches:
152152
description: The number of branches in the base branch. (Only available in PR mode)
153-
REFERENCE_NUM_PARTIAL_BRANCHES:
153+
reference_num_partial_branches:
154154
description: The number of partial branches in the base branch. (Only available in PR mode)
155-
REFERENCE_COVERED_BRANCHES:
155+
reference_covered_branches:
156156
description: The number of covered branches in the base branch. (Only available in PR mode)
157-
REFERENCE_MISSING_BRANCHES:
157+
reference_missing_branches:
158158
description: The number of branches with missing coverage in the base branch. (Only available in PR mode)
159-
DIFF_TOTAL_NUM_LINES:
159+
diff_total_num_lines:
160160
description: The total number of lines in the diff. (Only available in PR mode)
161-
DIFF_TOTAL_NUM_VIOLATIONS:
161+
diff_total_num_violations:
162162
description: The total number of lines with missing coverage in the diff. (Only available in PR mode)
163-
DIFF_TOTAL_PERCENT_COVERED:
163+
diff_total_percent_covered:
164164
description: The coverage percentage of the diff. (Only available in PR mode)
165-
DIFF_NUM_CHANGED_LINES:
165+
diff_num_changed_lines:
166166
description: The number of changed lines in the diff. (Only available in PR mode)
167167
runs:
168168
using: docker

coverage_comment/coverage.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ class CoverageMetadata:
2121
show_contexts: bool
2222

2323

24+
class OutputMixin:
25+
def as_output(self, prefix: str) -> dict:
26+
data = dataclasses.asdict(self)
27+
output = {}
28+
for key, value in data.items():
29+
if value is not None and not isinstance(value, dict):
30+
output[f"{prefix}_{key}"] = (
31+
float(value) if isinstance(value, decimal.Decimal) else value
32+
)
33+
return output
34+
35+
2436
@dataclasses.dataclass(kw_only=True)
25-
class CoverageInfo:
37+
class CoverageInfo(OutputMixin):
2638
covered_lines: int
2739
num_statements: int
2840
percent_covered: decimal.Decimal
@@ -33,16 +45,6 @@ class CoverageInfo:
3345
covered_branches: int = 0
3446
missing_branches: int = 0
3547

36-
def as_output(self, prefix: str) -> dict:
37-
data = dataclasses.asdict(self)
38-
output = {}
39-
for key, value in data.items():
40-
if value is not None:
41-
output[f"{prefix}_{key.upper()}"] = (
42-
float(value) if isinstance(value, decimal.Decimal) else value
43-
)
44-
return output
45-
4648

4749
@dataclasses.dataclass(kw_only=True)
4850
class FileCoverage:
@@ -86,23 +88,13 @@ def violation_lines(self) -> list[int]:
8688

8789

8890
@dataclasses.dataclass(kw_only=True)
89-
class DiffCoverage:
91+
class DiffCoverage(OutputMixin):
9092
total_num_lines: int
9193
total_num_violations: int
9294
total_percent_covered: decimal.Decimal
9395
num_changed_lines: int
9496
files: dict[pathlib.Path, FileDiffCoverage]
9597

96-
def as_output(self, prefix: str) -> dict:
97-
data = dataclasses.asdict(self)
98-
output = {}
99-
for key, value in data.items():
100-
if value is not None and not isinstance(value, dict):
101-
output[f"{prefix}_{key.upper()}"] = (
102-
float(value) if isinstance(value, decimal.Decimal) else value
103-
)
104-
return output
105-
10698

10799
def compute_coverage(
108100
num_covered: int,

coverage_comment/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ def process_pr(
268268
],
269269
)
270270

271-
outputs = {"ACTIVITY_RUN": "process_pr"}
272-
outputs |= coverage.info.as_output(prefix="NEW")
273-
outputs |= diff_coverage.as_output(prefix="DIFF")
271+
outputs = {"activity_run": "process_pr"}
272+
outputs |= coverage.info.as_output(prefix="new")
273+
outputs |= diff_coverage.as_output(prefix="diff")
274274
if previous_coverage:
275-
outputs |= previous_coverage.info.as_output(prefix="REFERENCE")
275+
outputs |= previous_coverage.info.as_output(prefix="reference")
276276

277277
try:
278278
if config.FORCE_WORKFLOW_RUN or not pr_number:
@@ -298,10 +298,10 @@ def process_pr(
298298
filename=config.FINAL_COMMENT_FILENAME,
299299
content=comment,
300300
)
301-
outputs |= {"COMMENT_FILE_WRITTEN": True}
301+
outputs["comment_file_written"] = True
302302
log.debug("Comment stored locally on disk")
303303
else:
304-
outputs |= {"COMMENT_FILE_WRITTEN": False}
304+
outputs["comment_file_written"] = False
305305
log.debug("Comment not generated")
306306

307307
github.set_output(
@@ -371,7 +371,7 @@ def post_comment(
371371
)
372372
log.info("Comment posted in PR")
373373

374-
github.set_output(github_output=config.GITHUB_OUTPUT, ACTIVITY_RUN="post_comment")
374+
github.set_output(github_output=config.GITHUB_OUTPUT, activity_run="post_comment")
375375
return 0
376376

377377

@@ -450,7 +450,7 @@ def save_coverage_data_files(
450450
log.info(log_message)
451451

452452
github.set_output(
453-
github_output=config.GITHUB_OUTPUT, ACTIVITY_RUN="save_coverage_data_files"
453+
github_output=config.GITHUB_OUTPUT, activity_run="save_coverage_data_files"
454454
)
455455

456456
return 0

tests/integration/test_main.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,34 @@ def get_expected_output(
6666
comment_written: bool, reference_coverage: bool
6767
) -> dict[str, str]:
6868
output = {
69-
"ACTIVITY_RUN": '"process_pr"',
70-
"COMMENT_FILE_WRITTEN": str(comment_written).lower(),
71-
"NEW_COVERED_LINES": "7",
72-
"NEW_NUM_STATEMENTS": "9",
73-
"NEW_PERCENT_COVERED": "0.7777777777777778",
74-
"NEW_MISSING_LINES": "2",
75-
"NEW_EXCLUDED_LINES": "0",
76-
"NEW_NUM_BRANCHES": "0",
77-
"NEW_NUM_PARTIAL_BRANCHES": "0",
78-
"NEW_COVERED_BRANCHES": "0",
79-
"NEW_MISSING_BRANCHES": "0",
80-
"DIFF_TOTAL_NUM_LINES": "4",
81-
"DIFF_TOTAL_NUM_VIOLATIONS": "1",
82-
"DIFF_TOTAL_PERCENT_COVERED": "0.75",
83-
"DIFF_NUM_CHANGED_LINES": "6",
69+
"activity_run": '"process_pr"',
70+
"comment_file_written": str(comment_written).lower(),
71+
"new_covered_lines": "7",
72+
"new_num_statements": "9",
73+
"new_percent_covered": "0.7777777777777778",
74+
"new_missing_lines": "2",
75+
"new_excluded_lines": "0",
76+
"new_num_branches": "0",
77+
"new_num_partial_branches": "0",
78+
"new_covered_branches": "0",
79+
"new_missing_branches": "0",
80+
"diff_total_num_lines": "4",
81+
"diff_total_num_violations": "1",
82+
"diff_total_percent_covered": "0.75",
83+
"diff_num_changed_lines": "6",
8484
}
8585
if reference_coverage:
8686
output.update(
8787
{
88-
"REFERENCE_COVERED_LINES": "3",
89-
"REFERENCE_NUM_STATEMENTS": "10",
90-
"REFERENCE_PERCENT_COVERED": "0.3",
91-
"REFERENCE_MISSING_LINES": "7",
92-
"REFERENCE_EXCLUDED_LINES": "0",
93-
"REFERENCE_NUM_BRANCHES": "0",
94-
"REFERENCE_NUM_PARTIAL_BRANCHES": "0",
95-
"REFERENCE_COVERED_BRANCHES": "0",
96-
"REFERENCE_MISSING_BRANCHES": "0",
88+
"reference_covered_lines": "3",
89+
"reference_num_statements": "10",
90+
"reference_percent_covered": "0.3",
91+
"reference_missing_lines": "7",
92+
"reference_excluded_lines": "0",
93+
"reference_num_branches": "0",
94+
"reference_num_partial_branches": "0",
95+
"reference_covered_branches": "0",
96+
"reference_missing_branches": "0",
9797
}
9898
)
9999
return output

0 commit comments

Comments
 (0)