Skip to content

Commit

Permalink
feat: add Python Semantic Release (#3631)
Browse files Browse the repository at this point in the history
* feat: added commitizen

* feat: added config for commitizen

* feat: added psr config

* feat: add GitHub Actions workflow for semantic release
  • Loading branch information
derkweijers authored Nov 29, 2024
1 parent 83150a0 commit 63556ea
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 13 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release with Python Semantic Release

on:
workflow_dispatch:


jobs:
release:
runs-on: ubuntu-latest
concurrency: release

env:
UV_INDEX_TSD_USERNAME: ${{ secrets.UV_INDEX_TSD_USERNAME }}
UV_INDEX_TSD_PASSWORD: ${{ secrets.UV_INDEX_TSD_PASSWORD }}

steps:
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.SNAPI_APP_ID }}
private-key: ${{ secrets.SNAPI_PRIVATE_KEY }}

- name: Setup | Install uv
uses: astral-sh/setup-uv@v3

- name: Setup | Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0

- name: Setup | Install the dependecies and project
run: |
uv sync
- name: Release | Run semantic-release
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
uv run semantic-release version
25 changes: 12 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_install_hook_types: [pre-commit, pre-push, commit-msg]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -10,28 +11,18 @@ repos:
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.6.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: []


- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
hooks:
- id: bandit
args: [ "-c", "pyproject.toml" ]
additional_dependencies: [ "bandit[toml]" ]

args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: [ "--py312-plus" ]

args: ["--py312-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
Expand All @@ -41,3 +32,11 @@ repos:
- id: ruff
# Run the formatter.
- id: ruff-format

- repo: https://github.com/commitizen-tools/commitizen
hooks:
- id: commitizen
- id: commitizen-branch
stages:
- pre-push
rev: v4.0.0
86 changes: 86 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
[tool.uv]
dev-dependencies = [
"bandit[toml]>=1.7.9",
"commitizen>=4.0.0",
"coverage>=7.6.1",
"django-filter-stubs>=0.1.3",
"djangorestframework-stubs[compatible-mypy]>=3.14.0,<3.15.0",
Expand All @@ -42,6 +43,7 @@ dev-dependencies = [
"pytest-cov>=5.0.0",
"pytest-django>=4.9.0",
"pytest-env>=1.1.5",
"python-semantic-release>=9.14.0",
"pyupgrade>=3.17.0",
"ruff>=0.6.6",
]
Expand Down Expand Up @@ -78,3 +80,87 @@ build-backend = "hatchling.build"
[[tool.uv.index]]
name = "tsd"
url = "https://pypi.thespacedevs.com/simple/"

# Mainly as fallback, as Python Semenatic Release will also handle this.
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "semver"
version_provider = "pep621"
update_changelog_on_bump = false

[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 = true
allow_zero_version = true
no_git_verify = false
tag_format = "{version}"
version_toml = ["pyproject.toml:project.version"]

[tool.semantic_release.branches.main]
match = "main"
prerelease_token = "rc"
prerelease = false

[tool.semantic_release.branches.beta]
match = "beta"
prerelease_token = "rc"
prerelease = true

[tool.semantic_release.changelog]
exclude_commit_patterns = []
mode = "init"
insertion_flag = "<!-- version list -->"
template_dir = "templates"

[tool.semantic_release.changelog.default_templates]
changelog_file = "CHANGELOG.md"
output_format = "md"

[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 = false

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

[tool.semantic_release.commit_parser_options]
minor_tags = ["feat", "chore"]
patch_tags = ["fix", "perf"]
allowed_tags = [
"feat",
"fix",
"perf",
"build",
"chore",
"ci",
"docs",
"style",
"refactor",
"test",
]
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
Loading

0 comments on commit 63556ea

Please sign in to comment.