Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Semantic Release support #24

Draft
wants to merge 1 commit into
base: jc/more-build-options
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ci": ["Github", "GitLab", "None"],
"jupytext": ["No", "Yes"],
"docs": ["Sphinx", "No docs"],
"versioning": ["Bumpversion", "None"],
"versioning": ["Python Semantic Release", "Bumpversion", "None"],
"python_package_name": "{{ cookiecutter.__project_name_slug.replace('-', '_') }}",
"__package_name": "{{ cookiecutter.python_package_name }}",
"_copy_without_render": [".github/workflows/*.yml", ".github/workflows/*.yaml"]
Expand Down
9 changes: 9 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bump_version.sh"
]

SEMANTIC_RELEASE_FILES = [
".github/workflows/check_future_version.yml",
".github/workflows/release.yml",
]

{% if cookiecutter.ci != "GitLab" %}
files_to_be_removed.extend(GITLAB_FILES)
{% endif %}
Expand All @@ -46,6 +51,10 @@
files_to_be_removed.extend(BUMPVERSION_FILES)
{% endif %}

{% if cookiecutter.versioning != "Python Semantic Release" %}
files_to_be_removed.extend(SEMANTIC_RELEASE_FILES)
{% endif %}

print("Cleaning files... 🌀")
for path in files_to_be_removed:
path = Path(path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check New Version

on: workflow_dispatch

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-v --noop"
45 changes: 45 additions & 0 deletions {{ cookiecutter.repo_name }}/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Semantic Release

on:
workflow_dispatch:
inputs:
releaseType:
description: "version update type"
required: true
type: choice
default: "automatic"
options:
- "automatic"
- "major"
- "minor"
- "patch"

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Python Semantic Release Manual
id: release_manual
if: ${{ github.event.inputs.releaseType != 'automatic' }}
uses: python-semantic-release/python-semantic-release@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: ${{ github.event.inputs.releaseType }}
changelog: false

- name: Python Semantic Release Automatic
id: release_automatic
if: ${{ github.event.inputs.releaseType == 'automatic' }}
uses: python-semantic-release/python-semantic-release@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
changelog: false
71 changes: 71 additions & 0 deletions {{ cookiecutter.repo_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,74 @@ exclude_dirs = ["venv"]
# B101 disables errors for asserts in the code
# remember to not use asserts for security and control flows
skips = ["B101"]

{% if cookiecutter.versioning == "Python Semantic Release" %}
[tool.semantic_release]
assets = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
major_on_zero = false
allow_zero_version = true
tag_format = "v{version}"
version_variables = [
"src/{{ cookiecutter.__package_name }}/__version__.py:__version__",
]

[tool.semantic_release.branches.main]
match = "(main|master)"
prerelease_token = "rc"
prerelease = false

[tool.semantic_release.changelog]
template_dir = "templates"
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []

{%- raw %}
[tool.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
{% endraw -%}

[tool.semantic_release.commit_author]
env = "GIT_COMMIT_AUTHOR"
default = "semantic-release <semantic-release>"

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"style",
"refactor",
"test",
]
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]
default_bump_level = 0

[tool.semantic_release.remote]
name = "origin"
type = "github"
ignore_token_for_push = false
insecure = false

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true
{% endif -%}
Loading