diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index cce6c5cf..ec9cb456 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -16,9 +16,15 @@ jobs: steps: - uses: actions/checkout@v4 - # rust-toolchain.toml names the toolchain and its components. + # rust-toolchain.toml names the toolchain and its components. The runner + # image's rustup (1.27) cannot read the channel from that file in + # `rustup toolchain install`, so pass it explicitly; rustup installs the + # file's components when the toolchain is first used. - name: Install Rust toolchain - run: rustup toolchain install + run: | + channel=$(sed -n 's/^channel = "\(.*\)"$/\1/p' rust-toolchain.toml) + rustup toolchain install "$channel" --profile minimal + rustup show active-toolchain # Runner environment overrides workflow-level CARGO_TARGET_DIR. Set it on # each Cargo process so trybuild's generated crate stays under this workspace diff --git a/crates/solverforge-config/WIREFRAME.md b/crates/solverforge-config/WIREFRAME.md index b4695262..4387e045 100644 --- a/crates/solverforge-config/WIREFRAME.md +++ b/crates/solverforge-config/WIREFRAME.md @@ -315,7 +315,6 @@ Derives: `Debug, Clone, Default, Deserialize, Serialize`. | Field | Type | |-------|------| | `late_acceptance_size` | `Option` | -| `tolerance` | `Option` | ### `GreatDelugeConfig` diff --git a/csemver.toml b/csemver.toml index a7c657a6..4d684d3e 100644 --- a/csemver.toml +++ b/csemver.toml @@ -17,6 +17,21 @@ releaseCommitMessageFormat = "chore(release): {{currentTag}}" commitUrlFormat = "https://github.com/SolverForge/solverforge/commit/{{hash}}" compareUrlFormat = "https://github.com/SolverForge/solverforge/compare/{{previousTag}}...{{currentTag}}" +# Commit types and their changelog sections. Declaring the list replaces +# csemver's default, which hides refactor: refactor commits get their own +# section, and the remaining types keep the default hidden state. This must +# stay above the first table header, or TOML scopes it into that table. +types = [ + { type = "feat", section = "Features" }, + { type = "fix", section = "Bug Fixes" }, + { type = "refactor", section = "Code Refactoring" }, + { type = "chore", hidden = true }, + { type = "docs", hidden = true }, + { type = "style", hidden = true }, + { type = "perf", hidden = true }, + { type = "test", hidden = true }, +] + packageFiles = [ # Reads the workspace version (the single source of truth; every crate # manifest inherits it through version.workspace = true). diff --git a/scripts/check-doc-names.py b/scripts/check-doc-names.py index 025ee3f3..77406a2f 100755 --- a/scripts/check-doc-names.py +++ b/scripts/check-doc-names.py @@ -18,6 +18,9 @@ - every multi-hump CamelCase name in a file-map description must be defined, as above. +For each wireframe table headed `| Field |` under a `### `Type`` heading, +every listed field must be a field of that struct in the crate's sources. + For each crate with a public-api.txt snapshot, every public struct, enum, trait, function, type alias and macro in it must be named in the crate's WIREFRAME.md. @@ -126,6 +129,60 @@ def check_file_map(path, types, problems): problems.append(f"{path.relative_to(ROOT)}:{number}: file `{relative}` does not exist") +def struct_fields(crate, name): + """The field names of `struct name { ... }` in the crate, or None.""" + header = re.compile(rf"\bstruct\s+{re.escape(name)}\b[^;{{]*\{{") + field = re.compile(r"^\s*(?:pub(?:\([^)]*\))?\s+)?([a-z_][a-z0-9_]*)\s*:", re.MULTILINE) + for source in crate.glob("src/**/*.rs"): + text = source.read_text(encoding="utf-8") + found = header.search(text) + if not found: + continue + depth, start = 1, found.end() + end = start + while depth and end < len(text): + depth += {"{": 1, "}": -1}.get(text[end], 0) + end += 1 + body = "\n".join( + line for line in text[start:end - 1].splitlines() if not line.lstrip().startswith("//") + ) + names = set(field.findall(body)) + # A `#[serde(flatten)]` field serializes as its own type's fields, and + # wireframes list those serialized keys. + flatten = re.compile(r"#\[serde\(flatten\)\]\s*(?:pub(?:\([^)]*\))?\s+)?\w+\s*:\s*(?:Option<)?([A-Z]\w*)") + for inner in flatten.findall(body): + names.update(struct_fields(crate, inner) or ()) + return names + return None + + +def check_field_tables(path, problems): + heading = re.compile(r"^#{2,4} (?:`([A-Z][A-Za-z0-9]*))?") + row = re.compile(r"^\| `([a-z_][a-z0-9_]*)` \|") + owner, fields, in_table = None, None, False + for number, line in prose_lines(path): + title = heading.match(line) + if title: + owner, fields, in_table = title.group(1), None, False + continue + if line.startswith("| Field |"): + in_table = owner is not None + if in_table: + fields = struct_fields(path.parent, owner) + if fields is None: + problems.append( + f"{path.relative_to(ROOT)}:{number}: no struct `{owner}` for its field table" + ) + in_table = False + continue + if not line.startswith("|"): + in_table = False + continue + cell = row.match(line) + if in_table and cell and cell.group(1) not in fields: + problems.append(f"{path.relative_to(ROOT)}:{number}: `{owner}` has no field `{cell.group(1)}`") + + def check_public_api(path, problems): snapshot = path.parent / "public-api.txt" if not snapshot.exists(): @@ -151,6 +208,7 @@ def main(): for path in sorted(ROOT.glob("crates/*/WIREFRAME.md")): check_inline(path, types, functions, problems) check_file_map(path, types, problems) + check_field_tables(path, problems) check_public_api(path, problems) for path in sorted(ROOT.glob("docs/*.md")): check_inline(path, types, functions, problems)