pi-ext
bugabingas pi extensions
owned by bugabinga
chore: make publish jj-aware
a6de390084f4e2f74271675c61be5452dd7bb682
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (1)
scripts/extensions.py
Modified 277 +def jj(
*args:
str, check:
bool = True, capture:
bool = False) -> subprocess.CompletedProcess[
str]:
278 + return subprocess.run(
283 + stdout
=subprocess.PIPE
if capture
else None,
284 + stderr
=subprocess.PIPE
if capture
else None,
288 +def use_jj() ->
bool:
289 + proc
= jj(
"root", check
=False, capture
=True)
290 + return proc.returncode
== 0 and Path(proc.stdout.strip()).resolve()
== ROOT
277 293 def git_changes(path: Path, since:
str | None) ->
list[
str]:
278 294 cmd
= [
"log",
"--format=%h %s"]
523 +def demo_installed(driver:
str, targets:
list[
str]) ->
bool:
524 + for target
in targets:
525 + ext
= EXT_ROOT
/ target
526 + if not (ext
/ "README.md").exists()
or not (ext
/ "assets" / f"{driver}
.gif").exists():
531 +def installed_drivers_for(exts:
list[Path]) ->
list[
tuple[
str,
list[
str]]]:
532 + return [(driver, targets)
for driver, targets
in drivers_for(exts)
if demo_installed(driver, targets)]
507 535 def update_demos(exts:
list[Path]) ->
list[Path]:
508 - drivers
= drivers_for(exts)
536 + drivers
= installed_drivers_for(exts)
510 538 print(
"OK demo none")
517 545 return sorted(path
for path
in touched
if path.exists())
548 +def jj_commit_id(rev:
str) ->
str:
549 + return jj(
"log",
"-r", rev,
"--no-graph",
"--template",
"commit_id", capture
=True).stdout.strip()
552 +def release_bookmark() ->
str:
553 + names
= jj(
"bookmark",
"list", capture
=True).stdout
554 + for name
in (
"trunk",
"main",
"master"):
555 + if re.search(
rf"^{re.escape(name)}
:", names, re.M):
560 +def changed_paths() ->
list[Path]:
562 + out
= jj(
"diff",
"--name-only", capture
=True).stdout
564 + out
= git(
"diff",
"--name-only", capture
=True).stdout
+ "\n" + git(
"diff",
"--cached",
"--name-only", capture
=True).stdout
565 + return sorted({Path(line)
for line
in out.splitlines()
if line.strip()})
568 +def allowed_change(path: Path, roots:
list[Path]) ->
bool:
570 + rel
= root.relative_to(ROOT)
571 + if path
== rel
or rel
in path.parents:
576 +def assert_only_release_changes(paths_to_add:
list[Path]) ->
None:
577 + roots
= [path
for path
in paths_to_add
if path.exists()]
578 + extra
= [path
for path
in changed_paths()
if not allowed_change(path, roots)]
580 + raise SystemExit(
"refusing to publish unrelated change(s): " + ", ".join(
str(path)
for path
in extra))
520 583 def create_tag() ->
str:
521 584 tag
= f"v{root_version()}
" 522 585 exists
= git(
"rev-parse",
"--verify",
"--quiet",
f"refs/tags/{tag}
", check
=False).returncode
== 0 524 587 print(
f"OK tag {tag}
exists")
590 + jj(
"git",
"export")
591 + target
= jj_commit_id(
"@-")
594 + git(
"tag", tag, target)
527 595 print(
f"OK tag {tag}
")
531 599 def commit_release(paths_to_add:
list[Path]) ->
None:
600 + assert_only_release_changes(paths_to_add)
602 + if jj(
"diff",
"--quiet", check
=False).returncode
== 0:
603 + print(
"OK commit none")
605 + jj(
"commit",
"-m",
f"release: v{root_version()}
")
606 + bookmark
= release_bookmark()
607 + jj(
"bookmark",
"set", bookmark,
"-r",
"@-")
608 + print(
f"OK commit v{root_version()}
({bookmark}
)")
532 611 paths
= sorted({
str(path.relative_to(ROOT))
for path
in paths_to_add
if path.exists()})
533 612 git(
"add",
*paths)
534 613 if git(
"diff",
"--cached",
"--quiet",
"--",
*paths, check
=False).returncode
== 0:
541 620 def push_release(tag:
str) ->
None:
543 - git(
"push",
"origin", tag)
622 + jj(
"git",
"push",
"--bookmark", release_bookmark())
623 + git(
"push",
"origin", tag)
626 + git(
"push",
"origin", tag)
648 - demos
= drivers_for(dirs)
731 + demos
= installed_drivers_for(dirs)
649 732 print(
"DRY RUN publish")
650 733 print(
f"version: v{root_version()}
")
651 734 print(
"demos: " + (
", ".join(name
for name, _targets
in demos)
if demos
else "none"))