Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Detect the build tool and thus the version
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon committed Mar 28, 2020
1 parent 3b76e3f commit b2ca7e7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,22 @@ release:
- uses: actions/checkout@v2
- uses: brettcannon/release-often@v1
with:
build-tool: flit
changelog-path: doc/CHANGELOG.rst
github-token: ${{ secret.GITHUB_TOKEN }}
pypi-token: ${{ secrets.PYPI_TOKEN }}
```
### Inputs
#### `build-tool`
The build tool used for the project. Acceptable values are:
- flit
- poetry

Leaving this input out will disable automatic version bumping.
#### `changelog-path`
The path to the changelog file. Paths must end in one of the following extensions to denote the file format:
**Required**: The path to the changelog file. Paths must end in one of the following extensions to denote the file format:
- `.md`
- `.rst`

Leaving this input out will disable automatic changelog updating.

#### `github-token`
The GitHub access token (i.e. `${{ secrets.GITHUB_TOKEN }}`). This allows for committing changes back to the repository.
**Required**: The GitHub access token (i.e. `${{ secrets.GITHUB_TOKEN }}`). This allows for committing changes back to the repository.

Leaving this input out will disable committing any changes made and creating a release.

Expand All @@ -60,13 +53,6 @@ The [PyPI API token](https://pypi.org/help/#apitoken) for this project. It is **

Leaving this input out will disable uploading to PyPI.

### Outputs
#### `version`
The new version of the project. Set to the empty string if a version change did not occur.

#### `artifacts`
Directory containing the built artifacts (traditionally `dist/`).


## Details
### Update version
Expand Down
29 changes: 25 additions & 4 deletions release_often/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
from gidgethub import actions

from . import version


def update_version():
build_tool, version_file = version.find_details(actions.workspace())
if build_tool is None:
# XXX
pass
file_contents = version_file.read_text(encoding="utf-8")
current_version = build_tool.read_version(file_contents)
new_version = version.bump_by_label(actions.event(), current_version)
new_contents = build_tool.change_version(
file_contents, current_version, new_version
)
version_file.write_text(new_contents, encoding="utf-8")


if __name__ == "__main__":
# Update the version number.
# XXX get current version
# XXX map label to enum (probably need gidgethub.actions.webhook_event())
# XXX update version
update_version()
# XXX update changelog
# XXX build the project
# XXX Commit the changes
# XXX Upload to PyPI
# XXX Create a release on GitHub
pass
17 changes: 17 additions & 0 deletions release_often/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import packaging

from . import flit, poetry


@enum.unique
class BumpLevel(enum.Enum):
Expand Down Expand Up @@ -31,3 +33,18 @@ def bump(version, bump_by):
return f"{major}.{minor}.{micro}.post{post}"
else:
return None


def find_details(directory):
"""Find the build tool and the file containing the current version."""
for build_tool in (flit, poetry):
try:
return build_tool, build_tool.version_file_path(directory)
except (ValueError, TypeError):
pass
else:
return None, None


def bump_by_label(event, old_version):
"""Calculate the new version based on the pull request event."""
12 changes: 12 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from release_often import version
from release_often import flit, poetry


@pytest.mark.parametrize(
Expand All @@ -16,3 +17,14 @@
)
def test_bump(given, level, expect):
assert version.bump(given, level) == expect


@pytest.mark.parametrize(
"test_path,build_tool,file_path",
[("poetry", poetry, "pyproject.toml"), ("flit/top_module", flit, "pkg.py")],
)
def test_version_file_path(data_path, test_path, build_tool, file_path):
directory = data_path / test_path
result = version.find_details(directory)
assert result[0] == build_tool
assert result[1] == directory / file_path

0 comments on commit b2ca7e7

Please sign in to comment.