From bf7ddf70a905b4e8780dd19ff23a6450ce5e086a Mon Sep 17 00:00:00 2001 From: Maciej Urbanski Date: Fri, 21 Jun 2024 21:59:51 +0200 Subject: [PATCH] cruft update (fix release process) --- .cruft.json | 2 +- noxfile.py | 27 +++++++++++++++++++++++++-- pyproject.toml | 18 ++++++++++++------ tests/unit/internal/test_setup.py | 4 +++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/.cruft.json b/.cruft.json index 301ccf8..8e7db46 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/reef-technologies/cookiecutter-rt-pkg", - "commit": "9098eed1a7c4e44e568f990cb111e9ccb6bf78ca", + "commit": "7390ecadb2c65075b6c6c9216c894cc6c4533b3e", "checkout": null, "context": { "cookiecutter": { diff --git a/noxfile.py b/noxfile.py index ade2cde..819dfc1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -162,6 +162,7 @@ def test(session, django: str): @nox.session(python=PYTHON_DEFAULT_VERSION) def make_release(session): + install(session, "release", no_self=True, no_default=True) parser = argparse.ArgumentParser() def version(value): @@ -174,14 +175,36 @@ def version(value): help="Release version in semver format (e.g. 1.2.3)", type=version, ) + parser.add_argument( + "--draft", + action="store_true", + help="Create a draft release", + ) parsed_args = parser.parse_args(session.posargs) local_changes = subprocess.check_output(["git", "diff", "--stat"]) if local_changes: session.error("Uncommitted changes detected") - current_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True) + current_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True).strip() if current_branch != MAIN_BRANCH_NAME: - session.error(f"WARNING: releasing from a branch different than {MAIN_BRANCH_NAME!r}") + session.warn(f"Releasing from a branch {current_branch!r}, while main branch is {MAIN_BRANCH_NAME!r}") + if not parsed_args.draft: + session.error("Only draft releases are allowed from non-main branch") session.run("towncrier", "build", "--yes", "--version", parsed_args.release_version) + + if parsed_args.draft: + tag = f"draft/v{parsed_args.release_version}" + message = f"Draft release {tag}" + else: + tag = f"v{parsed_args.release_version}" + message = f"release {tag}" + + session.log( + f'CHANGELOG updated, please review changes, and execute when ready:\n' + f' git commit -m {message!r}\n' + f' git push origin {current_branch}\n' + f' git tag {tag}\n' + f' git push origin {tag}\n' + ) diff --git a/pyproject.toml b/pyproject.toml index 0d7e6b2..d967105 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,5 @@ [project] name = "django-business-metrics" -version = "1.0.2" requires-python = ">=3.9" description = "Django Prometheus business metrics" keywords = [] @@ -12,6 +11,7 @@ authors = [ ] classifiers = [ "Framework :: Django", + "Framework :: Django :: 4.2", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", @@ -19,6 +19,9 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] +dynamic = [ + "version", +] dependencies = [ "Django>=3", "prometheus-client>=0.13.0", @@ -32,14 +35,12 @@ dependencies = [ requires = ["pdm-backend"] build-backend = "pdm.backend" -[tool.pytest.ini_options] -pythonpath = ["."] # allow for `import tests` in test files -target_package_name = "django_business_metrics" # required by pytest-apiver -DJANGO_SETTINGS_MODULE="tests.settings" - [tool.pdm] distribution = true +[tool.pdm.version] +source = "scm" + [tool.pdm.dev-dependencies] test = [ "freezegun", @@ -62,6 +63,11 @@ release = [ "towncrier", ] +[tool.pytest.ini_options] +pythonpath = ["."] # allow for `import tests` in test files +target_package_name = "django_business_metrics" # required by pytest-apiver +DJANGO_SETTINGS_MODULE="tests.settings" + [tool.ruff] line-length = 120 diff --git a/tests/unit/internal/test_setup.py b/tests/unit/internal/test_setup.py index 16a12ef..ac554c7 100644 --- a/tests/unit/internal/test_setup.py +++ b/tests/unit/internal/test_setup.py @@ -1,5 +1,7 @@ """ -Basic test environment setup test. +Test setup tests. + +This test file is here always to indicate that everything was installed and the CI was able to run tests. It should always pass as long as all dependencies are properly installed. """