Skip to content

Commit 983575a

Browse files
committed
Resolve #91 -- Add Github workflow message support for GitHub Actions
1 parent 0146df5 commit 983575a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

relint/__main__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import argparse
2+
import os
23
import subprocess # nosec
34
import sys
45
import warnings
56

67
from rich.progress import track
78

89
from relint.config import load_config
9-
from relint.parse import lint_file, match_with_diff_changes, parse_diff, print_culprits
10+
from relint.parse import lint_file, match_with_diff_changes, parse_diff, print_culprits, \
11+
print_github_actions_output
1012

1113

1214
def parse_args(args=None):
@@ -90,7 +92,11 @@ def main(args=None):
9092
changed_content = parse_diff(output)
9193
matches = match_with_diff_changes(changed_content, matches)
9294

93-
exit_code = print_culprits(matches, args)
95+
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"
96+
if GITHUB_ACTIONS:
97+
exit_code = print_github_actions_output(matches, args)
98+
else:
99+
exit_code = print_culprits(matches, args)
94100
exit(exit_code)
95101

96102

relint/parse.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import collections
4+
import os
45

56
try:
67
import regex as re
@@ -93,6 +94,20 @@ def split_diff_content_by_filename(output: str) -> {str: str}:
9394
return content_by_filename
9495

9596

97+
def print_github_actions_output(matches, args):
98+
exit_code = 0
99+
for filename, test, match, line_number in matches:
100+
exit_code = test.error if exit_code == 0 else exit_code
101+
start_line_no = match.string[: match.start()].count("\n") + 1
102+
end_line_no = match.string[: match.end()].count("\n") + 1
103+
104+
print(
105+
f"::{'error' if test.error else 'warning'} file={filename},line={start_line_no},endLine={end_line_no},title={test.name}::{test.hint}".replace("\n", "%0A")
106+
)
107+
return exit_code
108+
109+
110+
96111
def print_culprits(matches, args):
97112
exit_code = 0
98113
messages = []

0 commit comments

Comments
 (0)