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..f625e5e 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,33 @@ 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 -%} + +# 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}} 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" 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