diff --git a/cookiecutter.json b/cookiecutter.json index f47efea..7a09679 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -7,7 +7,7 @@ "ci": ["Github", "GitLab", "None"], "jupytext": ["No", "Yes"], "docs": ["Sphinx", "No docs"], - "versioning": ["Bumpversion", "None"], + "versioning": ["Python Semantic Release", "Bumpversion", "None"], "python_package_name": "{{ cookiecutter.__project_name_slug.replace('-', '_') }}", "__package_name": "{{ cookiecutter.python_package_name }}", "_copy_without_render": [".github/workflows/*.yml", ".github/workflows/*.yaml"] diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index a806a90..fc537d4 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -26,6 +26,11 @@ "bump_version.sh" ] +SEMANTIC_RELEASE_FILES = [ + ".github/workflows/check_future_version.yml", + ".github/workflows/release.yml", +] + {% if cookiecutter.ci != "GitLab" %} files_to_be_removed.extend(GITLAB_FILES) {% endif %} @@ -46,6 +51,10 @@ files_to_be_removed.extend(BUMPVERSION_FILES) {% endif %} +{% if cookiecutter.versioning != "Python Semantic Release" %} +files_to_be_removed.extend(SEMANTIC_RELEASE_FILES) +{% endif %} + print("Cleaning files... 🌀") for path in files_to_be_removed: path = Path(path) diff --git a/{{ cookiecutter.repo_name }}/.github/workflows/check_future_version.yml b/{{ cookiecutter.repo_name }}/.github/workflows/check_future_version.yml new file mode 100644 index 0000000..2bd2df2 --- /dev/null +++ b/{{ cookiecutter.repo_name }}/.github/workflows/check_future_version.yml @@ -0,0 +1,22 @@ +name: Check New Version + +on: workflow_dispatch + +jobs: + release: + runs-on: ubuntu-latest + concurrency: release + permissions: + id-token: write + contents: write + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python Semantic Release + uses: python-semantic-release/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + root_options: "-v --noop" \ No newline at end of file diff --git a/{{ cookiecutter.repo_name }}/.github/workflows/release.yml b/{{ cookiecutter.repo_name }}/.github/workflows/release.yml new file mode 100644 index 0000000..74d3682 --- /dev/null +++ b/{{ cookiecutter.repo_name }}/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Semantic Release + +on: + workflow_dispatch: + inputs: + releaseType: + description: "version update type" + required: true + type: choice + default: "automatic" + options: + - "automatic" + - "major" + - "minor" + - "patch" + +jobs: + release: + runs-on: ubuntu-latest + concurrency: release + permissions: + id-token: write + contents: write + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python Semantic Release Manual + id: release_manual + if: ${{ github.event.inputs.releaseType != 'automatic' }} + uses: python-semantic-release/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + force: ${{ github.event.inputs.releaseType }} + changelog: false + + - name: Python Semantic Release Automatic + id: release_automatic + if: ${{ github.event.inputs.releaseType == 'automatic' }} + uses: python-semantic-release/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + changelog: false diff --git a/{{ cookiecutter.repo_name }}/pyproject.toml b/{{ cookiecutter.repo_name }}/pyproject.toml index bff0d5f..8dfe4d5 100644 --- a/{{ cookiecutter.repo_name }}/pyproject.toml +++ b/{{ cookiecutter.repo_name }}/pyproject.toml @@ -138,3 +138,74 @@ exclude_dirs = ["venv"] # B101 disables errors for asserts in the code # remember to not use asserts for security and control flows skips = ["B101"] + +{% if cookiecutter.versioning == "Python Semantic Release" %} +[tool.semantic_release] +assets = [] +commit_message = "{version}\n\nAutomatically generated by python-semantic-release" +commit_parser = "angular" +logging_use_named_masks = false +major_on_zero = false +allow_zero_version = true +tag_format = "v{version}" +version_variables = [ + "src/{{ cookiecutter.__package_name }}/__version__.py:__version__", +] + +[tool.semantic_release.branches.main] +match = "(main|master)" +prerelease_token = "rc" +prerelease = false + +[tool.semantic_release.changelog] +template_dir = "templates" +changelog_file = "CHANGELOG.md" +exclude_commit_patterns = [] + +{%- raw %} +[tool.semantic_release.changelog.environment] +block_start_string = "{%" +block_end_string = "%}" +variable_start_string = "{{" +variable_end_string = "}}" +comment_start_string = "{#" +comment_end_string = "#}" +trim_blocks = false +lstrip_blocks = false +newline_sequence = "\n" +keep_trailing_newline = false +extensions = [] +autoescape = true +{% endraw -%} + +[tool.semantic_release.commit_author] +env = "GIT_COMMIT_AUTHOR" +default = "semantic-release " + +[tool.semantic_release.commit_parser_options] +allowed_tags = [ + "build", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "style", + "refactor", + "test", +] +minor_tags = ["feat"] +patch_tags = ["fix", "perf"] +default_bump_level = 0 + +[tool.semantic_release.remote] +name = "origin" +type = "github" +ignore_token_for_push = false +insecure = false + +[tool.semantic_release.publish] +dist_glob_patterns = ["dist/*"] +upload_to_vcs_release = true +{% endif -%}