Skip to content

Commit

Permalink
Merge pull request #131 from greenbone/y0urself/release-patch
Browse files Browse the repository at this point in the history
[pontos-release] Release the next patch version with --patch
  • Loading branch information
y0urself authored Jun 22, 2021
2 parents 4b7d852 + cdec389 commit 04a7f4d
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Calendar Versioning](https://calver.org).

## [Unreleased]
### Added
* `pontos-release prepare` can be used with `--patch`, to create a release with the next patch version. [#131](https://github.com/greenbone/pontos/pull/131)

### Changed
### Deprecated
### Removed
Expand Down
25 changes: 21 additions & 4 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ if it has been lost.
rm .release.txt.md
```

## Create the Release
## Prepare the Release

### Set the version manually

* Run pontos-release release. If you use a "non-Greenbone" project, you may set
the argument `--space <my-workspace>`.
Expand All @@ -159,20 +161,35 @@ if it has been lost.
poetry run pontos-release release --release-version <version> --next-version <dev-version> --git-remote-name upstream
```

## Create Release without giving a version
### Let pontos set the next version

* You can also let pontos calculate the next **calendar** version for you. Therefore you can use the `--calendar` argument in prepare:
* You can let pontos calculate the next **calendar** version for you. Therefore you can use the `--calendar` argument in prepare:

```sh
poetry run pontos-release prepare --calendar --git-signing-key <your-public-gpg-key>
```

* You can let pontos set the next **patch** version for you. Therefore you can use the `--patch` argument in prepare:

```sh
poetry run pontos-release prepare --patch --git-signing-key <your-public-gpg-key>
```

### Dev version

* Pontos can also automatically set the next dev version for you. If you do not explicitly set a `--next-version` it will set to the next dev version:
* e.g. release-version is 0.0.1, pontos will set next-version to 0.0.2.dev1

## Release

```sh
poetry run pontos-release release --git-remote-name upstream
```

* If you use a "non-Greenbone" project, you may set the argument `--space <my-workspace>`.

```sh
poetry run pontos-release --space greenbone release --git-remote-name upstream
poetry run pontos-release --space <my-workspace> release --git-remote-name upstream
```

## Uploading to the 'real' PyPI
Expand Down
9 changes: 9 additions & 0 deletions pontos/release/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pontos.version import (
calculate_calendar_version,
get_current_version,
get_next_patch_version,
get_next_dev_version,
)
from pontos import changelog
Expand Down Expand Up @@ -79,6 +80,11 @@ def initialize_default_parser() -> argparse.ArgumentParser:
),
action='store_true',
)
version_group.add_argument(
'--patch',
help=('Release next patch version: ' 'e.g. x.x.3 -> x.x.4'),
action='store_true',
)

prepare_parser.add_argument(
'--git-signing-key',
Expand Down Expand Up @@ -183,9 +189,12 @@ def prepare(
else find_signing_key(shell_cmd_runner)
)
calendar: bool = args.calendar
patch: bool = args.patch

if calendar:
release_version: str = calculate_calendar_version()
elif patch:
release_version: str = get_next_patch_version()
else:
release_version: str = args.release_version

Expand Down
2 changes: 2 additions & 0 deletions pontos/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from .helper import (
calculate_calendar_version,
get_current_version,
get_next_patch_version,
get_next_dev_version,
)

Expand Down Expand Up @@ -58,6 +59,7 @@ def main(leave=True, args=None):
'CMakeVersionCommand',
'get_version_from_pyproject_toml',
'get_current_version',
'get_next_patch_version',
'get_next_dev_version',
'is_version_pep440_compliant',
'PontosVersionCommand',
Expand Down
22 changes: 22 additions & 0 deletions pontos/version/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,25 @@ def calculate_calendar_version() -> str:
f"'{str(today.year % 100)}.{str(today.month)}'."
)
sys.exit(1)


def get_next_patch_version() -> str:
"""find the correct next patch version by checking latest version"""

current_version_str: str = get_current_version()
current_version = Version(current_version_str)

if current_version.dev:
release_version = Version(
f'{str(current_version.major)}.'
f'{str(current_version.minor)}.'
f'{str(current_version.micro)}'
)
else:
release_version = Version(
f'{str(current_version.major)}.'
f'{str(current_version.minor)}.'
f'{str(current_version.micro + 1)}'
)

return str(release_version)
51 changes: 48 additions & 3 deletions tests/version/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
from pathlib import Path


from pontos.version import (
calculate_calendar_version,
)
from pontos.version import calculate_calendar_version, get_next_patch_version


class CalculateNextVersionTestCase(unittest.TestCase):
Expand Down Expand Up @@ -75,3 +73,50 @@ def test_calculate_calendar_versions(self):
proj_file.unlink()

tmp_path.rmdir()

def test_get_next_patch_version(self):
today = datetime.datetime.today()

filenames = ['pyproject.toml', 'CMakeLists.txt']
mocks = [
'pontos.version.helper.PontosVersionCommand',
'pontos.version.helper.CMakeVersionCommand',
]
current_versions = [
'20.4.1.dev3',
f'{str(today.year % 100)}.4.1.dev3',
f'19.{str(today.month)}.1.dev3',
f'{str(today.year % 100)}.{str(today.month)}.1',
'20.6.1',
]
assert_versions = [
'20.4.1',
f'{str(today.year % 100)}.4.1',
f'19.{str(today.month)}.1',
f'{str(today.year % 100)}.{str(today.month)}.2',
'20.6.2',
]

tmp_path = Path.cwd() / 'tmp'

for filename, mock in zip(filenames, mocks):
for current_version, assert_version in zip(
current_versions, assert_versions
):
tmp_path.mkdir(parents=True, exist_ok=True)
os.chdir(tmp_path)
proj_file = Path.cwd() / filename
proj_file.touch()
with patch(mock) as cmd_mock:
cmd_mock.return_value.get_current_version.return_value = (
current_version
)

release_version = get_next_patch_version()

self.assertEqual(release_version, assert_version)

os.chdir('..')
proj_file.unlink()

tmp_path.rmdir()

0 comments on commit 04a7f4d

Please sign in to comment.