-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to parse a Sphinx build log and turn it into GitHub Actions formatted messages. Add ability to specify a build log output location to Makefile. Use these to scrape the Sphinx build log in order to report whether there are any warnings or errors encountered during HTML generation. This uses job outputs to avoid having to upload the build log as an artifact. Note however that this has a 1MB size limit. For now, this should be fine, especially as only warnings/errors are passed this way (not the entire build log).
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import re | ||
import sys | ||
|
||
from typing import List | ||
|
||
# ----------------------------------------------------------------------------- | ||
def read_log(path: str) -> List[str]: | ||
out = [] | ||
|
||
with open(path, 'rt') as f: | ||
for line in f: | ||
out.append(re.sub('\033[[][0-9;]*m', '', line.strip())) | ||
|
||
return out | ||
|
||
# ----------------------------------------------------------------------------- | ||
def main(log_path: str, out_path: str, src_root: str = '.'): | ||
re_loc = r'(?P<file>[^:]+):((?P<line>[0-9]+):)?\s*' | ||
re_info = r'(?P<type>\w+):\s*(?P<message>.*)' | ||
lines = read_log(log_path) | ||
|
||
messages = [] | ||
for line in lines: | ||
m = re.match(re_loc + re_info, line) | ||
if m: | ||
t = m.group('type').lower() | ||
if t not in {'warning', 'error'}: | ||
t = 'warning' | ||
|
||
params = {'file': os.path.relpath(m.group('file'), src_root)} | ||
line = m.group('line') | ||
if line: | ||
params['line'] = line | ||
|
||
p = ','.join([f'{k}={v}' for k, v in params.items()]) | ||
m = m.group('message') | ||
messages.append(f'::{t} {p}::{m}') | ||
|
||
if len(messages): | ||
print(messages) | ||
s = '\\n'.join([m.replace('\\', '\\\\') for m in messages]) | ||
with open(out_path, 'at') as f: | ||
f.write(f'messages={s}\n') | ||
|
||
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
if __name__ == '__main__': | ||
main(*sys.argv[1:]) |