Skip to content

Commit

Permalink
Merge pull request #12 from brainelectronics/feature/support-full-sem…
Browse files Browse the repository at this point in the history
…ver-for-version-line

Support full semver for version line
  • Loading branch information
brainelectronics authored Aug 5, 2022
2 parents 4c19a04 + 261fd99 commit 90a243f
Show file tree
Hide file tree
Showing 7 changed files with 443 additions and 92 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,3 @@ jobs:
skip_existing: true
verbose: true
print_hash: true
- name: Test with nose2
run: |
python -m pip install .[test]
python create_report_dirs.py
nose2 --config tests/unittest.cfg
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./reports/coverage/coverage.xml
flags: unittests
verbose: true
22 changes: 0 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ jobs:
run: |
python -m tox -e py
# echo "Passing :P"
- name: Test with nose2
run: |
python create_report_dirs.py
nose2 --config tests/unittest.cfg
coverage xml
coverage html
- name: Install deploy dependencies
run: |
python -m pip install -U setuptools wheel build
Expand All @@ -61,22 +55,6 @@ jobs:
- name: Test built package
run: |
twine check dist/*.tar.gz
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
OS: 'ubuntu-latest'
PYTHON: ${{ matrix.python-version }}
if: ${{ matrix.python-version == '3.9' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
# directory: ./reports/coverage/
env_vars: OS,PYTHON
# fail_ci_if_error: true # default is false
files: ./reports/coverage/coverage.xml
flags: unittests
# name: codecov-umbrella
# path_to_write_report: ./reports/coverage/codecov_report.txt
verbose: true
- name: Archive build package artifact
uses: actions/upload-artifact@v3
if: ${{ matrix.python-version == '3.9' }}
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# this file is *not* meant to cover or endorse the use of GitHub Actions, but rather to
# help make automated releases for this project

name: Unittest Python Package

on: push

permissions:
contents: read

jobs:
test-and-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Execute tests
run: |
pip install .[test]
python create_report_dirs.py
nose2 --config tests/unittest.cfg
- name: Create coverage report
run: |
coverage xml
- uses: actions/cache@v3
with:
path: ./reports/coverage/coverage.xml
key: coverage-xml-report

upload-coverage:
needs: test-and-coverage
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3
with:
path: ./reports/coverage/coverage.xml
key: coverage-xml-report
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./reports/coverage/coverage.xml
flags: unittests
verbose: true
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ adjust the regular expression to your needs.

## Credits

Based on the [PyPa sample project][ref-pypa-sample].
Based on the [PyPa sample project][ref-pypa-sample]. Also a big thank you to
the creators and maintainers of [SemVer.org][ref-semver] for their
documentation and [regex example][ref-semver-regex-example]

<!-- Links -->
[ref-pypa-sample]: https://github.com/pypa/sampleproject
[ref-semver]: https://semver.org/
[ref-semver-regex-example]: https://regex101.com/r/Ly7O1x/3/
25 changes: 23 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.3.0] - 2022-08-05
### Changed
- Regex to extract the first version line from a changelog supports the full
feature scope of semantic versioning, resolve [#8][ref-issue-8]
- Regex to get the semantic versioning content of a version line supports the
full feature scope of semantic versioning, resolve [#8][ref-issue-8]
- Testing of this package with `nose2` and coverage report generation with
`coverage` including upload to [Codecov][ref-codecov-changelog2version] was
moved to new [GitHub CI unittest workflow](.github/workflows/unittest.yml),
resolve [#11][ref-issue-11]

### Removed
- `nose2` and `coverage` steps as well as upload to
[Codecov][ref-codecov-changelog2version] removed from
[GitHub CI release workflow](.github/workflows/release.yml) and
[GitHub CI test workflow](.github/workflows/test.yml)

## [0.2.0] - 2022-08-03
### Added
- [`ExtractVersion class`](src/changelog2version/extract_version.py) to
extract the version line from a changelog file and to parse the semver
content from a version line, see [#4][ref-issue-4]
content from a version line, resolve [#4][ref-issue-4]
- `semver_line_regex` and `version_line_regex` args for `changelog2version` to
provide custom regular expressions to parse a version line from a changelog
and to extract the semver content from a line
Expand Down Expand Up @@ -71,12 +88,16 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
- Data folder after fork

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/changelog2version/compare/0.2.0...develop
[Unreleased]: https://github.com/brainelectronics/changelog2version/compare/0.3.0...develop

[0.3.0]: https://github.com/brainelectronics/changelog2version/tree/0.3.0
[0.2.0]: https://github.com/brainelectronics/changelog2version/tree/0.2.0
[0.1.1]: https://github.com/brainelectronics/changelog2version/tree/0.1.1
[0.1.0]: https://github.com/brainelectronics/changelog2version/tree/0.1.0

[ref-issue-8]: https://github.com/brainelectronics/changelog2version/issues/8
[ref-issue-11]: https://github.com/brainelectronics/changelog2version/issues/11
[ref-issue-4]: https://github.com/brainelectronics/changelog2version/issues/4

[ref-codecov-changelog2version]: https://app.codecov.io/github/brainelectronics/changelog2version
[ref-python-gitignore-template]: https://github.com/github/gitignore/blob/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Python.gitignore
46 changes: 39 additions & 7 deletions src/changelog2version/extract_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,33 @@ def __init__(self,
logger = self._create_logger()
self._logger = logger

# append "$" to match only ISO8601 dates without additional timestamps
self._version_line_regex = r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}" # noqa
self._semver_line_regex = r"\[\d{1,}[.]\d{1,}[.]\d{1,}\]"
self._semver_line_regex = (
r"^(?P<major>0|[1-9]\d*)\." # major version part
r"(?P<minor>0|[1-9]\d*)\." # minor version part
r"(?P<patch>0|[1-9]\d*)" # bugfix/patch version part
# optional prerelease version part, starting with a "-"
r"(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" # noqa
# optional build metadata version part, starting with a "+"
r"(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
)

self._version_line_regex = (
# begin of line with two "#" followed by a single space
r"(?P<title_begin>\#\#)[ ]{1}"
# anything after a "["
r"\[(?P<potential_semver>("
# three numbers with one or more digits, seperated by dot
r"(\d{1,}\.\d{1,}\.\d{1,})"
r"([-+]?)" # zero or one of either a "-" or "+" character
# r"(.*)" # any character zero or more times
r"([a-zA-Z.+-d]*)" # any character (a-Z), dot, "-", "+" or number
# for zero or more times
r")(?=\]))\]" # positive lookahead for the "]" and the "]"
r"[ ]{1}\-[ ]{1}" # exactly one space, "-", exactly one space
r"(?P<datetime>\d{4}\-\d{2}-\d{2})" # datetime as YYYY-MM-DD
r"(([T ]{1})" # seperation between date and time by "T" or space
r"(?P<timestamp>\d{2,}:\d{2,}:\d{2,}?))?" # time as HH:MM:SS
)

@property
def version_line_regex(self) -> str:
Expand Down Expand Up @@ -151,6 +175,7 @@ def parse_semver_line(self, release_version_line: str) -> str:
Examples of a valid SemVer line:
- "## [0.2.0] - 2022-05-19"
- "## [107.3.18] - 1900-01-01 12:34:56"
- "## [1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay] - 2012-01-02" # noqa
:param release_version_line: The release version line
:type release_version_line: str
Expand All @@ -160,12 +185,19 @@ def parse_semver_line(self, release_version_line: str) -> str:
"""
semver_string = "0.0.0"

# extract semver from release version line
match = re.search(self.semver_line_regex, release_version_line)
# try to extract any content between square brackets
match = re.search(r"\[(.*?)\]", release_version_line)
if not match:
return semver_string

# the potential semver content is the first group of the complete line
potential_semver = match.group(1)

# try to extract semver from release version line
match = re.search(self.semver_line_regex, potential_semver)

if match:
semver_string = match.group()
# remove '[' and ']' from semver_string
semver_string = re.sub(r"[\[\]]", "", semver_string)
if not semver.VersionInfo.isvalid(semver_string):
self._logger.error("Parsed SemVer string is invalid, check "
"the changelog format")
Expand Down
Loading

0 comments on commit 90a243f

Please sign in to comment.