Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version bump and tag #82

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/plugins/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ If you're using the version plugin for the first time on a repo and a `Ctl/VERSI
ctl version tag 1.0.0 --init
```

You may also choose to add a prefix to the tag

```sh
# update Ctl/VERSION to 1.1.0
# tag v1.1.0
# push tag
ctl version tag 1.0.0 prefix v
```

You may also chose to bump a semantic version

```sh
Expand All @@ -41,6 +50,15 @@ You may also chose to bump a semantic version
ctl version bump minor
```

You may also choose to bump but not tag in git

```sh
# update Ctl/VERSION to 1.1.0
# tag v1.1.0
# push tag
ctl version bump --nogit
```

### Use existing repository checkout

Instead of configuring and specifying a git type plugin to use
Expand Down
9 changes: 6 additions & 3 deletions src/ctl/plugins/semver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def tag(self, version, repo, prerelease=None, **kwargs):
raise UsageError("Currently checked out branch is not clean")

version = semver.VersionInfo.parse(version)

if prerelease:
version = version.bump_prerelease(prerelease)

Expand All @@ -125,7 +124,9 @@ def tag(self, version, repo, prerelease=None, **kwargs):
repo_plugin.commit(files=files, message=f"Version {version_tag}", push=True)
nogit = kwargs.pop("nogit", False)
if not nogit:
repo_plugin.tag(version_tag, message=version_tag, push=True)
prefix = kwargs.pop("prefix", None)
version_tag = f"{prefix}{version_tag}" if prefix else version_tag
repo_plugin.tag(version_tag, message=version_tag, push=True, prefix=prefix)

@expose("ctl.{plugin_name}.bump")
def bump(self, version, repo, **kwargs):
Expand Down Expand Up @@ -166,7 +167,9 @@ def bump(self, version, repo, **kwargs):

self.log.info(f"Bumping semantic version: {current} to {new_version}")

self.tag(version=str(new_version), repo=repo, **kwargs)
nogit = kwargs.pop("nogit", False)
if not nogit:
self.tag(version=str(new_version), repo=repo, **kwargs)

@expose("ctl.{plugin_name}.release")
def release(self, repo, **kwargs):
Expand Down
14 changes: 14 additions & 0 deletions src/ctl/plugins/version_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def add_arguments(cls, parser, plugin_config, confu_cli_args):
op_tag_parser.add_argument(
"version", nargs=1, type=str, help="version string to tag with"
)
op_tag_parser.add_argument(
"prefix",
nargs=1,
type=str,
help="prefix string to tag with i.e. {v}1.0.1 - v being the prefix",
required=False,
default=None,
)

confu_cli_args.add(op_tag_parser, "changelog_validate")
confu_cli_args.add(op_tag_parser, "branch")
Expand All @@ -117,6 +125,12 @@ def add_arguments(cls, parser, plugin_config, confu_cli_args):
choices=["major", "minor", "patch", "prerelease"],
help="bumps the specified version segment by 1",
)
op_bump_parser.add_argument(
"--nogit",
action="store_true",
help="whether to tag or not to tag (default: False)",
default=False,
)

confu_cli_args.add(op_bump_parser, "changelog_validate")
confu_cli_args.add(op_bump_parser, "branch")
Expand Down
12 changes: 8 additions & 4 deletions tests/test_plugin_semver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def test_tag(tmpdir, ctlr):
assert dummy_repo.version == "1.0.3"
assert not dummy_repo.has_tag("1.0.3")

plugin.tag(version="1.0.4", repo="dummy_repo", prefix="v")
assert dummy_repo.version == "1.0.4"
assert dummy_repo.has_tag("v1.0.4")


def test_tag_prerelease(tmpdir, ctlr):
plugin, dummy_repo = instantiate(tmpdir, ctlr)
Expand All @@ -60,7 +64,7 @@ def test_tag_pyproject(tmpdir, ctlr):

plugin.tag(version="2.0.0", repo="dummy_repo", prerelease="rc")

with open(pyproject_path, "r") as f:
with open(pyproject_path) as f:
pyproject = tomlkit.load(f)
assert pyproject["tool"]["poetry"]["version"] == "2.0.0-rc.1"

Expand All @@ -83,7 +87,7 @@ def test_bump(tmpdir, ctlr):
plugin.bump(version="invalid", repo="dummy_repo")

plugin.bump(version="patch", repo="dummy_repo", nogit=True)
assert dummy_repo.version == "2.0.1"
assert dummy_repo.version == "2.0.0"
assert not dummy_repo.has_tag("2.0.1")


Expand All @@ -96,7 +100,7 @@ def test_bump_w_prerelease_flag(tmpdir, ctlr):
assert dummy_repo.has_tag("1.0.1-rc.1")

plugin.bump(version="patch", repo="dummy_repo", prerelease="beta", nogit=True)
assert dummy_repo.version == "1.0.2-beta.1"
assert dummy_repo.version == "1.0.1-rc.1"
assert not dummy_repo.has_tag("1.0.2-beta.1")


Expand All @@ -112,7 +116,7 @@ def test_bump_prerelease_version(tmpdir, ctlr):
assert dummy_repo.has_tag("1.0.0-rc.3")

plugin.bump(version="prerelease", repo="dummy_repo", nogit=True)
assert dummy_repo.version == "1.0.0-rc.4"
assert dummy_repo.version == "1.0.0-rc.3"
assert not dummy_repo.has_tag("1.0.0-rc.4")


Expand Down