1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
from enum import Enum
from pathlib import Path
import git
import semantic_release
from semantic_release.cli.commands.main import Cli
PROJ_DIR = Path(__file__).parent.parent.absolute().resolve()
class RepoActionStep(str, Enum):
CONFIGURE = "CONFIGURE"
WRITE_CHANGELOGS = "WRITE_CHANGELOGS"
GIT_CHECKOUT = "GIT_CHECKOUT"
GIT_COMMIT = "GIT_COMMIT"
GIT_MERGE = "GIT_MERGE"
GIT_SQUASH = "GIT_SQUASH"
GIT_TAG = "GIT_TAG"
RELEASE = "RELEASE"
MAKE_COMMITS = "MAKE_COMMITS"
A_FULL_VERSION_STRING = "1.11.567"
A_PRERELEASE_VERSION_STRING = "2.3.4-dev.23"
A_FULL_VERSION_STRING_WITH_BUILD_METADATA = "4.2.3+build.12345"
EXAMPLE_REPO_OWNER = "example_owner"
EXAMPLE_REPO_NAME = "example_repo"
EXAMPLE_HVCS_DOMAIN = "example.com"
DEFAULT_BRANCH_NAME = "main"
INITIAL_COMMIT_MESSAGE = "Initial commit"
MAIN_PROG_NAME = str(semantic_release.__name__).replace("_", "-")
SUCCESS_EXIT_CODE = 0
CHANGELOG_SUBCMD = Cli.SubCmds.CHANGELOG.name.lower()
GENERATE_CONFIG_SUBCMD = Cli.SubCmds.GENERATE_CONFIG.name.lower()
PUBLISH_SUBCMD = Cli.SubCmds.PUBLISH.name.lower()
VERSION_SUBCMD = Cli.SubCmds.VERSION.name.lower()
NULL_HEX_SHA = git.Object.NULL_HEX_SHA
COMMIT_MESSAGE = "{version}\n\nAutomatically generated by python-semantic-release\n"
SUPPORTED_ISSUE_CLOSURE_PREFIXES = [
"Close",
"Closes",
"Closed",
"Closing",
"Fix",
"Fixes",
"Fixed",
"Fixing",
"Resolve",
"Resolves",
"Resolved",
"Resolving",
"Implement",
"Implements",
"Implemented",
"Implementing",
]
CONVENTIONAL_COMMITS_CHORE = ("ci: added a commit lint job\n",)
# Different in-scope commits that produce a certain release type
CONVENTIONAL_COMMITS_PATCH = (
*CONVENTIONAL_COMMITS_CHORE,
"fix: fixed voltage in the flux capacitor\n",
)
CONVENTIONAL_COMMITS_MINOR = (
*CONVENTIONAL_COMMITS_PATCH,
"feat: last minute rush order\n",
)
# Take previous commits and insert a breaking change
CONVENTIONAL_COMMITS_MAJOR = (
*CONVENTIONAL_COMMITS_MINOR,
"fix!: big change\n\nBREAKING CHANGE: reworked something for previous feature\n",
)
EMOJI_COMMITS_CHORE = (
":broom: updated lint & code style\n",
":none: updated ci pipeline\n",
)
EMOJI_COMMITS_PATCH = (
*EMOJI_COMMITS_CHORE,
":bug: fixed voltage in the flux capacitor\n",
)
EMOJI_COMMITS_MINOR = (
*EMOJI_COMMITS_PATCH,
":sparkles::pencil: docs for something special\n",
# Emoji in description should not be used to evaluate change type
":sparkles: last minute rush order\n\nGood thing we're 10x developers :boom:\n",
)
EMOJI_COMMITS_MAJOR = (
*EMOJI_COMMITS_MINOR,
":boom: Move to the blockchain\n",
)
# Note - the scipy commit fixtures for commits that should evaluate to the various scopes
# are in tests/fixtures/scipy
EXAMPLE_PROJECT_NAME = "example"
EXAMPLE_PROJECT_VERSION = "0.0.0"
EXAMPLE_PROJECT_LICENSE = "MIT"
# Uses the internal defaults of semantic-release unless otherwise needed for testing
# modify the pyproject toml as necessary for the test using update_pyproject_toml()
# and derivative fixtures
EXAMPLE_PYPROJECT_TOML_CONTENT = rf"""
[project]
license-expression = "{EXAMPLE_PROJECT_LICENSE}"
[tool.poetry]
name = "{EXAMPLE_PROJECT_NAME}"
version = "{EXAMPLE_PROJECT_VERSION}"
description = "Just an example"
license = "{EXAMPLE_PROJECT_LICENSE}"
authors = ["semantic-release <not-a.real@email.com>"]
readme = "README.md"
classifiers = [
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only"
]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.semantic_release]
version_variables = [
"src/{EXAMPLE_PROJECT_NAME}/_version.py:__version__",
]
version_toml = ["pyproject.toml:tool.poetry.version"]
""".lstrip()
EXAMPLE_SETUP_CFG_CONTENT = rf"""
[metadata]
name = example
version = {EXAMPLE_PROJECT_VERSION}
description = Just an example really
long_description = file: README.md
long_description_content_type = text/markdown
author = semantic-release
author_email = not-a.real@email.com
url = https://github.com/python-semantic-release/python-semantic-release
python_requires = >=3.7
[options]
zip_safe = True
include_package_data = True
packages = find:
install_requires =
PyYAML==6.0
pydantic==1.9.0
[options.extras_require]
dev =
tox
twine==3.1.1
test =
pytest
pytest-cov
pytest-mock
pytest-aiohttp
lint =
flake8
black>=22.6.0
isort>=5.10.1
[options.packages.find]
exclude =
test*
[bdist_wheel]
universal = 1
[coverage:run]
omit = */tests/*
[tools:pytest]
python_files = tests/test_*.py tests/**/test_*.py
[isort]
skip = .tox,venv
default_section = THIRDPARTY
known_first_party = {EXAMPLE_PROJECT_NAME},tests
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
[flake8]
max-line-length = 88
""".lstrip()
EXAMPLE_SETUP_PY_CONTENT = rf"""
import re
import sys
from setuptools import find_packages, setup
def _read_long_description():
try:
with open("readme.rst") as fd:
return fd.read()
except Exception:
return None
with open("{EXAMPLE_PROJECT_NAME}/_version.py", "r") as fd:
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE
).group(1)
try:
from semantic_release import setup_hook
setup_hook(sys.argv)
except ImportError:
pass
setup(
name="{EXAMPLE_PROJECT_NAME}",
version="{EXAMPLE_PROJECT_VERSION}",
url="http://github.com/python-semantic-release/python-semantic-release",
author="semantic-release",
author_email="not-a.real@email.com",
description="Just an example",
long_description=_read_long_description(),
packages=find_packages(exclude=("tests",)),
license="MIT",
install_requires=[
"click>=7,<9",
"click_log>=0.3,<1",
"gitpython>=3.0.8,<4",
"invoke>=1.4.1,<2",
"semver>=2.10,<3",
"twine>=3,<4",
"requests>=2.25,<3",
"wheel",
"python-gitlab>=2,<4",
# tomlkit used to be pinned to 0.7.0
# See https://github.com/python-semantic-release/python-semantic-release/issues/336
# and https://github.com/python-semantic-release/python-semantic-release/pull/337
# and https://github.com/python-semantic-release/python-semantic-release/issues/491
"tomlkit~=0.10",
"dotty-dict>=1.3.0,<2",
"dataclasses==0.8; python_version < '3.7.0'",
"packaging",
],
extras_require={{
"test": [
"coverage>=5,<6",
"pytest>=5,<6",
"pytest-xdist>=1,<2",
"pytest-mock>=2,<3",
"pytest-lazy-fixture~=0.6.3",
"responses==0.13.3",
"mock==1.3.0",
],
"docs": ["Sphinx==1.3.6", "Jinja2==3.0.3"],
"dev": ["tox", "isort", "black"],
"mypy": ["mypy", "types-requests"],
}},
include_package_data=True,
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)
""".lstrip()
EXAMPLE_CHANGELOG_MD_CONTENT = r"""
# CHANGELOG
<!-- This is an example changelog -->
## v1.0.0
* Various bugfixes, security enhancements
* Extra cookies to enhance your experience
* ~Removed~ simplified cookie opt-out handling logic
""".lstrip()
EXAMPLE_CHANGELOG_RST_CONTENT = r"""
.. _changelog:
=========
CHANGELOG
=========
..
example project base changelog
.. _changelog-v1.0.0:
v1.0.0 (1970-01-01)
===================
* Various bugfixes, security enhancements
* Extra cookies to enhance your experience
* ~Removed~ simplified cookie opt-out handling logic
""".lstrip()
EXAMPLE_RELEASE_NOTES_TEMPLATE = r"""
## What's Changed
{% for type_, commits in release["elements"] | dictsort
%}{{ "### %s" | format(type_ | title)
}}{% if type_ != "unknown"
%}{% for commit in commits
%}{{ "* %s" | format(commit.descriptions[0] | trim)
}}{% endfor
%}{% endif
%}{% endfor
%}
""".lstrip() # noqa: E501
RELEASE_NOTES = "# Release Notes"
DEFAULT_MERGE_STRATEGY_OPTION = "theirs"
|