diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index fa80f7b..1a26145 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -7,6 +7,8 @@ on: jobs: build: runs-on: ubuntu-latest + outputs: + buildlog: ${{steps.check.outputs.messages}} steps: - name: Checkout uses: actions/checkout@v4 @@ -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 @@ -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 Sphinx logs + shell: bash + run: | + echo -e "${{needs.check.outputs.messages}}" + [ -z "${{needs.check.outputs.messages}}" ] deploy: if: github.event.repository.default_branch == github.ref_name needs: build diff --git a/Makefile b/Makefile index 4467f60..a3a565c 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/check-build-logs.py b/check-build-logs.py new file mode 100755 index 0000000..883471a --- /dev/null +++ b/check-build-logs.py @@ -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[^:]+):((?P[0-9]+):)?\s*' + re_info = r'(?P\w+):\s*(?P.*)' + 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:])