Skip to content
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Detailed workflows are available to draft a changelog, draft a release, publish
- Checks the links in Markdown and reStructuredText files
- Adds a commit that includes the hashes of the dist files
- Creates an annotated version tag in standard format
- If given, bumps the version using the post version spec
- If given, bumps the version using the post version spec. The post version
spec can also be given as a setting, see the [Write Releaser Config Guide](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/write_config.html).
- Pushes the commits and tag to the target `branch`
- Publishes a draft GitHub release for the tag with the changelog entry as the text

Expand Down
3 changes: 2 additions & 1 deletion docs/source/background/theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Detailed workflows are available to draft a changelog, draft a release, publish
- Checks the links in Markdown and reStructuredText files
- Adds a commit that includes the hashes of the dist files
- Creates an annotated version tag in standard format
- If given, bumps the version using the post version spec
- If given, bumps the version using the post version spec. he post version
spec can also be given as a setting, [Write Releaser Config Guide](../how_to_guides/write_config.html#automatic-dev-versions).
- Pushes the commits and tag to the target `branch`
- Publishes a draft GitHub release for the tag with the changelog entry as the text

Expand Down
12 changes: 12 additions & 0 deletions docs/source/how_to_guides/write_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ Example `package.json`:
}
}
```

## Automatic Dev Versions

If you'd like to use dev versions for your repository between builds,
use `dev` as the `post-version-spec` setting, e.g.

```toml
[tools.jupyter-releaser.options]
post-version-spec = "dev"
```

This will bump it to the next minor release with a `.dev0` suffix.
9 changes: 9 additions & 0 deletions jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,12 @@ def extract_current(changelog_path):
if start != -1 and end != -1:
body = changelog[start + len(START_MARKER) : end]
return body


def extract_current_version(changelog_path):
"""Extract the current released version from the changelog"""
body = extract_current(changelog_path)
match = re.match(r"#+ ([\d.]+)", body.strip())
if not match:
raise ValueError("Could not find previous version")
return match.groups()[0]
5 changes: 3 additions & 2 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ def prep_git(ref, branch, repo, auth, username, git_url):
@main.command()
@add_options(version_spec_options)
@add_options(version_cmd_options)
@add_options(changelog_path_options)
@add_options(python_packages_options)
@use_checkout_dir()
def bump_version(version_spec, version_cmd, python_packages):
def bump_version(version_spec, version_cmd, changelog_path, python_packages):
"""Prep git and env variables and bump version"""
prev_dir = os.getcwd()
for python_package in [p.split(":")[0] for p in python_packages]:
os.chdir(python_package)
lib.bump_version(version_spec, version_cmd)
lib.bump_version(version_spec, version_cmd, changelog_path)
os.chdir(prev_dir)


Expand Down
10 changes: 7 additions & 3 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
from jupyter_releaser import util


def bump_version(version_spec, version_cmd):
def bump_version(version_spec, version_cmd, changelog_path):
"""Bump the version and verify new version"""
util.bump_version(version_spec, version_cmd=version_cmd)
util.bump_version(
version_spec, version_cmd=version_cmd, changelog_path=changelog_path
)

version = util.get_version()

Expand Down Expand Up @@ -237,7 +239,9 @@ def draft_release(

# Bump to post version if given
if post_version_spec:
post_version = bump_version(post_version_spec, version_cmd)
post_version = bump_version(
post_version_spec, version_cmd=version_cmd, changelog_path=changelog_path
)
util.log(post_version_message.format(post_version=post_version))
util.run(f'git commit -a -m "Bump to {post_version}"')

Expand Down
24 changes: 19 additions & 5 deletions jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def test_handle_npm_config(npm_package):
npmrc.write_text(npmrc_text, encoding="utf-8")


def test_bump_version(py_package):
for spec in ["1.0.1", "1.0.1.dev1", "1.0.3a4"]:
def test_bump_version_reg(py_package):
for spec in ["1.0.1", "1.0.3a4"]:
util.bump_version(spec)
util.run("git commit -a -m 'bump version'")
assert util.get_version() == spec
Expand All @@ -258,13 +258,27 @@ def test_bump_version(py_package):
util.bump_version("1.0.3a5")
util.bump_version("next")
assert util.get_version() == "1.0.3a6"
util.bump_version("1.0.3.dev1")
util.bump_version("next")
assert util.get_version() == "1.0.3"
util.bump_version("minor")
assert util.get_version() == "1.1.0"


def test_bump_version_dev(py_package):
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev1"
# Should get the version from the changelog
util.bump_version("next", changelog_path=py_package / "CHANGELOG.md")
assert util.get_version() == "0.0.2"
util.bump_version("dev")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("patch", changelog_path=py_package / "CHANGELOG.md")
assert util.get_version() == "0.0.2"
util.bump_version("1.0.0.dev0")
util.bump_version("minor")
assert util.get_version() == "1.0.0"


def test_get_config_python(py_package):
Path(util.JUPYTER_RELEASER_CONFIG).unlink()
text = util.PYPROJECT.read_text(encoding="utf-8")
Expand Down
47 changes: 37 additions & 10 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def create_release_commit(version, release_message=None, dist_dir="dist"):
return shas


def bump_version(version_spec, version_cmd=""):
def bump_version(version_spec, *, changelog_path="", version_cmd=""):
"""Bump the version"""
# Look for config files to determine version command if not given
if not version_cmd:
Expand Down Expand Up @@ -241,17 +241,44 @@ def bump_version(version_spec, version_cmd=""):
# Add some convenience options on top of "tbump"
if "tbump" in version_cmd:
v = parse_version(get_version())
if version_spec == "next":
if v.is_devrelease:

if v.is_devrelease:
# bump from the version in the changelog.
if version_spec in ["patch", "next"]:
from jupyter_releaser.changelog import extract_current_version

v = parse_version(extract_current_version(changelog_path))
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"

# Drop the dev portion and move to the minor release.
elif version_spec == "minor":
version_spec = f"{v.major}.{v.minor}.{v.micro}"
elif v.is_prerelease:
version_spec = f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
else:

# Bump to the next dev version.
elif version_spec == "dev":
version_spec = f"{v.major}.{v.minor}.{v.micro}.dev{v.dev + 1}"

else:
# Bump to next minor for dev.
if version_spec == "dev":
version_spec = f"{v.major}.{v.minor + 1}.0.dev0"

# For next, go to next prerelease or patch if it is a final version.
elif version_spec == "next":
if v.is_prerelease:
version_spec = (
f"{v.major}.{v.minor}.{v.micro}{v.pre[0]}{v.pre[1] + 1}"
)
else:
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"

# For patch, always patch.
elif version_spec == "patch":
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
elif version_spec == "patch":
version_spec = f"{v.major}.{v.minor}.{v.micro + 1}"
elif version_spec == "minor":
version_spec = f"{v.major}.{v.minor + 1}.0"

# For minor, always minor.
elif version_spec == "minor":
version_spec = f"{v.major}.{v.minor + 1}.0"

# Bump the version
run(f"{version_cmd} {version_spec}")
Expand Down