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
9 changes: 7 additions & 2 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,13 @@ Every install channel above is built on the same foundation: standalone,
self-contained binaries (bundled Python interpreter + all dependencies —
nothing needs to be pre-installed) for macOS (arm64/x64), Linux
(x64/arm64), and Windows (x64), built by CI (`.github/workflows/release.yml`)
on every `vX.Y.Z` tag push and attached to the matching GitHub Release
along with a `SHA256SUMS` file.
when a maintainer with write access runs the Release workflow by hand
(Actions tab, `workflow_dispatch`) for an existing `vX.Y.Z` tag whose
`src/secfoo/__about__.py` (at that tag) has the same version. It is
deliberately not triggered by tag pushes. The run creates the GitHub Release
for that tag, attaches the binaries and a `SHA256SUMS` file, and in the same
run publishes to PyPI, npm and GHCR. A PyPI version cannot be re-uploaded, so
dispatch it only for a version you mean to release.

- **pip**: the "real"/native path — a normal Python sdist+wheel, published
to PyPI as usual.
Expand Down
57 changes: 57 additions & 0 deletions tests/test_docs_consistency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Guards against documentation drifting away from the code it describes."""

from __future__ import annotations

import re
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]

# "tag push", "tag-push", "Tag push", "on every vX.Y.Z tag" ... unless negated.
_TAG_PUSH_CLAIM = re.compile(r"tag[- ]push|on every `?v?X\.Y\.Z`? tag", re.IGNORECASE)
_NEGATED = re.compile(r"\bnot\b[^.]{0,40}$", re.IGNORECASE)


def _has_push_trigger(on_block: str) -> bool:
"""`push` as a trigger: the inline value (`on: push`, `on: [push, ...]`)
or a block-form key (` push:`). Comments and descriptions don't count."""
inline, _, body = on_block.partition("\n")
if re.search(r"\bpush\b", inline.split("#", 1)[0]):
return True
return bool(re.search(r"^[ \t]+push[ \t]*:", body, re.MULTILINE))


def _top_level_on_block(workflow: str) -> str:
"""The workflow's `on:` block: from `on:` to the next top-level key,
blank lines and comments included (a blank line must not end it)."""
match = re.search(r'^["\']?on["\']?:[ \t]*(.*)\n((?:(?:[ \t]+.*|[ \t]*|#.*)\n)*)', workflow, re.MULTILINE)
assert match, "release.yml has no top-level `on:` key"
return match.group(1) + "\n" + match.group(2)


def test_release_workflow_is_manual_only() -> None:
"""The release workflow is workflow_dispatch only; any push trigger
(block form, flow form, or after a blank line) fails this test."""
workflow = (ROOT / ".github" / "workflows" / "release.yml").read_text(encoding="utf-8")
triggers = _top_level_on_block(workflow)
assert "workflow_dispatch" in triggers
assert not _has_push_trigger(triggers), triggers


def test_docs_do_not_claim_the_release_runs_on_tag_push() -> None:
files = [ROOT / "README.md", ROOT / "CONTRIBUTING.md", *sorted((ROOT / "docs").rglob("*.md"))]
offenders = []
for path in files:
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
for match in _TAG_PUSH_CLAIM.finditer(line):
if not _NEGATED.search(line[: match.start()]):
offenders.append(f"{path.relative_to(ROOT)}:{number}: {line.strip()}")
assert offenders == []


def test_the_on_block_parser_sees_triggers_after_a_blank_line() -> None:
workflow = "name: R\non:\n workflow_dispatch:\n inputs: {}\n\n push:\n tags: ['v*']\njobs: {}\n"
assert _has_push_trigger(_top_level_on_block(workflow))
assert _has_push_trigger(_top_level_on_block('"on": [push, workflow_dispatch]\njobs: {}\n'))
commented = "on:\n workflow_dispatch:\n\n# the GHCR push needs packages: write\njobs: {}\n"
assert not _has_push_trigger(_top_level_on_block(commented))