add releaser script

This commit is contained in:
Wolf Vollprecht 2021-11-22 19:42:32 +01:00
parent 8b13203cdb
commit 20a4463e7b
6 changed files with 288 additions and 2 deletions

View File

@ -1,7 +1,7 @@
2021.11.19
==========
all `0.18.1`
Releases: libmamba 0.18.1, libmambapy 0.18.1, mamba 0.18.1, micromamba 0.18.1
Bug fixes
- [all] Fix default log level, use warning everywhere (@adriendelsalle) #1279
@ -11,7 +11,7 @@ Bug fixes
2021.11.17
==========
all `0.18.0`
Releases: libmamba 0.18.0, libmambapy 0.18.0, mamba 0.18.0, micromamba 0.18.0
New features
- [libmamba, mamba, micromamba] Implement parallel packages extraction using subprocesses (@jonashaag @adriendelsalle) #1195

View File

@ -0,0 +1,38 @@
// Copyright (c) 2019, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.
#ifndef LIBMAMBA_VERSION_HPP
#define LIBMAMBA_VERSION_HPP
#include <array>
#include <string>
#define LIBMAMBA_VERSION_MAJOR 0
#define LIBMAMBA_VERSION_MINOR 19
#define LIBMAMBA_VERSION_PATCH 0
// Binary version
#define LIBMAMBA_BINARY_CURRENT 1
#define LIBMAMBA_BINARY_REVISION 0
#define LIBMAMBA_BINARY_AGE 0
#define __LIBMAMBA_STRINGIZE_IMPL(s) #s
#define __LIBMAMBA_STRINGIZE(s) STRINGIZE_IMPL(s)
#define LIBMAMBA_VERSION \
(LIBMAMBA_VERSION_MAJOR * 10000 + LIBMAMBA_VERSION_MINOR * 100 + LIBMAMBA_VERSION_PATCH)
#define LIBMAMBA_VERSION_STRING __LIBMAMBA_STRINGIZE(LIBMAMBA_VERSION_MAJOR) "." \
__LIBMAMBA_STRINGIZE(LIBMAMBA_VERSION_MINOR) "." \
__LIBMAMBA_STRINGIZE(LIBMAMBA_VERSION_PATCH)
namespace mamba
{
std::string version();
std::array<int, 3> version_arr();
}
#endif

View File

@ -0,0 +1,2 @@
version_info = ({{ version_major }}, {{ version_minor }}, {{ version_patch }})
__version__ = ".".join(map(str, version_info))

View File

@ -0,0 +1,2 @@
version_info = ({{ version_major }}, {{ version_minor }}, {{ version_patch }})
__version__ = ".".join(map(str, version_info))

View File

@ -0,0 +1,38 @@
// Copyright (c) 2019, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.
#ifndef UMAMBA_VERSION_HPP
#define UMAMBA_VERSION_HPP
#include <array>
#include <string>
#define UMAMBA_VERSION_MAJOR {{ version_major }}
#define UMAMBA_VERSION_MINOR {{ version_minor }}
#define UMAMBA_VERSION_PATCH {{ version_patch }}
// Binary version
#define UMAMBA_BINARY_CURRENT 1
#define UMAMBA_BINARY_REVISION 0
#define UMAMBA_BINARY_AGE 0
#define __UMAMBA_STRINGIZE_IMPL(s) #s
#define __UMAMBA_STRINGIZE(s) STRINGIZE_IMPL(s)
#define UMAMBA_VERSION \
(UMAMBA_VERSION_MAJOR * 10000 + UMAMBA_VERSION_MINOR * 100 + UMAMBA_VERSION_PATCH)
#define UMAMBA_VERSION_STRING __UMAMBA_STRINGIZE(UMAMBA_VERSION_MAJOR) "." \
__UMAMBA_STRINGIZE(UMAMBA_VERSION_MINOR) "." \
__UMAMBA_STRINGIZE(UMAMBA_VERSION_PATCH)
namespace umamba
{
std::string version();
std::array<int, 3> version_arr();
}
#endif

206
releaser.py Normal file
View File

@ -0,0 +1,206 @@
# script to release any of the mamba packages
import copy
import datetime
import re
template = {"version": None, "changes": []}
def append_element(selector, element, releases, islist, result):
element = element.strip()
def def_el(a, x):
if not a:
return
if islist:
x = f"- {x}"
result[a]["changes"].append(x)
selector = selector.strip()
s = [x.strip() for x in selector.split(",")]
if "all" in s:
for r in releases:
def_el(r, element)
else:
for el in s:
def_el(el, element)
templates = {
"libmamba": "libmamba/include/mamba/version.hpp.tmpl",
"micromamba": "micromamba/src/version.hpp.tmpl",
"libmambapy": "libmambapy/libmambapy/_version.py.tmpl",
"mamba": "mamba/mamba/_version.py.tmpl",
}
def apply_changelog(name, version, changes):
res = ""
today = datetime.date.today()
fmt_today = today.strftime("%B %d, %Y")
header_line = f"{name} {version} ({fmt_today})"
res += f"{header_line}\n{'=' * len(header_line)}\n\n"
for idx, c in enumerate(changes):
if c.startswith("-"):
if idx > 0 and not changes[idx - 1].startswith("- "):
res += f"\n{c}\n"
else:
res += f"{c}\n"
else:
res += f"{c}\n"
res += "\n"
cl_file = name + "/CHANGELOG.md"
with open(cl_file, "r") as fi:
prev_cl = fi.read()
with open(cl_file, "w") as fo:
fo.write(res + prev_cl)
version_major, version_minor, version_patch = version.split(".")
def template_substitute(contents):
x = contents.replace("{{ version_major }}", version_major)
x = x.replace("{{ version_minor }}", version_minor)
x = x.replace("{{ version_patch }}", version_patch)
return x
if name in templates:
template = templates[name]
with open(template, "r") as fi:
final = template_substitute(fi.read())
with open(template[: -len(".tmpl")], "w") as fo:
fo.write(final)
def commands(changes):
print("git diff")
commit_msg = ", ".join([f"{x} {changes[x]['version']}" for x in changes])
today = datetime.date.today()
date_stamp = today.strftime("%Y.%m.%d")
files_to_commit = ""
for c in changes:
files_to_commit += f" {c}/CHANGELOG.md \\\n"
files_to_commit += f" {templates[c][:-len('.tmpl')]} \\\n"
files_to_commit = files_to_commit[:-3]
print(f"git commit -m 'release {commit_msg}' \\\n{files_to_commit}")
print(f"git tag {date_stamp}")
for c in changes:
print(f"git tag {c}_{changes[c]['version']}")
class Section:
def __init__(self):
self.items = []
self.applies_to = ["all"]
self.text = ""
class Item:
def __init__(self):
self.applies_to = ["all"]
self.text = ""
def populate_changes(name, sections, changes):
el = changes[name]
def applies(x):
return "all" in x or name in x
for s in sections:
s_applies = applies(s.applies_to)
if s_applies and len(s.items):
s_applies = any(applies(i.applies_to) for i in s.items)
if s_applies:
if s != sections[0]:
el["changes"].append("\n" + s.text.strip())
else:
el["changes"].append(s.text.strip())
for i in s.items:
if applies(i.applies_to):
el["changes"].append(f"- {i.text.strip()}")
def main():
changes = {}
with open("CHANGELOG.md", "r") as fi:
contents = fi.readlines()
for idx, line in enumerate(contents):
if line.startswith("====="):
release_start = idx + 1
break
brackets_re = re.compile(r"\[(.*)\]")
# section with groups, heading + items
sections = []
in_section = False
contents = contents[release_start:]
for idx, c in enumerate(contents):
if c.startswith("Releases"):
releases = [x.strip() for x in c[len("Releases: ") :].split(",")]
for r in releases:
rsplit = r.split()
changes[rsplit[0].strip()] = copy.deepcopy(template)
changes[rsplit[0].strip()]["version"] = rsplit[1].strip()
continue
if contents[idx + 1].startswith("===="):
break
if c.strip() == "" or c[0] == "-":
in_section = False
if c.strip() == "":
continue
if c[0] != "-":
if not in_section:
sections.append(Section())
in_section = True
sections[-1].text += c
if m := re.search(brackets_re, c):
if in_section:
sections[-1].applies_to(m.groups(1)[0])
else:
sections[-1].items.append(Item())
sections[-1].items[-1].text = c[m.end() :].strip()
sections[-1].items[-1].applies_to = m.groups(1)[0]
# if len(change_el):
# append_element(groups, change_el, release_names, islist, changes)
else:
if c.startswith(" "):
if in_section:
sections[-1].text += " " + c.strip()
else:
sections[-1].items[-1].text += c.strip()
else:
if not in_section:
sections[-1].items.append(Item())
sections[-1].items[-1].text = c.strip()
sections[-1].items[-1].applies_to = "all"
for c in changes:
populate_changes(c, sections, changes)
for el in changes:
apply_changelog(el, changes[el]["version"], changes[el]["changes"])
commands(changes)
if __name__ == "__main__":
main()