Skip to content
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
79 changes: 69 additions & 10 deletions .github/workflows/azure-static-web-apps-lemon-flower-08f5ff603.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ on:
description: 'Force re-render executable posts'
type: boolean
default: false
raise_issues:
description: 'File render diagnostics as issues (main does this anyway)'
type: boolean
default: false
schedule:
# Weekly deployment - Sunday 19:00 UTC (GitHub Actions cron is always UTC).
# Note: UTC does not observe daylight saving, so this lands at 20:00 UK time
# during BST and 19:00 during GMT.
- cron: '0 19 * * 0'
push:
branches:
- main
Expand All @@ -19,22 +28,25 @@ on:
jobs:
render_site:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@v2
- name: Install GDebi first
run: sudo apt-get install gdebi-core
- name: Download the deb file
run: sudo curl -LO https://quarto.org/download/latest/quarto-linux-amd64.deb
- name: Install the deb file
run: sudo apt-get install -y ./quarto-linux-amd64.deb
- uses: actions/checkout@v4
- name: Setup Quarto (latest stable release)
uses: quarto-dev/quarto-actions/setup@v2
with:
version: release
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Jupyter
run: pip install jupyter
- name: Verify Install
run: /usr/local/bin/quarto check
run: |
quarto --version
quarto check
- name: Setup post venvs and re-render
if: inputs.rerender == true
run: |
Expand All @@ -54,17 +66,64 @@ jobs:
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }}
- name: render site
run: quarto render site/
id: render
# Keep the log so the steps below can turn Quarto's diagnostics into
# tickets. A failed render must still reach those steps, so the job is
# failed explicitly at the end rather than here.
continue-on-error: true
run: |
set -o pipefail
quarto render site/ 2>&1 | tee render.log
- name: Collect render diagnostics
run: |
python3 scripts/parse_render_log.py render.log \
${{ steps.render.outcome == 'failure' && '--render-failed' || '' }} \
> render-findings.json
cat render-findings.json
- name: Ensure render issue labels exist
if: github.ref == 'refs/heads/main' || inputs.raise_issues == true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh label create render-issue --force --color B60205 \
--description 'Raised automatically from a site render'
gh label create render-error --force --color D93F0B \
--description 'Render diagnostic: error'
gh label create render-warning --force --color FBCA04 \
--description 'Render diagnostic: warning'
gh label create automated --force --color C5DEF5 \
--description 'Opened by automation'
- name: Raise issues for render diagnostics
# The default branch files real tickets, as does a dispatch that asks
# for them; every other ref only reports what it would have filed, so
# branches cannot spam the tracker.
#
# The condition is phrased negatively on purpose. GitHub's && and ||
# yield operands rather than booleans, and '' is falsy, so the natural
# reading -- cond && '' || '--dry-run' -- collapses to '--dry-run' on
# both branches. Keep the non-empty value out of the falsy slot.
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRY_RUN: ${{ (github.ref != 'refs/heads/main' && inputs.raise_issues != true) && '--dry-run' || '' }}
run: python3 scripts/report_render_issues.py render-findings.json $DRY_RUN
- name: Output folder directories
run: ls
- name: Upload _site directory for deploy job
if: steps.render.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: site_deployment
path: site/_site
- name: Fail the job if the render failed
if: steps.render.outcome == 'failure'
run: |
echo "::error::quarto render failed - see the issues raised above"
exit 1
deploy_to_azure_static_webapp:
needs: render_site
if: success() && github.event.ref == 'refs/heads/main'
# github.ref (unlike github.event.ref) is populated for every event type, so
# scheduled and manually dispatched runs on main deploy as well as pushes.
if: success() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: Deploy to Azure App Service
steps:
Expand Down
132 changes: 132 additions & 0 deletions scripts/parse_render_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
"""Extract diagnostics from a `quarto render` log and emit them as JSON.

Quarto reports problems on stderr/stdout as it walks the document list, but a
green build hides them: the render succeeds and the warnings scroll away. This
parses the captured log, attributes each diagnostic to the document that was
being rendered at the time, and collapses repeats so the caller can raise one
ticket per distinct problem.

Usage: parse_render_log.py render.log [--render-failed] > findings.json
"""

import argparse
import hashlib
import json
import re
import sys

ANSI = re.compile(r"\x1b\[[0-9;]*[A-Za-z]")
# "[ 8/30] tips/Notebook/Customcellmagics.qmd" - the document Quarto is on.
DOC = re.compile(r"^\[\s*\d+\s*/\s*\d+\]\s+(?P<path>\S.*?)\s*$")
# "WARN: ...", "WARNING (/opt/quarto/.../main.lua:10090)", "ERROR: ..."
DIAG = re.compile(r"^(?P<sev>WARN|WARNING|ERROR)\b:?\s*(?P<rest>.*)$")
# Quarto embeds its own install paths and line numbers; they churn between
# versions and would otherwise fingerprint as a brand new problem each upgrade.
NOISE = re.compile(r"\((?:/|[A-Za-z]:\\)[^)]*?:\d+\)")

SEVERITY = {"WARN": "warning", "WARNING": "warning", "ERROR": "error"}


def normalise(message):
"""Strip version-dependent detail so the same problem fingerprints alike."""
message = NOISE.sub("", message)
message = re.sub(r"\s+", " ", message)
return message.strip(" :\t")


def parse(lines):
findings = {}
current_doc = None
index = 0

while index < len(lines):
line = ANSI.sub("", lines[index]).rstrip()

doc_match = DOC.match(line)
if doc_match:
current_doc = doc_match.group("path")
index += 1
continue

diag_match = DIAG.match(line)
if not diag_match:
index += 1
continue

severity = SEVERITY[diag_match.group("sev")]
parts = [diag_match.group("rest").strip()]

# A Quarto warning header is often bare, with the actual complaint on
# the following lines. Keep reading until the next document or
# diagnostic, tolerating the blank line Quarto puts mid-message.
lookahead = index + 1
blanks = 0
while lookahead < len(lines):
nxt = ANSI.sub("", lines[lookahead]).rstrip()
if not nxt.strip():
blanks += 1
if blanks > 1:
break
lookahead += 1
continue
if DOC.match(nxt) or DIAG.match(nxt) or nxt.startswith("Output created:"):
break
parts.append(nxt.strip())
lookahead += 1
index = lookahead

message = normalise(" ".join(p for p in parts if p))
if not message:
continue

document = current_doc or "(site)"
fingerprint = hashlib.sha1(
f"{document}\n{message}".encode("utf-8")
).hexdigest()[:12]

if fingerprint in findings:
findings[fingerprint]["occurrences"] += 1
else:
findings[fingerprint] = {
"fingerprint": fingerprint,
"severity": severity,
"document": document,
"message": message,
"occurrences": 1,
}

return list(findings.values())


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("log", help="captured `quarto render` output")
parser.add_argument(
"--render-failed",
action="store_true",
help="the render itself exited non-zero; ensure that is reported even "
"if no line matched",
)
args = parser.parse_args()

with open(args.log, encoding="utf-8", errors="replace") as handle:
findings = parse(handle.read().splitlines())

if args.render_failed and not any(f["severity"] == "error" for f in findings):
findings.append({
"fingerprint": "render-failed",
"severity": "error",
"document": "(site)",
"message": "quarto render exited non-zero without a parseable error "
"line; see the workflow log",
"occurrences": 1,
})

findings.sort(key=lambda f: (f["severity"] != "error", f["document"], f["message"]))
json.dump(findings, sys.stdout, indent=2)
sys.stdout.write("\n")


if __name__ == "__main__":
main()
Loading
Loading