From fd07d1dffb468a101c0bf08cf5260dbaaff1e6cf Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Tue, 29 Aug 2023 05:52:58 +0000 Subject: [PATCH] Further integration with GitLab/GitHub. --- .github/workflows/ci.yml | 4 ++- .vscode/settings.json | 4 ++- README.md.jinja | 12 ++++++-- ...'gitlab' %].gitlab-ci.yml[% endif %].jinja | 0 .../FUNDING.yml.jinja | 0 .../workflows/ci.yml.jinja | 4 ++- .../workflows/readthedocs-preview.yml.jinja | 0 .../workflows/release.yml.jinja | 0 copier.yaml | 21 ++++++++------ includes/variable.jinja | 28 +++++++++++++++++++ pyproject.toml.jinja | 6 ++-- 11 files changed, 63 insertions(+), 16 deletions(-) rename [% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja => [% if ci == 'gitlab' %].gitlab-ci.yml[% endif %].jinja (100%) rename {[% if ci=='github' or ci == 'both' %].github[% endif %] => [% if ci=='github' %].github[% endif %]}/FUNDING.yml.jinja (100%) rename {[% if ci=='github' or ci == 'both' %].github[% endif %] => [% if ci=='github' %].github[% endif %]}/workflows/ci.yml.jinja (95%) rename {[% if ci=='github' or ci == 'both' %].github[% endif %] => [% if ci=='github' %].github[% endif %]}/workflows/readthedocs-preview.yml.jinja (100%) rename {[% if ci=='github' or ci == 'both' %].github[% endif %] => [% if ci=='github' %].github[% endif %]}/workflows/release.yml.jinja (100%) create mode 100644 includes/variable.jinja diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fa448d4..30b1f2d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,9 @@ jobs: rm -rf src/serious_scaffold rm -rf .github rm -rf .gitlab-ci.yml - copier copy -x '!src/serious_scaffold' -d ci=both -r HEAD -f . . + copier copy -x '!src/serious_scaffold' -d repo_host_choice=gitlab -r HEAD -f . . + rm .copier-answers.yml + copier copy -r HEAD -f . . - run: git diff - run: git status --porcelain - run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index aebf53aa..c30d1f39 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -79,6 +79,9 @@ "author_name", "organization_name", "author_email", + "repo_host_choice", + "repo_host", + "ci", "repo_namespace", "repo_name", "package_name", @@ -87,7 +90,6 @@ "min_py", "max_py", "default_py", - "ci", "choices", "stages", "default", diff --git a/README.md.jinja b/README.md.jinja index c1db7b64..d2bd18e6 100644 --- a/README.md.jinja +++ b/README.md.jinja @@ -1,11 +1,14 @@ +[% from pathjoin("includes", "variable.jinja") import ci_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import license_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] # {{ project_name }} {{ project_description }} -[![CI Status](https://github.com/{{ repo_namespace }}/{{ repo_name }}/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/{{ repo_namespace }}/{{ repo_name }}/actions/workflows/ci.yml) +{{ ci_badge() }} [![codecov](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}/branch/main/graph/badge.svg?token=4JPKXI122N)](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}) [![Documentation Status](https://readthedocs.org/projects/{{ repo_name }}/badge/)](https://{{ repo_name }}.readthedocs.io/) -[![GitHub](https://img.shields.io/github/license/{{ repo_namespace }}/{{ repo_name }})](https://github.com/{{ repo_namespace }}/{{ repo_name }}/blob/main/LICENSE) +{{ license_badge() }} [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/{{ package_name }})](https://pypi.org/project/{{ package_name }}/) [![PyPI](https://img.shields.io/pypi/v/{{ package_name }})](https://pypi.org/project/{{ package_name }}/) @@ -16,12 +19,15 @@ [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/5697b1e4c4a9790ece607654e6c02a160620c7e1/docs/badge/v2.json)](https://pydantic.dev) [![Serious Scaffold Python](https://img.shields.io/badge/serious%20scaffold-python-blue)](https://github.com/serious-scaffold/serious-scaffold-python) -[![{{ project_name }}](docs/_static/images/logo.svg)](https://github.com/{{ repo_namespace }}/{{ repo_name }}) +[![{{ project_name }}](docs/_static/images/logo.svg)](https://{{ repo_url() }}) Setting up a project often involves more than just establishing a basic project structure. It involves tasks like integrating GitHub Actions or GitLab CI/CD, configuring lint, test and documentation, as well as implementing settings, logging and other frequently used modules. [Serious Scaffold Python](https://github.com/serious-scaffold/serious-scaffold-python) streamlines this process. Powered by [`copier`](https://copier.readthedocs.io/), bootstrapping a new Python project can be done with a single command. By answering a few questions, the project will be fully configured and ready for development. Furthermore, the project can be updated alongside the advancement of the template. +[% if repo_host_choice == 'github' -%] If you find this helpful, please consider [sponsorship](https://github.com/sponsors/{{ author_name }}). +[% endif -%] + ## :hammer_and_wrench: Features - Project setup and template update with [`copier`](https://copier.readthedocs.io/). diff --git a/[% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja b/[% if ci == 'gitlab' %].gitlab-ci.yml[% endif %].jinja similarity index 100% rename from [% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja rename to [% if ci == 'gitlab' %].gitlab-ci.yml[% endif %].jinja diff --git a/[% if ci=='github' or ci == 'both' %].github[% endif %]/FUNDING.yml.jinja b/[% if ci=='github' %].github[% endif %]/FUNDING.yml.jinja similarity index 100% rename from [% if ci=='github' or ci == 'both' %].github[% endif %]/FUNDING.yml.jinja rename to [% if ci=='github' %].github[% endif %]/FUNDING.yml.jinja diff --git a/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/ci.yml.jinja b/[% if ci=='github' %].github[% endif %]/workflows/ci.yml.jinja similarity index 95% rename from [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/ci.yml.jinja rename to [% if ci=='github' %].github[% endif %]/workflows/ci.yml.jinja index 21838659..442c9171 100644 --- a/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/ci.yml.jinja +++ b/[% if ci=='github' %].github[% endif %]/workflows/ci.yml.jinja @@ -80,7 +80,9 @@ jobs: rm -rf src/serious_scaffold rm -rf .github rm -rf .gitlab-ci.yml - copier copy -x '!src/serious_scaffold' -d ci=both -r HEAD -f . . + copier copy -x '!src/serious_scaffold' -d repo_host_choice=gitlab -r HEAD -f . . + rm .copier-answers.yml + copier copy -r HEAD -f . . - run: git diff - run: git status --porcelain - run: | diff --git a/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja b/[% if ci=='github' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja similarity index 100% rename from [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja rename to [% if ci=='github' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja diff --git a/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/release.yml.jinja b/[% if ci=='github' %].github[% endif %]/workflows/release.yml.jinja similarity index 100% rename from [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/release.yml.jinja rename to [% if ci=='github' %].github[% endif %]/workflows/release.yml.jinja diff --git a/copier.yaml b/copier.yaml index ac319ec0..71d56a64 100644 --- a/copier.yaml +++ b/copier.yaml @@ -37,6 +37,19 @@ author_email: [%- endif %] help: 'Specify the email address of the author:' type: str +repo_host_choice: + choices: + GitHub: github.com + GitLab: gitlab.com + GitLab (self-managed): gitlab-self-managed + default: github + help: 'Choose the host for the repository:' + type: str +repo_host: + defaults: '{{ repo_host_choice }}' + help: 'Specify the host of the self-managed GitLab:' + type: str + when: '{{ repo_host_choice == gitlab-self-managed }}' repo_namespace: default: '{{ organization_name|lower|replace(" ", "-") }}' help: 'Indicate the GitHub Repository Owner or GitLab Namespace. This is typically the account name of the author or the organization:' @@ -100,11 +113,3 @@ default_py: default: '{{ max_py }}' help: 'Choose the default Python version for development, documentation generation, and package build:' type: str -ci: - choices: - Both (for test only): both - GitHub Actions: github - GitLab CI: gitlab - default: github - help: 'Choose the Continuous Integration service to use:' - type: str diff --git a/includes/variable.jinja b/includes/variable.jinja new file mode 100644 index 00000000..381f80e6 --- /dev/null +++ b/includes/variable.jinja @@ -0,0 +1,28 @@ +[% macro repo_url() -%] + {{ repo_host }}/{{ repo_namespace }}/{{ repo_name }} +[%- endmacro %] + +[% macro repo_base_url() -%] + [% if repo_host_choice == 'github' -%] + {{ repo_url() }} + [%- else -%] {# Base url for GitLab and self-managed GitLab #} + {{ repo_url() }}/- + [%- endif %] +[%- endmacro %] + +[% macro ci_badge() -%] + [% if repo_host_choice == 'github' -%] + [![CI Status](https://{{ repo_url() }}/actions/workflows/ci.yml/badge.svg?branch=main)](https://{{ repo_url() }}/actions/workflows/ci.yml) + [%- elif repo_host_choice == 'gitlab' -%] + [![pipeline status](https://{{ repo_url() }}/badges/main/pipeline.svg)](https://{{ repo_base_url() }}/commits/main) + [%- endif %] +[%- endmacro %] + +[% macro license_badge() -%] + [% if repo_host_choice == 'github' -%] + [![GitHub](https://img.shields.io/github/license/{{ repo_namespace }}/{{ repo_name }})] + [%- elif repo_host_choice == 'gitlab' -%] + [![GitLab](https://img.shields.io/gitlab/license/{{ repo_namespace }}/{{ repo_name }}?gitlab_url=https%3A%2F%2F{{ repo_host() }})] + [%- endif -%] + (https://{{ repo_base_url() }}/blob/main/LICENSE) +[%- endmacro %] diff --git a/pyproject.toml.jinja b/pyproject.toml.jinja index a39a047c..98211b97 100644 --- a/pyproject.toml.jinja +++ b/pyproject.toml.jinja @@ -1,3 +1,5 @@ +[% from pathjoin("includes", "variable.jinja") import repo_base_url with context -%] +[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] [% from pathjoin("includes", "version_compare.jinja") import version_between -%] [build-system] build-backend = "setuptools.build_meta" @@ -45,8 +47,8 @@ requires-python = ">={{ min_py }}" {{ package_name }}-cli = "{{ module_name }}.cli:app" [project.urls] -homepage = "https://github.com/{{ repo_namespace }}/{{ repo_name }}/" -issue = "https://github.com/{{ repo_namespace }}/{{ repo_name }}/issues" +homepage = "https://{{ repo_url() }}/" +issue = "https://{{ repo_base_url() }}/issues" [tool.coverage.report] fail_under = {{ coverage_threshold }}