beamte 0.1.0

Test-quality rules over treebank trees. Trees in, findings out.
Documentation
name: ci

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  # What a pull request touched decides what the rest of this file runs. On a
  # push there is no base to compare against, so everything counts as changed
  # and main is gated on the whole file exactly as before.
  changes:
    name: changes
    runs-on: ubuntu-latest
    timeout-minutes: 5
    outputs:
      code: ${{ steps.filter.outputs.code }}
    steps:
      - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
        with:
          fetch-depth: 0
      - id: filter
        env:
          BASE: ${{ github.event.pull_request.base.sha }}
        run: |
          if [ -z "$BASE" ]; then
            echo "code=true" >> "$GITHUB_OUTPUT"
            echo "not a pull request; everything runs"
            exit 0
          fi
          # Named as what cannot affect a build rather than what can, so a new
          # kind of file is treated as code until someone says otherwise. Both
          # jobs below assert on the dependency tree, so Cargo.toml and
          # Cargo.lock matter here as much as any .rs file does.
          if git diff --name-only "$BASE"...HEAD \
              | grep -qvE '^(README\.md|DESIGN\.md)$'; then
            echo "code=true" >> "$GITHUB_OUTPUT"
          else
            echo "code=false" >> "$GITHUB_OUTPUT"
            echo "only the top-level prose changed; the cargo jobs are skipped"
          fi

  # notes/DESIGN.md 8.3 gate 1. The published library has no dependencies and no
  # parser; building it without `dev` is what proves nothing dev-gated became
  # reachable from the API.
  library:
    name: library (default features)
    runs-on: ubuntu-latest
    timeout-minutes: 30
    needs: changes
    if: needs.changes.outputs.code == 'true'
    steps:
      - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
      # The claim in Cargo.toml is that `default-features = false` leaves a
      # library with no dependencies at all. Checked, not asserted.
      - run: cargo build --locked --no-default-features
      - name: no dependencies without default features
        run: |
          set -euo pipefail
          # `grep -vc` with `|| true`: under pipefail a grep that matches
          # nothing exits 1, which is the success case here and would
          # otherwise fail the step for having no dependencies.
          deps=$(cargo tree --locked --no-default-features --prefix none | sort -u | grep -vc '^beamte ' || true)
          if [ "$deps" -ne 0 ]; then
            cargo tree --locked --no-default-features
            echo "::error::expected no dependencies, found $deps"
            exit 1
          fi
          echo "no dependencies without default features"
      # The default library reads grammar manifests, so it takes treebank --
      # but treebank's own defaults are `pack` and `fetch`, which are a wasm
      # engine and an HTTP stack. Turning those on would put 238 crates into
      # a library whose premise is that it links neither, and it would break
      # straitjacket's musl release build, which is the exact failure beamte
      # exists not to cause. `default-features = false` is load-bearing, so
      # it is checked rather than trusted to survive an edit.
      - name: the default library links no engine
        run: |
          set -euo pipefail
          tree=$(cargo tree --locked --prefix none)
          heavy=$(echo "$tree" | grep -Eic 'wasmtime|wasmer|cranelift|ureq|tree-sitter' || true)
          if [ "$heavy" -ne 0 ]; then
            echo "$tree" | grep -Ei 'wasmtime|wasmer|cranelift|ureq|tree-sitter'
            echo "::error::the default library pulled in an engine or a parser"
            exit 1
          fi
          echo "no engine, no parser, no HTTP stack in the default tree"
      - run: cargo build --locked
      - run: cargo test --locked
      - run: cargo clippy --locked --all-targets -- -D warnings

  # The rules themselves, against treebank's grammar and treebank's roles.
  rules:
    name: rules (dev harness)
    runs-on: ubuntu-latest
    timeout-minutes: 30
    needs: changes
    if: needs.changes.outputs.code == 'true'
    steps:
      - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
      - run: cargo fmt --all --check
      - run: cargo test --workspace --locked
      - run: cargo clippy --workspace --locked --all-targets -- -D warnings