-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: Chores/fix semantic release (#7)
* MINOR: test * Fix the semantic release * fix build command.
- Loading branch information
Showing
5 changed files
with
152 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ jobs: | |
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GA" | ||
PYTHONPATH=$PWD python setup.py sdist | ||
PYTHONPATH=$PWD semantic-release version | ||
PYTHONPATH=$PWD twine upload --non-interactive dist/* | ||
PYTHONPATH=$PWD semantic-release publish | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
python-semantic-release==9.8.0 | ||
twine==5.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[semantic_release] | ||
assets = [] | ||
build_command = "python setup.py sdist" | ||
build_command_env = [] | ||
commit_message = "{version}\n\nAutomatically generated by python-semantic-release" | ||
commit_parser = "semantic_release_config.parser:BimdataCommitParser" | ||
logging_use_named_masks = false | ||
major_on_zero = true | ||
allow_zero_version = true | ||
no_git_verify = false | ||
tag_format = "v{version}" | ||
version_variables = ["setup.py:VERSION"] | ||
|
||
[semantic_release.branches.main] | ||
match = "(main|master)" | ||
prerelease_token = "rc" | ||
prerelease = false | ||
|
||
[semantic_release.changelog] | ||
template_dir = "templates" | ||
changelog_file = "CHANGELOG.md" | ||
exclude_commit_patterns = [] | ||
|
||
[semantic_release.changelog.environment] | ||
block_start_string = "{%" | ||
block_end_string = "%}" | ||
variable_start_string = "{{" | ||
variable_end_string = "}}" | ||
comment_start_string = "{#" | ||
comment_end_string = "#}" | ||
trim_blocks = false | ||
lstrip_blocks = false | ||
newline_sequence = "\n" | ||
keep_trailing_newline = false | ||
extensions = [] | ||
autoescape = true | ||
|
||
[semantic_release.commit_author] | ||
env = "GIT_COMMIT_AUTHOR" | ||
default = "semantic-release <semantic-release>" | ||
|
||
[semantic_release.commit_parser_options] | ||
allowed_tags = ["PATCH", "MINOR", "MAJOR"] | ||
major_tags = ["MAJOR"] | ||
minor_tags = ["MINOR"] | ||
patch_tags = ["PATCH"] | ||
|
||
[semantic_release.remote] | ||
name = "origin" | ||
token = { env = "GH_TOKEN" } | ||
type = "github" | ||
ignore_token_for_push = false | ||
insecure = false | ||
|
||
[semantic_release.publish] | ||
dist_glob_patterns = ["dist/*"] | ||
upload_to_vcs_release = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,99 @@ | ||
from semantic_release import UnknownCommitMessageStyleError | ||
from semantic_release.settings import config | ||
from semantic_release.history.parser_helpers import ParsedCommit | ||
""" | ||
BIMData.io commit style parser | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
def parse_commit_message(message): | ||
import logging | ||
import re | ||
from typing import TYPE_CHECKING, Tuple | ||
|
||
from pydantic.dataclasses import dataclass | ||
|
||
from semantic_release.commit_parser._base import CommitParser, ParserOptions | ||
from semantic_release.commit_parser.token import ParsedCommit, ParseError, ParseResult | ||
from semantic_release.enums import LevelBump | ||
from semantic_release.commit_parser.util import parse_paragraphs | ||
|
||
if TYPE_CHECKING: | ||
from git.objects.commit import Commit | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def _logged_parse_error(commit: Commit, error: str) -> ParseError: | ||
log.debug(error) | ||
return ParseError(commit, error=error) | ||
|
||
|
||
@dataclass | ||
class BimdataParserOptions(ParserOptions): | ||
"""Options dataclass for AngularCommitParser""" | ||
|
||
allowed_tags: Tuple[str, ...] = ( | ||
"MAJOR", | ||
"MINOR", | ||
"PATCH", | ||
) | ||
major_tags: Tuple[str, ...] = ("MAJOR",) | ||
minor_tags: Tuple[str, ...] = ("MINOR",) | ||
patch_tags: Tuple[str, ...] = ("PATCH",) | ||
default_bump_level: LevelBump = LevelBump.NO_RELEASE | ||
|
||
|
||
class BimdataCommitParser(CommitParser[ParseResult, BimdataParserOptions]): | ||
""" | ||
Parses a commit message according to the 1.0 version of python-semantic-release. It expects | ||
a tag of some sort in the commit message and will use the rest of the first line as changelog | ||
content. | ||
:param message: A string of a commit message. | ||
:raises semantic_release.UnknownCommitMessageStyle: If it does not recognise the commit style | ||
:return: A tuple of (level to bump, type of change, scope of change, a tuple with descriptions) | ||
BIMData.io parser | ||
""" | ||
if config.get('minor_tag') in message: | ||
level = 'feature' | ||
level_bump = 2 | ||
subject = message.replace(config.get('minor_tag'), '') | ||
|
||
elif config.get('fix_tag') in message: | ||
level = 'fix' | ||
level_bump = 1 | ||
subject = message.replace(config.get('fix_tag'), '') | ||
|
||
elif config.get('major_tag') in message: | ||
level = 'breaking' | ||
level_bump = 3 | ||
subject = message.replace(config.get('major_tag'), '') | ||
|
||
else: | ||
raise UnknownCommitMessageStyleError( | ||
'Unable to parse the given commit message: {0}'.format(message) | ||
) | ||
|
||
body = message | ||
footer = message | ||
parser_options = BimdataParserOptions | ||
|
||
def __init__(self, options: BimdataParserOptions | None = None) -> None: | ||
super().__init__(options) | ||
self.re_parser = re.compile(r"^(?P<type>\w+)?:?\s*(?P<subject>.+)") | ||
|
||
# The problem is the cache likely won't be present in CI environments | ||
def parse(self, commit: Commit) -> ParseResult: | ||
""" | ||
Attempt to parse the commit message with a regular expression into a | ||
ParseResult | ||
""" | ||
message = str(commit.message) | ||
subject = message.split("\n")[0] | ||
|
||
return ParsedCommit(level_bump, level, None, (subject.strip(), body.strip(), footer.strip()), None) | ||
parsed = self.re_parser.match(subject) | ||
if not parsed: | ||
return _logged_parse_error( | ||
commit, f"Unable to parse the given commit message: {message}" | ||
) | ||
parsed_type = parsed.group("type") | ||
|
||
level_bump = self.options.default_bump_level | ||
level = "unknown" | ||
if parsed_type in self.options.major_tags: | ||
level_bump = LevelBump.MAJOR | ||
level = "breaking" | ||
elif parsed_type in self.options.minor_tags: | ||
level_bump = LevelBump.MINOR | ||
level = "feature" | ||
elif parsed_type in self.options.patch_tags: | ||
level_bump = LevelBump.PATCH | ||
level = "fix" | ||
else: | ||
log.debug( | ||
f"commit {commit.hexsha} didn't match any tag, use default {level_bump} level_bump" | ||
) | ||
log.debug(f"commit {commit.hexsha} introduces a {level_bump} level_bump") | ||
|
||
descriptions = parse_paragraphs(message) | ||
|
||
return ParsedCommit( | ||
bump=level_bump, | ||
type=level, | ||
scope="", | ||
descriptions=descriptions, | ||
breaking_descriptions=( | ||
descriptions[1:] if level_bump is LevelBump.MAJOR else [] | ||
), | ||
commit=commit, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,2 @@ | ||
[flake8] | ||
max-line-length=99 | ||
|
||
[semantic_release] | ||
version_variable = setup.py:VERSION | ||
commit_parser=semantic_release_config.parser.parse_commit_message | ||
minor_tag=MINOR: | ||
fix_tag=PATCH: | ||
major_tag=MAJOR: |