Skip to content

Commit

Permalink
Merge pull request #55 from cps-org/scrape-sphinx-logs
Browse files Browse the repository at this point in the history
Check Sphinx build log in CI
  • Loading branch information
mwoehlke authored Apr 18, 2024
2 parents f1d0969 + 67770ba commit 454cda8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
outputs:
check_result: ${{steps.check.outputs.result}}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,7 +22,10 @@ jobs:
- name: Install Environment
run: make setup
- name: Build Documentation
run: make html/fast
run: make html/fast LOGFILE=_build_html.log
- name: Parse Build Logs
id: check
run: python check-build-logs.py _build_html.log "$GITHUB_OUTPUT"
- name: Archive Documentation
run: make archive/fast
- name: Upload Archive
Expand All @@ -29,6 +34,15 @@ jobs:
if-no-files-found: error
name: github-pages
path: ${{github.workspace}}/cps-docs.tar
check:
runs-on: ubuntu-latest
needs: build
steps:
- name: Check Build Logs
env:
RESULT: ${{needs.build.outputs.check_result}}
run: |
exit $RESULT
deploy:
if: github.event.repository.default_branch == github.ref_name
needs: build
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ endif
setup.flags += --with=docs

build.flags += $(if $(BUILDER),-b $(BUILDER),-b html)
build.flags += $(if $(LOGFILE),-w "$(LOGFILE)")
build.flags += $(if $(NOCOLOR),,--color)
build.flags += $(SPHINXOPTS)

Expand Down
48 changes: 48 additions & 0 deletions check-build-logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python

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):
re_loc = r'(?P<file>[^:]+):((?P<line>[0-9]+):)?\s*'
re_info = r'(?P<type>\w+):\s*(?P<message>.*)'
lines = read_log(log_path)

result = 0
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': m.group('file')}
line = m.group('line')
if line:
params['line'] = line

p = ','.join([f'{k}={v}' for k, v in params.items()])
m = m.group('message')
print(f'::{t} {p}::{m}')
result = 1

with open(out_path, 'at') as f:
f.write(f'result={result}\n')

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if __name__ == '__main__':
main(*sys.argv[1:])

0 comments on commit 454cda8

Please sign in to comment.