Commit f3302e4a authored by Gaëtan Montury's avatar Gaëtan Montury
Browse files

feat: add `release-commit-additional-patterns` option (to enable dynamic versioning capabilities)

parent 88ee027b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -463,6 +463,7 @@ The release job is bound to the `publish` stage, appears only on production and
| :lock: `GIT_PASSWORD`   | Git password for Git push operations (see below)                        | _none_            |
| :lock: `GIT_PRIVATE_KEY`| SSH key for Git push operations (see below)                             | _none_            |
| `release-commit-message` / `PYTHON_RELEASE_COMMIT_MESSAGE`| The Git commit message to use on the release commit. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are current_version and new_version. | `chore(python-release): {current_version} → {new_version}  [skip ci on prod]` |
| `release-commit-additional-patterns` / `PYTHON_RELEASE_COMMIT_ADDITIONAL_PATTERNS`| Add additional patterns to git commit when release after bump (with git convention). | `` |

When `py-release` job is enabled, `py-publish` job is automatically enabled too.

+5 −0
Original line number Diff line number Diff line
@@ -233,6 +233,11 @@
          "default": "chore(python-release): {current_version} → {new_version} [skip ci on prod]",
          "advanced": true
        },
        {
          "name": "PYTHON_RELEASE_COMMIT_ADDITIONAL_PATTERNS",
          "description": "Define additional patterns to git commit when release after bump (with git convention).",
          "advanced": true
        },
        {
          "name": "GIT_USERNAME",
          "description": "Git username for Git push operations",
+16 −21
Original line number Diff line number Diff line
@@ -164,6 +164,9 @@ spec:
    release-commit-message:
      description: The Git commit message to use on the release commit. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are current_version and new_version.
      default: "chore(python-release): {current_version} \u2192 {new_version} [skip ci on prod]"
    release-commit-additional-patterns:
      description: Define additional patterns to git commit when release after bump (with git convention).
      default: ""
    repository-url:
      description: |-
        Target PyPI repository to publish packages.
@@ -286,6 +289,7 @@ variables:

  PYTHON_RELEASE_NEXT: $[[ inputs.release-next ]]
  PYTHON_RELEASE_COMMIT_MESSAGE: $[[ inputs.release-commit-message ]]
  PYTHON_RELEASE_COMMIT_ADDITIONAL_PATTERNS: $[[ inputs.release-commit-additional-patterns ]]

  # By default, publish on the Packages registry of the project
  # https://docs.gitlab.com/user/packages/pypi_repository/#authenticate-with-a-ci-job-token
@@ -879,15 +883,18 @@ variables:
    rm -fr tbc_tmp/version.txt >&2
  }

  function py_commit_pyproject() {
  function py_git_tag_commit_release_change() {
    py_cur_version="$1"
    py_next_version="$2"  
    # Git commit and tag
    git add pyproject.toml
    log_info "[git] will commit pyproject.toml ${PYTHON_RELEASE_COMMIT_ADDITIONAL_PATTERNS}"
    # shellcheck disable=SC2086
    git add pyproject.toml ${PYTHON_RELEASE_COMMIT_ADDITIONAL_PATTERNS}
    git status -sb
    # emulate bump-my-version to generate commit message
    py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))")
    git commit -m "$py_commit_message"
    git tag "$py_next_version"  
    git tag --force "$py_next_version"  
  }

  function py_release() {
@@ -920,12 +927,8 @@ variables:
      poetry version ${TRACE+--verbose} "$py_next_version"
      # eval exact next version
      py_next_version=$(poetry version --short)
      # Git commit and tag
      git add pyproject.toml
      # emulate bump-my-version to generate commit message
      py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))")
      git commit -m "$py_commit_message"
      git tag "$py_next_version"

      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
    elif [[ "$PYTHON_BUILD_SYSTEM" =~ ^uv ]]
    then
      maybe_install_build_system
@@ -937,7 +940,6 @@ variables:
          log_info "[uv version] increase \\e[1;94m${PYTHON_RELEASE_NEXT}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
          uv version ${TRACE+--verbose} --bump "$PYTHON_RELEASE_NEXT"
          py_next_version=$(uv version --short)

        else
          log_info "[uv version] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
          uv version ${TRACE+--verbose} "$py_next_version"
@@ -950,22 +952,14 @@ variables:
          uvx --from toml-cli toml get --toml-path pyproject.toml project.version > tbc_tmp/version.txt
          py_cur_version=$(cat tbc_tmp/version.txt)

          log_info "[bump-my-version] increase \\e[1;94m${PYTHON_RELEASE_NEXT}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
          uvx bump-my-version bump ${TRACE+--verbose} --current-version "$py_cur_version" "$PYTHON_RELEASE_NEXT" tbc_tmp/version.txt
          py_next_version=$(cat tbc_tmp/version.txt)
          rm -fr tbc_tmp/version.txt
          py_next_version=$(py_bump_my_version "$py_cur_version" "$PYTHON_RELEASE_NEXT")
        fi

        log_info "[toml-cli] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
        uvx --from toml-cli toml set --toml-path pyproject.toml project.version "$py_next_version"
      fi

      # Git commit and tag
      git add pyproject.toml
      # emulate bump-my-version to generate commit message
      py_commit_message=$(python -c "print('$PYTHON_RELEASE_COMMIT_MESSAGE'.format(current_version='$py_cur_version', new_version='$py_next_version'))")
      git commit -m "$py_commit_message"
      git tag --force "$py_next_version"
      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
    elif [[ "$PYTHON_BUILD_SYSTEM" =~ ^hatch ]]
    then
      maybe_install_build_system
@@ -978,7 +972,8 @@ variables:
      log_info "[hatch] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
      _pip install toml-cli
      _run toml set --toml-path pyproject.toml project.version "$py_next_version"
      py_commit_pyproject "$py_cur_version" "$py_next_version"

      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
    else
      # Setuptools / bump-my-version
      # shellcheck disable=SC2086