From abe00fbb4855ebe7d0f1d4355c4b1b52ec815ae3 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Mon, 8 Dec 2025 14:59:55 +0700 Subject: [PATCH 1/3] Introduce gitlab --- copier.yaml | 14 +++++ template/pyproject.toml.jinja | 8 ++- ...e_gitlab_action %}.gitlab-ci{% endif%}.yml | 52 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 template/{% if enable_gitlab_action %}.gitlab-ci{% endif%}.yml diff --git a/copier.yaml b/copier.yaml index 1fda0cc..4a8d812 100644 --- a/copier.yaml +++ b/copier.yaml @@ -26,6 +26,14 @@ repository_namespace: help: Your repository namespace default: "trobz" +git_platform: + type: str + help: Git platform hosting the repository + default: github.com + choices: + - github.com + - gitlab.trobz.com + repository_name: type: str help: | @@ -48,8 +56,14 @@ author_email: enable_github_action: type: bool default: False + when: "{{ git_platform == 'github.com' }}" publish_to_pypi: type: bool default: False when: "{{ enable_github_action }}" + +enable_gitlab_action: + type: bool + default: False + when: "{{ git_platform == 'gitlab.com' }}" diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 8ffb2cf..1a362f3 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -13,7 +13,7 @@ dependencies = [ ] [project.urls] -Repository = "https://github.com/trobz/{{project_name}}" +Repository = "https://{{git_platform}}/trobz/{{project_name}}" [project.scripts] {{ project_name }} = "{{ package_name }}.main:app" @@ -42,12 +42,16 @@ module-name = "{{ package_name }}" module-root = "" -{% if enable_github_action -%} +{% if enable_github_action or enable_gitlab_action -%} [project.optional-dependencies] build = ["uv ~= 0.7.12"] [tool.semantic_release] version_toml = ["pyproject.toml:project.version"] +{% if enable_gitlab_action -%} +type = "gitlab" +{% endif -%} + build_command = """ python -m pip install -e '.[build]' uv lock --upgrade-package {{project_name}} diff --git a/template/{% if enable_gitlab_action %}.gitlab-ci{% endif%}.yml b/template/{% if enable_gitlab_action %}.gitlab-ci{% endif%}.yml new file mode 100644 index 0000000..5442e64 --- /dev/null +++ b/template/{% if enable_gitlab_action %}.gitlab-ci{% endif%}.yml @@ -0,0 +1,52 @@ +stages: + - test + - release + +test: + stage: test + image: python:3.13 + script: + - make test + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: '$CI_COMMIT_BRANCH == "main"' + +# Semantic release job +semantic-release: + stage: release + image: python:3.13 + + # Critical variables for GitLab integration + variables: + GIT_STRATEGY: clone + GIT_DEPTH: 0 # Full git history needed for semantic-release + # Ensure we can make commits + GIT_AUTHOR_NAME: "GitLab CI" + GIT_AUTHOR_EMAIL: "$GITLAB_USER_EMAIL" + GIT_COMMITTER_NAME: "GitLab CI" + GIT_COMMITTER_EMAIL: "$GITLAB_USER_EMAIL" + + before_script: + # Configure git for making commits + - git config --global user.name "GitLab CI" + - git config --global user.email "$GITLAB_USER_EMAIL" + # Checkout the branch (important for pushing changes back) + - git checkout -B "$CI_COMMIT_REF_NAME" + # Ensure we have the remote configured properly for pushing + - git remote set-url origin "https://gitlab-ci-token:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" + + script: + # Install python-semantic-release + - pip install python-semantic-release + # Run semantic release + - semantic-release version --print + - semantic-release version + - semantic-release changelog + - semantic-release publish + + rules: + # Only run on main branch pushes (not merge requests) + - if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"' + + # Allow manual triggering for testing + when: on_success From db35e50790d6c297edbae5a4a31921e1951d986c Mon Sep 17 00:00:00 2001 From: trisdoan Date: Wed, 10 Dec 2025 15:22:06 +0700 Subject: [PATCH 2/3] feat: Allow major version to be zero --- template/pyproject.toml.jinja | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 1a362f3..f625e5e 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -52,6 +52,23 @@ version_toml = ["pyproject.toml:project.version"] type = "gitlab" {% endif -%} +# Commit parser - this should be at the top level +commit_parser = "conventional" + +# Allow 0.x.x versions (prevents jumping straight to 1.0.0) +allow_zero_version = true + +# Don't do major version bumps when in 0.x.x +major_on_zero = false + +# Tag format +tag_format = "v{version}" + +# Branch configuration +[tool.semantic_release.branches.main] +match = "main" +prerelease = false + build_command = """ python -m pip install -e '.[build]' uv lock --upgrade-package {{project_name}} From d7cee8c113231851d7ce833c59181213c1a245c7 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Fri, 26 Dec 2025 11:25:00 +0700 Subject: [PATCH 3/3] fix: ignore invalid-argument-type in test --- template/ty.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/template/ty.toml b/template/ty.toml index 528c2e2..42136b6 100644 --- a/template/ty.toml +++ b/template/ty.toml @@ -1,3 +1,6 @@ +[rules.invalid-argument-type] +ignore = [] + [environment] python = "./.venv" python-version = "3.12"