Skip to content

Commit

Permalink
update tasks locally
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Feb 29, 2024
1 parent 18aeb73 commit c28d65c
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit c28d65c

Please sign in to comment.