Skip to content
Merged
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
97 changes: 97 additions & 0 deletions .cz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

[tool.commitizen]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved commitizen logic to this file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cz.toml require a [tool.commitizen] section? isn't that a pyproject.toml thing? I would expect options here to be flat.

Copy link
Collaborator Author

@sdn4z sdn4z Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd make sense yeah. Based on the docs it is expected this way though.

version_files = ["pyproject.toml:version"]
version = "2.8.28"
tag_format = "v$version"
name = "cz_customize"

[tool.commitizen.customize]
message_template = "{{prefix}}{% if scope %}({{scope}}){% endif %}: {{subject}}{% if body %}\n\n{{body}}{% endif %}{% if is_breaking_change %}\n\nBREAKING CHANGE: {{footer}}{% else %}\n\n{{footer}}{% endif %}"

bump_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?"
change_type_order = [
"BREAKING CHANGE",
"Feat",
"Fix",
"Refactor",
"Perf",
"CI",
"Docs",
"Technical",
"Tests",
]
bump_message = "bump: version $current_version → $new_version"
schema = "<type>(<scope>): <subject>\n<BLANK LINE>\n<body>\n<BLANK LINE>\n(BREAKING CHANGE: )<footer>"
schema_pattern = "(?s)(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\\(\\S+\\))?!?:( [^\\n\\r]+)((\\n\\n.*)|(\\s*))?$"
commit_parser = "^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE|ci|docs|style|test|chore|revert|build)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?"
version_parser = "(?P<version>([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?(\\w+)?)"
changelog_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?" # same as bump_pattern
[tool.commitizen.customize.bump_map]
"^.+!$" = "MAJOR"
"^BREAKING[\\-\\ ]CHANGE" = "MAJOR"
"^feat" = "MINOR"
"^fix" = "PATCH"
"^refactor" = "PATCH"
"^perf" = "PATCH"
"^ci" = "PATCH"
"^docs" = "PATCH"
"^style" = "PATCH"
"^test" = "PATCH"
"^chore" = "PATCH"
"^revert" = "PATCH"
"^build" = "PATCH"

[tool.commitizen.customize.change_type_map]
"feat" = "Feat"
"fix" = "Fix"
"refactor" = "Refactor"
"perf" = "Perf"
"ci" = "CI"
"docs" = "Docs"
"style" = "Technical"
"test" = "Tests"
"chore" = "Technical"
"revert" = "Fix"
"build" = "Technical"

[[tool.commitizen.customize.questions]]
type = "list"
name = "prefix"
message = "Select the type of change you are committing"
choices = [
{ value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer", key = "x" },
{ value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer", key = "f" },
{ value = "docs", name = "docs: Documentation only changes", key = "d" },
{ value = "style", name = "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)", key = "s" },
{ value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature", key = "r" },
{ value = "perf", name = "perf: A code change that improves performance", key = "p" },
{ value = "test", name = "test: Adding missing or correcting existing tests", key = "t" },
{ value = "build", name = "build: Changes that affect the build system or external dependencies (example scopes: pip, docker, npm)", key = "b" },
{ value = "ci", name = "ci: Changes to our CI configuration files and scripts (example scopes: GitLabCI)", key = "c" },
]

[[tool.commitizen.customize.questions]]
type = "input"
name = "scope"
message = "What is the scope of this change? ((story number, class or file name): (press [enter] to skip)\n"

[[tool.commitizen.customize.questions]]
type = "input"
name = "subject"
message = "Write a short and imperative summary of the code changes: (lower case and no period)\n"

[[tool.commitizen.customize.questions]]
type = "input"
name = "body"
message = "Provide additional contextual information about the code changes: (press [enter] to skip)\n"

[[tool.commitizen.customize.questions]]
type = "confirm"
message = "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer"
name = "is_breaking_change"
default = false

[[tool.commitizen.customize.questions]]
type = "input"
name = "footer"
message = "Footer. Information about Breaking Changes and reference issues that this commit closes: (press [enter] to skip)\n"
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
uses: dependabot/fetch-metadata@a3e5f86ae9f2f49b441498973ddec20035d326b8 # v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
Expand Down
102 changes: 102 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This workflow builds the package, installs it, and tests basic functionality

name: Build and Test Package

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
test-build-package:
name: Test package build
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'bump:')"

steps:
- name: Check out the repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install uv
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6.4.1

- name: Build the package
run: uv build

- name: List built artifacts
run: ls -la dist/

- name: Install the built wheel
run: |
uv venv
# Find the wheel file and install it
WHEEL_FILE=$(ls dist/*.whl | head -1)
echo "Installing wheel: $WHEEL_FILE"
uv pip install "$WHEEL_FILE"

- name: Test --version flag
run: |
# Test that the CLI is available and --version works
uv run twyn --version

should-test-docker-build:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always testing if the docker image can be built would result in very slow builds. Instead, we only try to build it if there were any changes in the Dockerfile or .dockerignore files (the latter does not exist yet, but it's more future proof this way).

permissions:
contents: read
pull-requests: read
name: Check if should `test_docker_build` run
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'bump:')"
steps:
- name: Check out the repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Check if Dockerfile changed
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: dockerfile-changes
with:
filters: |
dockerfile:
- 'Dockerfile'
- '.dockerignore'
outputs:
docker: ${{ steps.dockerfile-changes.outputs.dockerfile }}

test-docker-build:
needs: [should-test-docker-build]
name: Test Docker build
runs-on: ubuntu-latest
if: needs.should-test-docker-build.outputs.docker == 'true' && !startsWith(github.event.head_commit.message, 'bump:')
permissions:
contents: read
packages: read
steps:
- name: Check out the repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Log in to GitHub Container Registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: elementsinteractive/twyn

- name: Build Docker image
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
file: ./Dockerfile
push: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll try to use cache in case it exists. This cache is ONLY created when publishing the package. We should never override this cache from a PR.

26 changes: 18 additions & 8 deletions .github/workflows/bumpversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ jobs:
bump_version:
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
container:
image: commitizen/commitizen:4.8.3@sha256:08a078c52b368f85f34257a66e10645ee74d8cbe9b471930b80b2b4e95a9bd4a

name: "Bump version and create changelog with commitizen"
steps:
- uses: actions/create-github-app-token@v1
- uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1.12.0
id: app-token
with:
app-id: ${{ vars.ELEMENTSINTERACTIVE_BOT_APP_ID }}
private-key: ${{ secrets.ELEMENTSINTERACTIVE_BOT_PRIVATE_KEY }}
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.head_ref }}
# Make sure the value of GITHUB_TOKEN will not be persisted in repo's config
persist-credentials: false

- name: Configure git
run: |
git config --global --add safe.directory "*"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- id: cz
name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ steps.app-token.outputs.token }}
run: |
cz bump --yes --changelog
git push origin HEAD:main
git push origin --tags

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
run: echo "Bumped to version $(cz version -p)"
6 changes: 3 additions & 3 deletions .github/workflows/conventional-label.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
on:
pull_request_target:
types: [ opened, edited ]
types: [opened, edited]
name: conventional-release-labels
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: bcoe/conventional-release-labels@v1
- uses: bcoe/conventional-release-labels@886f696738527c7be444262c327c89436dfb95a8 #v1.3.1
with:
type_labels: '{"feat": "feature", "fix": "fix", "breaking": "breaking", "ci": "CI"}'
type_labels: '{"feat": "feature", "fix": "fix", "BREAKING CHANGE": "breaking", "ci": "CI", "build": "build", "refactor": "refactor", "test": "test"}'
2 changes: 1 addition & 1 deletion .github/workflows/lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
exit 1

- name: Checkout PR code
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: refs/pull/${{ github.event.issue.number }}/merge

Expand Down
45 changes: 25 additions & 20 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,40 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'bump:')"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install uv
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6.4.1

- name: Install the project
run: uv sync --locked --group dev

- name: Cache mypy cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.1
with:
python-version: "3.13"
- name: Install just
run: |
sudo apt update
sudo snap install --edge --classic just
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install
path: .mypy_cache
key: mypy-${{ runner.os }}
restore-keys: |
mypy-${{ runner.os }}

- name: Lint
run: |
just lint
uv run ruff format --check src tests
uv run ruff check src tests
uv run mypy src tests

lint-commit:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'bump:')"
name: "Lint commit message"
container:
image: commitizen/commitizen:4.8.3@sha256:08a078c52b368f85f34257a66e10645ee74d8cbe9b471930b80b2b4e95a9bd4a
steps:
- name: Check out
uses: actions/checkout@v4
- name: Install commitizen
run: |
python -m pip install --upgrade pip
python -m pip install commitizen
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Check commit message
run: cz check --rev-range HEAD
run: |
git config --global --add safe.directory /__w/twyn/twyn
cz check --rev-range HEAD
Loading