From c28d65c8cd35dad2ddc8da4fad0186b41d733987 Mon Sep 17 00:00:00 2001 From: tomvanmele Date: Thu, 29 Feb 2024 22:56:18 +0100 Subject: [PATCH] update tasks locally --- tasks.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index fa055f3..24f91db 100644 --- a/tasks.py +++ b/tasks.py @@ -8,6 +8,7 @@ from compas_invocations import docs as docs_ from compas_invocations import tests from compas_invocations.console import chdir +from compas_invocations.console import confirm @invoke.task( @@ -117,6 +118,55 @@ def linkcheck(ctx, rebuild=False): ctx.run("sphinx-build {} -b linkcheck docs dist/docs".format(opts)) +@invoke.task(help={"release_type": "Type of release follows semver rules. Must be one of: major, minor, patch."}) +def release(ctx, release_type): + """Releases the project in one swift command!""" + if release_type not in ("patch", "minor", "major"): + raise invoke.Exit("The release type parameter is invalid.\nMust be one of: major, minor, patch.") + + # Run formatter + ctx.run("invoke format") + + # Run checks + ctx.run("invoke test") + + # Bump version and git tag it + ctx.run("bump-my-version bump %s --verbose" % release_type) + + # Build project + ctx.run("python -m build") + + # Prepare the change log for the next release + prepare_changelog(ctx) + + # Clean up local artifacts + clean(ctx) + + # Upload to pypi + if confirm( + "Everything is ready. You are about to push to git which will trigger a release to pypi.org. Are you sure?", + assume_yes=False, + ): + ctx.run("git push --tags && git push") + else: + raise invoke.Exit("You need to manually revert the tag/commits created.") + + +@invoke.task +def prepare_changelog(ctx): + """Prepare changelog for next release.""" + UNRELEASED_CHANGELOG_TEMPLATE = "## Unreleased\n\n### Added\n\n### Changed\n\n### Removed\n\n\n## " + + with chdir(ctx.base_folder): + # Preparing changelog for next release + with open("CHANGELOG.md", "r+") as changelog: + content = changelog.read() + changelog.seek(0) + changelog.write(content.replace("## ", UNRELEASED_CHANGELOG_TEMPLATE, 1)) + + ctx.run('git add CHANGELOG.md && git commit -m "Prepare changelog for next release"') + + ns = Collection( docs_.help, check, @@ -127,9 +177,9 @@ def linkcheck(ctx, rebuild=False): tests.test, tests.testdocs, tests.testcodeblocks, - build.prepare_changelog, + prepare_changelog, clean, - build.release, + release, build.build_ghuser_components, ) ns.configure(