diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 32fe862..e1eed44 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,10 @@ jobs: uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 - name: Install dependencies run: uv sync + - name: Set git identity + run: | + git config --global user.email "ci-example-user@xomnia.com" + git config --global user.name "CI Example User" - name: Run pytest run: uv run pytest # Single aggregate check to require in the branch ruleset. It depends on diff --git a/copier.yml b/copier.yml index ec19824..6ac0de2 100644 --- a/copier.yml +++ b/copier.yml @@ -13,6 +13,13 @@ _tasks: - "git checkout -b main" - "uv sync" - "uv run pre-commit install" + - "git add --all -- :!branch_protection_rules.json" + - "git commit -m \"chore: initial commit\"" + - command: gh repo create {{ github_username }}/{{ project_github_name }} --source=. --push --private + when: "{{ push_to_github }}" + - command: "gh api --method PUT -H \"Accept: application/vnd.github+json\" repos/{{ github_username }}/{{ project_github_name }}/branches/main/protection --input branch_protection_rules.json" + when: "{{ push_to_github }}" + - rm branch_protection_rules.json # Questions @@ -29,7 +36,7 @@ author_email: github_username: type: str help: GitHub username or organization - default: "{{ author_name | lower | replace(' ', '') }}" + default: "XomniaAi" project_name: type: str @@ -53,6 +60,11 @@ project_slug: and underscores only, and it may not start with a digit. {% endif %} +project_github_name: + type: str + default: "{{ project_slug | lower | replace('_', '-') }}" + when: false + project_short_description: type: str help: A short description of the project @@ -81,3 +93,10 @@ include_hexagonal: adapters layers with an example slice, plus import-linter contracts that enforce the layer boundaries. default: true + +push_to_github: + type: bool + help: >- + Push the repository to GitHub. Auto-applies standard branch protection rules + standard for trunk-based development. (e.g. one main branch) + default: true \ No newline at end of file diff --git a/template/README.md.jinja b/template/README.md.jinja index 2912efb..7f983cf 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -1,12 +1,12 @@ # {{ project_name }} -[![Tests](https://github.com/{{ github_username }}/{{ project_slug }}/actions/workflows/ci.yaml/badge.svg)](https://github.com/{{ github_username }}/{{ project_slug }}/actions/workflows/ci.yaml) +[![Tests](https://github.com/{{ github_username }}/{{ project_github_name }}/actions/workflows/ci.yaml/badge.svg)](https://github.com/{{ github_username }}/{{ project_github_name }}/actions/workflows/ci.yaml) [![PyPI version](https://badge.fury.io/py/{{ project_slug | replace('_', '-') }}.svg)](https://pypi.org/project/{{ project_slug | replace('_', '-') }}/) {{ project_short_description }} -Original repository: [https://github.com/{{ github_username }}/{{ project_slug }}](https://github.com/{{ github_username }}/{{ project_slug }}) +Original repository: [https://github.com/{{ github_username }}/{{ project_github_name }}](https://github.com/{{ github_username }}/{{ project_github_name }}) {% if include_hexagonal -%} diff --git a/template/branch_protection_rules.json b/template/branch_protection_rules.json new file mode 100644 index 0000000..6984163 --- /dev/null +++ b/template/branch_protection_rules.json @@ -0,0 +1,19 @@ +{ + "allow_deletions": false, + "allow_force_pushes": false, + "enforce_admins": true, + "required_linear_history": false, + "required_pull_request_reviews": { + "dismiss_stale_reviews": true, + "require_code_owner_reviews": false, + "require_last_push_approval": true, + "required_approving_review_count": 1 + }, + "required_status_checks": { + "contexts": [ + "ci-gate" + ], + "strict": true + }, + "restrictions": null +} diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index c0f0ae2..ef8d00a 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -25,8 +25,8 @@ dependencies = [ ] [project.urls] -Homepage = "https://github.com/{{ github_username }}/{{ project_slug }}" -Repository = "https://github.com/{{ github_username }}/{{ project_slug }}" +Homepage = "https://github.com/{{ github_username }}/{{ project_github_name }}" +Repository = "https://github.com/{{ github_username }}/{{ project_github_name }}" [tool.hatch.build.targets.wheel] packages = ["src/{{ project_slug }}"] diff --git a/tests/test_template.py b/tests/test_template.py index e971b86..2bb44d6 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -47,6 +47,7 @@ def _triggers(workflow: dict) -> dict: "project_short_description": "A test project.", "version": "0.1.0", "license": "MIT", + "push_to_github": False } @@ -327,7 +328,7 @@ def test_default_slug_is_valid_package_name(tmp_path): copier.run_copy( src_path=str(TEMPLATE_ROOT), dst_path=str(dst), - data={"author_name": "Joe Doe", "author_email": "joe@example.com"}, + data={"author_name": "Joe Doe", "author_email": "joe@example.com", "push_to_github": False}, defaults=True, unsafe=True, vcs_ref="HEAD",