Skip to main content

check-typed-output.yml

Flags typed (“faked”) code output in Quarto sources. A page that shows what code prints should get that output by running the code, in an executable {r} or {python} chunk, so the page cannot show a value the code no longer produces. The check flags the two shapes that stand in for a run:

Each finding is reported as file:line with the matched text, as a warning annotation by default.

Two scopes are available. By default the check scans every tracked file its globs match, which measures how much typed output a repository carries. With diff-scoped: true, a pull-request run reports only findings on lines the pull request adds (for an output block, any added line of the block), diffed from the merge base with the PR base, the same anchor check-new-line-breaks.yml uses. A repository with legacy occurrences can then adopt the check and see only what each PR adds. A finding whose lines the same diff also deletes, contiguously and in order, is treated as moved, so splitting a chapter into subfiles does not report the output it relocates. For an output block, those lines run from the code fence it follows through the block’s closing fence, so a short printed value such as 1 is not excused by an unrelated deletion of the same text. A diff-scoped run with no PR base, such as a push to main, is skipped with a warning rather than widened to the whole tree.

Inputs

Input Type Default Description
python-version string '3.x' Python version to set up.
patterns string '' Newline-separated Python regular expressions searched for in each line of a code fence. Replaces the default set (#\s*->, #\s*=>, #>, #\s*(?i:output):); empty uses the defaults. An invalid expression fails the run rather than being skipped.
globs string '*.qmd' Space-separated git pathspecs of tracked files to check (recursive by default).
paths-ignore string '' Comma- or newline-separated glob patterns (relative paths) to skip; supports *, ?, and recursive **.
fail boolean false Fail the workflow when typed output is found; otherwise findings are warnings only.
diff-scoped boolean false Report only lines a pull request adds. Skipped with a warning on a run with no PR base.
runs-on string empty (CI_RUNNER variable, else ubuntu-latest) Runner label for the job. Use a self-hosted label only for a private repository; never for a public one, whose pull requests can run arbitrary code on it (#1167).

Permissions

Only contents: read (the default), so no permissions: block is needed.

Example

# Copy to .github/workflows/check-typed-output.yml in your repo.
# Flags typed ("faked") code output in .qmd files: a `# ->` / `#>` / `# Output:`
# comment standing in for a printed value inside a code fence, and a
# hand-written ```text output block right after a code fence. Show output by
# running the code in an executable {r}/{python} chunk instead.
# Warn-only by default; set diff-scoped: true so a repo with legacy
# occurrences sees only what each PR adds.
# Only contents:read is needed (the default), so no permissions block is required.
name: Check for typed code output

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  check:
    uses: Morrison-Lab/gha/.github/workflows/check-typed-output.yml@v3
    # with:
    #   globs: '*.qmd'                         # pathspecs to check (recursive)
    #   paths-ignore: 'chapters/outtakes/**'   # skip known-noisy paths
    #   fail: true                             # block instead of warn (defaults to false)
    #   diff-scoped: true                      # report only lines a PR adds
    #   patterns: |                            # replaces the default patterns
    #     #\s*->
    #     #>
    #   runs-on: private-runner                # self-hosted runner label (private repositories only)

See examples/check-typed-output.yml for the full caller stub.