Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f054759e2f | ||
|
|
42625f4b23 | ||
|
|
57910d9c86 |
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
@@ -206,3 +206,14 @@ the version comes from `style.css`'s `Version:` header.
|
|||||||
5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag).
|
5. **Cut a Gitea release** on the source repo and attach the zip (idempotent on re-run/re-tag).
|
||||||
6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with
|
6. **Publish** the zip + computed `${slug}.json` manifest to the channel repo over SSH, with
|
||||||
retry + jitter for concurrent releases.
|
retry + jitter for concurrent releases.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
`build-manifest.py` has `unittest` tests under `tests/`. They need the same `markdown` +
|
||||||
|
`pyyaml` packages `release.sh` installs. From the repo root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m unittest discover -s tests
|
||||||
|
```
|
||||||
+21
-7
@@ -68,8 +68,14 @@ def md_to_html(text: str) -> str:
|
|||||||
|
|
||||||
def wporg_subheads(text: str) -> str:
|
def wporg_subheads(text: str) -> str:
|
||||||
"""wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears
|
"""wp.org `= Subhead =` -> bold paragraph (NOT a heading: WP's modal clears
|
||||||
floats on h*, so heading-led content gaps below the sidebar)."""
|
floats on h*, so heading-led content gaps below the sidebar).
|
||||||
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"**\1**", text)
|
|
||||||
|
The bold line is set off by a blank line on each side so it stays its own
|
||||||
|
block, as wp.org's <h4> does. Python-Markdown won't let a list interrupt a
|
||||||
|
paragraph, so without the blank after it a `= 1.0 =` line's `* ` items became
|
||||||
|
literal text joined by nl2br's <br />; without the blank before it, a subhead
|
||||||
|
straight after a list joined that list's last item."""
|
||||||
|
return re.sub(r"(?m)^=[ \t]+(.+?)[ \t]*=[ \t]*$", r"\n**\1**\n", text)
|
||||||
|
|
||||||
|
|
||||||
def strip_leading_title(md: str) -> str:
|
def strip_leading_title(md: str) -> str:
|
||||||
@@ -128,7 +134,10 @@ def resolve_in_repo(repo_root: str, rel: str):
|
|||||||
|
|
||||||
def read_text(repo_root: str, name: str):
|
def read_text(repo_root: str, name: str):
|
||||||
p = os.path.join(repo_root, name)
|
p = os.path.join(repo_root, name)
|
||||||
return open(p, encoding="utf-8").read() if os.path.isfile(p) else None
|
if not os.path.isfile(p):
|
||||||
|
return None
|
||||||
|
with open(p, encoding="utf-8") as fh:
|
||||||
|
return fh.read()
|
||||||
|
|
||||||
|
|
||||||
def parse_readme_sections(repo_root: str) -> dict:
|
def parse_readme_sections(repo_root: str) -> dict:
|
||||||
@@ -181,7 +190,9 @@ def build_sections(base: dict, repo_root: str, autogen: bool, strip_cfg) -> dict
|
|||||||
if m:
|
if m:
|
||||||
full = resolve_in_repo(repo_root, m.group("path"))
|
full = resolve_in_repo(repo_root, m.group("path"))
|
||||||
if full:
|
if full:
|
||||||
resolved[key] = convert(open(full, encoding="utf-8").read(), m.group("ext"), key, strip_cfg)
|
with open(full, encoding="utf-8") as fh:
|
||||||
|
included = fh.read()
|
||||||
|
resolved[key] = convert(included, m.group("ext"), key, strip_cfg)
|
||||||
continue
|
continue
|
||||||
sys.stderr.write(f"build-manifest: section '{key}' include '{m.group('path')}' not found — literal\n")
|
sys.stderr.write(f"build-manifest: section '{key}' include '{m.group('path')}' not found — literal\n")
|
||||||
resolved[key] = body
|
resolved[key] = body
|
||||||
@@ -215,7 +226,8 @@ def main() -> None:
|
|||||||
repo_root = args.repo_root
|
repo_root = args.repo_root
|
||||||
cfg = {}
|
cfg = {}
|
||||||
if args.config and os.path.isfile(args.config):
|
if args.config and os.path.isfile(args.config):
|
||||||
cfg = yaml.safe_load(open(args.config, encoding="utf-8")) or {}
|
with open(args.config, encoding="utf-8") as fh:
|
||||||
|
cfg = yaml.safe_load(fh) or {}
|
||||||
sec_cfg = cfg.get("sections") or {}
|
sec_cfg = cfg.get("sections") or {}
|
||||||
autogen = bool(sec_cfg.get("autogen", True))
|
autogen = bool(sec_cfg.get("autogen", True))
|
||||||
strip_cfg = sec_cfg.get("strip_title")
|
strip_cfg = sec_cfg.get("strip_title")
|
||||||
@@ -223,11 +235,13 @@ def main() -> None:
|
|||||||
base = {}
|
base = {}
|
||||||
base_path = os.path.join(repo_root, BASE_FILE)
|
base_path = os.path.join(repo_root, BASE_FILE)
|
||||||
if os.path.isfile(base_path):
|
if os.path.isfile(base_path):
|
||||||
base = yaml.safe_load(open(base_path, encoding="utf-8")) or {}
|
with open(base_path, encoding="utf-8") as fh:
|
||||||
|
base = yaml.safe_load(fh) or {}
|
||||||
if not isinstance(base, dict):
|
if not isinstance(base, dict):
|
||||||
sys.exit(f"build-manifest: {BASE_FILE} must be a mapping")
|
sys.exit(f"build-manifest: {BASE_FILE} must be a mapping")
|
||||||
|
|
||||||
computed = json.load(open(args.computed, encoding="utf-8"))
|
with open(args.computed, encoding="utf-8") as fh:
|
||||||
|
computed = json.load(fh)
|
||||||
shots = computed.pop("_screenshots", None) # {N: src} from release.sh (channel URLs)
|
shots = computed.pop("_screenshots", None) # {N: src} from release.sh (channel URLs)
|
||||||
sections = build_sections(base, repo_root, autogen, strip_cfg)
|
sections = build_sections(base, repo_root, autogen, strip_cfg)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
"""Tests for build-manifest.py. Run from the repo root:
|
||||||
|
|
||||||
|
python3 -m unittest discover -s tests
|
||||||
|
|
||||||
|
Needs the same `markdown` + `pyyaml` packages release.sh installs.
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
_BUILDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, "build-manifest.py")
|
||||||
|
_SPEC = importlib.util.spec_from_file_location("build_manifest", _BUILDER)
|
||||||
|
if _SPEC is None or _SPEC.loader is None:
|
||||||
|
raise ImportError(f"cannot load build-manifest.py from {_BUILDER}")
|
||||||
|
bm = importlib.util.module_from_spec(_SPEC)
|
||||||
|
_SPEC.loader.exec_module(bm)
|
||||||
|
|
||||||
|
|
||||||
|
def readme_sections(readme: str) -> dict:
|
||||||
|
with tempfile.TemporaryDirectory() as root:
|
||||||
|
with open(os.path.join(root, "readme.txt"), "w", encoding="utf-8") as fh:
|
||||||
|
fh.write(readme)
|
||||||
|
return bm.build_sections({}, root, True, None)
|
||||||
|
|
||||||
|
|
||||||
|
class ReadmeSubheadTest(unittest.TestCase):
|
||||||
|
def test_changelog_versions_render_as_headings_over_lists(self):
|
||||||
|
sections = readme_sections(
|
||||||
|
"=== Plugin ===\n\n"
|
||||||
|
"== Changelog ==\n\n"
|
||||||
|
"= 2.0.0 =\n"
|
||||||
|
"* Added a thing.\n"
|
||||||
|
"* Fixed a thing.\n"
|
||||||
|
"= 1.0.0 =\n"
|
||||||
|
"* Initial release.\n"
|
||||||
|
"* Second line.\n"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
sections["changelog"],
|
||||||
|
"<p><strong>2.0.0</strong></p>\n"
|
||||||
|
"<ul>\n<li>Added a thing.</li>\n<li>Fixed a thing.</li>\n</ul>\n"
|
||||||
|
"<p><strong>1.0.0</strong></p>\n"
|
||||||
|
"<ul>\n<li>Initial release.</li>\n<li>Second line.</li>\n</ul>",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_subhead_already_set_off_by_blank_lines_is_unchanged(self):
|
||||||
|
sections = readme_sections(
|
||||||
|
"=== Plugin ===\n\n"
|
||||||
|
"== Frequently Asked Questions ==\n\n"
|
||||||
|
"= Does it work? =\n\n"
|
||||||
|
"Yes, it does.\n\n"
|
||||||
|
"**Commands**\n\n"
|
||||||
|
"* one\n"
|
||||||
|
"* two\n"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
sections["faq"],
|
||||||
|
"<p><strong>Does it work?</strong></p>\n"
|
||||||
|
"<p>Yes, it does.</p>\n"
|
||||||
|
"<p><strong>Commands</strong></p>\n"
|
||||||
|
"<ul>\n<li>one</li>\n<li>two</li>\n</ul>",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user