pi-ext
bugabingas pi extensions
owned by bugabinga
fix release publish flow
708299cf05870cd3dee8359ef2f42e679dae7e8c
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
Browse filesCompare with HEAD
Changed files (1)
scripts/extensions.py
Modified 144 144 return json.loads((ROOT
/ "package.json").read_text())
147 +SEMVER_RE
= re.compile(
r"^(\d+)\.(\d+)\.(\d+)$")
147 150 def root_version() ->
str:
148 151 return root_pkg().get(
"version",
"0.0.0")
154 +def parse_version(version:
str) ->
tuple[
int,
int,
int]:
155 + match
= SEMVER_RE.match(version)
157 + raise SystemExit(
f"root package.json version must be X.Y.Z, got {version
!r}
")
158 + return tuple(
int(part)
for part
in match.groups())
161 +def bump_patch(version:
str) ->
str:
162 + major, minor, patch
= parse_version(version)
163 + return f"{major}
.{minor}
.{patch
+ 1}
" 166 +def write_json(path: Path, data:
object) ->
None:
167 + path.write_text(json.dumps(data, indent
="\t")
+ "\n", encoding
="utf-8", newline
="\n")
170 +def set_root_version(version:
str) ->
None:
171 + parse_version(version)
173 + pkg[
"version"]
= version
174 + write_json(ROOT
/ "package.json", pkg)
176 + lock_path
= ROOT
/ "package-lock.json" 177 + lock
= json.loads(lock_path.read_text())
178 + lock[
"version"]
= version
179 + root_lock_pkg
= lock.get(
"packages", {}).get(
"")
180 + if isinstance(root_lock_pkg,
dict):
181 + root_lock_pkg[
"version"]
= version
182 + write_json(lock_path, lock)
183 + print(
f"OK version v{version}
")
151 186 def pkg_name(spec:
str) ->
str:
152 187 if spec.startswith(
"@"):
153 188 parts
= spec.split(
"/")
320 -def jj(
*args:
str, check:
bool = True, capture:
bool = False) -> subprocess.CompletedProcess[
str]:
321 - return subprocess.run(
326 - stdout
=subprocess.PIPE
if capture
else None,
327 - stderr
=subprocess.PIPE
if capture
else None,
331 -def use_jj() ->
bool:
332 - proc
= jj(
"root", check
=False, capture
=True)
333 - return proc.returncode
== 0 and Path(proc.stdout.strip()).resolve()
== ROOT
336 355 def git_changes(path: Path, since:
str | None) ->
list[
str]:
337 356 cmd
= [
"log",
"--format=%h %s"]
823 842 return update_demo_drivers(installed_drivers_for(exts))
826 -def jj_commit_id(rev:
str) ->
str:
828 - "log",
"-r", rev,
"--no-graph",
"--template",
"commit_id", capture
=True 832 -def release_bookmark() ->
str:
833 - names
= jj(
"bookmark",
"list", capture
=True).stdout
834 - for name
in (
"trunk",
"main",
"master"):
835 - if re.search(
rf"^{re.escape(name)}
:", names, re.M):
840 845 def changed_paths() ->
list[Path]:
842 - out
= jj(
"diff",
"--name-only", capture
=True).stdout
845 - git(
"diff",
"--name-only", capture
=True).stdout
847 - + git(
"diff",
"--cached",
"--name-only", capture
=True).stdout
847 + git(
"diff",
"--name-only", capture
=True).stdout
849 + + git(
"diff",
"--cached",
"--name-only", capture
=True).stdout
849 851 return sorted({Path(line)
for line
in out.splitlines()
if line.strip()})
871 +def release_tag_for(version:
str) ->
str:
872 + parse_version(version)
873 + return f"v{version}
" 869 876 def release_tag() ->
str:
870 - return f"v{root_version()}
" 877 + return release_tag_for(root_version())
873 880 def tag_exists(tag:
str) ->
bool:
874 881 return git(
"rev-parse",
"--verify",
"--quiet",
f"refs/tags/{tag}
", check
=False).returncode
== 0 884 +def remote_tag_exists(tag:
str) ->
bool:
891 + f"refs/tags/{tag}
",
899 +def ensure_unreleased_version() ->
str:
900 + git(
"fetch",
"--prune",
"--tags",
"origin")
901 + version
= root_version()
903 + while tag_exists(release_tag_for(version))
or remote_tag_exists(release_tag_for(version)):
904 + version
= bump_patch(version)
907 + set_root_version(version)
877 911 def create_tag() ->
str:
878 912 tag
= release_tag()
879 913 exists
= tag_exists(tag)
881 915 print(
f"OK tag {tag}
exists")
884 - jj(
"git",
"export")
885 - target
= jj_commit_id(
"@-")
888 - git(
"tag", tag, target)
917 + git(
"tag", tag,
"HEAD")
889 918 print(
f"OK tag {tag}
")
893 922 def commit_release(paths_to_add:
list[Path]) ->
bool:
894 923 assert_only_release_changes(paths_to_add)
896 - if jj(
"diff",
"--quiet", check
=False).returncode
== 0:
897 - print(
"OK commit none")
899 - jj(
"commit",
"-m",
f"release: v{root_version()}
")
900 - bookmark
= release_bookmark()
901 - jj(
"bookmark",
"set", bookmark,
"-r",
"@-")
902 - print(
f"OK commit v{root_version()}
({bookmark}
)")
905 924 paths
= sorted({
str(path.relative_to(ROOT))
for path
in paths_to_add
if path.exists()})
906 925 git(
"add",
*paths)
907 926 if git(
"diff",
"--cached",
"--quiet",
"--",
*paths, check
=False).returncode
== 0:
915 934 def push_release(tag:
str) ->
None:
917 - jj(
"git",
"push",
"--bookmark", release_bookmark())
918 - git(
"push",
"origin", tag)
921 - git(
"push",
"origin", tag)
936 + git(
"push",
"origin", tag)
1057 1072 def cmd_publish(selected:
list[
str]) ->
int:
1058 1073 dirs
= ext_dirs(selected)
1059 - tag
= release_tag()
1060 - committed
= commit_release(release_paths(dirs))
1061 - if not committed
and not tag_exists(tag):
1063 - "no prepared release changes to publish; run mise run release-prepare first" 1074 + paths
= release_paths(dirs)
1075 + assert_only_release_changes(paths)
1076 + ensure_unreleased_version()
1077 + cmd_release_prepare(selected, model
=None, skip_demo
=False)
1078 + commit_release(paths)
1065 1079 tag
= create_tag()
1066 1080 push_release(tag)