From 7da51d54d7266771eeccc050b3c53d8f27edf066 Mon Sep 17 00:00:00 2001
From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com>
Date: Sun, 12 May 2024 23:17:10 +0200
Subject: [PATCH] add prefix and suffix

---
 CHANGELOG.md                       |  6 +++
 README.md                          | 81 ++++++++++++++++++++++++++++--
 templates/release-by-changelog.yml | 17 +++++--
 3 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a4815a..0ab096a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+* More documentation
+
+### Added
+
+* Prefix and suffix to tag and release name
+
 ## [0.3.4] - 2024-05-12
 
 * Better documentation
diff --git a/README.md b/README.md
index 3942512..23370e6 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,81 @@ release-by-changelog:
 
 You can customize the job by overriding the following variables:
 
-| Name                 | Description                        | Default          |
-|----------------------|------------------------------------|------------------|
-| `CHANGELOG_FILEPATH` | The path to the CHANGELOG.md file. | `"CHANGELOG.md"` |
+| Name                 | Description                                   | Default          |
+|----------------------|-----------------------------------------------|------------------|
+| `CHANGELOG_FILEPATH` | The path to the CHANGELOG.md file.            | `"CHANGELOG.md"` |
+| `PREFIX`             | Value to prepend to the tag and release name. |                  |
+| `SUFFIX`             | Value to append to the tag and release name.  |                  |
+| `TAG_PREFIX`         | Value to prepend to the tag.                  | `$PREFIX`        |
+| `TAG_SUFFIX`         | Value to append to the tag.                   | `$SUFFIX`        |
+| `NAME_PREFIX`        | Value to prepend to the release name.         | `$PREFIX`        |
+| `NAME_SUFFIX`        | Value to append to the release name.          | `$SUFFIX`        |
+
+## About `CHANGELOG.md`
+
+### Unreleased changes
+
+The `CHANGELOG.md` file may have an `Unreleased` section at the top of the file.
+This section is used to keep track of changes that are not yet released.
+
+Example:
+
+```markdown
+# Changelog
+
+## [Unreleased]
+
+* Add new feature
+
+## [1.0.0] - 2020-01-01
+
+* First release
+```
+
+#### Bump the version
+
+When the release is ready, the `Unreleased` section must be moved to a new version
+section and the version number must be bumped.
+
+If you are using [bump_my_version](https://pypi.org/project/bump-my-version/), you can
+automate the update of the `Unreleased` section.
+
+To do so, you need this configuration in your `pyproject.toml` file:
+
+```toml
+[[tool.bumpversion.files]]
+filename = "CHANGELOG.md"
+replace = """## [Unreleased]
+
+## [{new_version}] - {now:%Y-%m-%d}
+"""
+search = """## [Unreleased]
+"""
+```
+
+Then you can bump the version by running the following command:
+
+```shell
+bump_my_version bump <MAJOR|MINOR|PATCH>
+```
+
+You'll find a full example of the `bump_my_version`
+configuration [here](pyproject.toml).
+
+### Upcoming and Historical releases
+
+For each release, the version release date MUST be included
+(see [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)). This date is used
+to define the release date in the GitLab release. If the date is the same as the
+current date when the job runs, the release exact time is defined by gitlab. Otherwise,
+the release time is set to 00:00:00 UTC and the release will carry a badge as historical
+or upcoming.
+
+* For upcoming releases, the badge will be removed when the release is published.
+* For historical releases, the badge will remain, and release evidences won't be
+  available.
+
+See:
+
+* [Upcoming releases](https://docs.gitlab.com/ee/user/project/releases/#upcoming-releases)
+* [Historical releases](https://docs.gitlab.com/ee/user/project/releases/#historical-releases)
diff --git a/templates/release-by-changelog.yml b/templates/release-by-changelog.yml
index d5edf8c..8d19315 100644
--- a/templates/release-by-changelog.yml
+++ b/templates/release-by-changelog.yml
@@ -1,10 +1,13 @@
 release_by_changelog:
     variables:
-        IMAGE_NAME: 'registry.gitlab.com/gitlab-org/release-cli'
-        IMAGE_TAG: 'latest'
-        IMAGE: '$IMAGE_NAME:$IMAGE_TAG'
         CHANGELOG_FILEPATH: 'CHANGELOG.md'
-    image: $IMAGE
+        PREFIX: ''
+        SUFFIX: ''
+        TAG_PREFIX: $PREFIX
+        TAG_SUFFIX: $SUFFIX
+        NAME_PREFIX: $PREFIX
+        NAME_SUFFIX: $SUFFIX
+    image: registry.gitlab.com/gitlab-org/release-cli
     stage: test
     script:
         # Use grep to find version headers and store them in a variable
@@ -55,7 +58,11 @@ release_by_changelog:
         - 'echo "Text:"'
         - 'echo "$text"'
 
+        # Set the tag and name
+        - 'tag="$TAG_PREFIX$version$TAG_SUFFIX"'
+        - 'name="$NAME_PREFIX$version$NAME_SUFFIX"'
+
         # Create the release
-        - 'release-cli create --name "$version" --tag-name "$version" --description "$text" --released-at "$formatted_date"'
+        - 'release-cli create --name "$name" --tag-name "$tag" --description "$text" --released-at "$formatted_date"'
     rules:
         -   if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
-- 
GitLab