From 9db709ad8fe96c7ed524f8083e57b845914e4009 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Montury?=
 <10528250-pytgaen@users.noreply.gitlab.com>
Date: Sat, 11 Jan 2025 22:41:39 +0100
Subject: [PATCH] feat: add auto-release as an optional feature for releases

---
 README.md                      | 1 +
 kicker.json                    | 6 ++++++
 templates/gitlab-ci-python.yml | 7 +++++++
 3 files changed, 14 insertions(+)

diff --git a/README.md b/README.md
index ef3afd0..e4cfdca 100644
--- a/README.md
+++ b/README.md
@@ -403,6 +403,7 @@ The release job is bound to the `publish` stage, appears only on production and
 | Input / Variable        | Description                                                             | Default value     |
 | ----------------------- | ----------------------------------------------------------------------- | ----------------- |
 | `release-enabled` / `PYTHON_RELEASE_ENABLED`| Set to `true` to enable the release job                                 | _none_ (disabled) |
+| `auto-release-enabled` / `PYTHON_AUTO_RELEASE_ENABLED`| When set the job start automatically on production branch. When not set (default), the job is manual. Note that this behavior also depends on release-enabled being set. | _none_ (disabled) |
 | `release-next` / `PYTHON_RELEASE_NEXT`   | The part of the version to increase (one of: `major`, `minor`, `patch`) | `minor`           |
 | `semrel-release-disabled` / `PYTHON_SEMREL_RELEASE_DISABLED`| Set to `true` to disable [semantic-release integration](#semantic-release-integration)   | _none_ (disabled) |
 | `GIT_USERNAME`          | Git username for Git push operations (see below)                        | _none_            |
diff --git a/kicker.json b/kicker.json
index 37a7d3c..5528b9b 100644
--- a/kicker.json
+++ b/kicker.json
@@ -187,6 +187,12 @@
       "description": "Manually trigger a release of your code (uses [bumpversion](https://pypi.org/project/bumpversion/))",
       "enable_with": "PYTHON_RELEASE_ENABLED",
       "variables": [
+        {
+          "name": "PYTHON_AUTO_RELEASE_ENABLED",
+          "description": "When set the job start automatically. When not set (default), the job is manual. Note that this behavior also depends on release-enabled being set.",
+          "type": "boolean",
+          "advanced": true
+        },        
         {
           "name": "PYTHON_RELEASE_NEXT",
           "type": "enum",
diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml
index 0464e88..52b0ea4 100644
--- a/templates/gitlab-ci-python.yml
+++ b/templates/gitlab-ci-python.yml
@@ -130,6 +130,10 @@ spec:
       description: Enable Release
       type: boolean
       default: false
+    auto-release-enabled:
+      description: When set the job start automatically on production branch. When not set (default), the job is manual. Note that this behavior also depends on release-enabled being set.
+      type: boolean
+      default: false
     publish-enabled:
       description: Enable Publish Package
       type: boolean
@@ -292,6 +296,7 @@ variables:
   PYTHON_SBOM_DISABLED: $[[ inputs.sbom-disabled ]]
   PYTHON_RELEASE_ENABLED: $[[ inputs.release-enabled ]]
   PYTHON_PUBLISH_ENABLED: $[[ inputs.publish-enabled ]]
+  PYTHON_AUTO_RELEASE_ENABLED: $[[ inputs.auto-release-enabled ]]
 
   PYTHON_BLACK_ENABLED: $[[ inputs.black-enabled ]]
   PYTHON_ISORT_ENABLED: $[[ inputs.isort-enabled ]]
@@ -1387,6 +1392,8 @@ py-release:
     # exclude if $PYTHON_RELEASE_ENABLED not set
     - if: '$PYTHON_RELEASE_ENABLED != "true"'
       when: never
+    # on production branch: auto if $PYTHON_AUTO_RELEASE_ENABLED set and implicitly $PYTHON_RELEASE_ENABLED set
+    - if: '$PYTHON_AUTO_RELEASE_ENABLED == "true" && $CI_COMMIT_REF_NAME =~ $PROD_REF'
     # on production or integration branch: manual, non blocking
     - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF'
       when: manual
-- 
GitLab