Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Sphinx build log in CI #55

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:])