Override semver regex for projects 77/65977/10 v0.58.0
authorAnil Belur <abelur@linuxfoundation.org>
Wed, 4 Nov 2020 23:36:59 +0000 (09:36 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Fri, 6 Nov 2020 21:45:33 +0000 (07:45 +1000)
Allow project to override the semver regex to use versions
as exception that do not conform with semver standards.

Issue: IT-20974
Change-Id: If0a13ecf2394183d6e22e5348dff2a6f0a99c37a
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
docs/jjb/lf-release-jobs.rst
jjb/lf-macros.yaml
releasenotes/notes/release-version-regex-f4e82b48b3a01fee.yaml [new file with mode: 0644]
shell/release-job.sh

index 02e7312..dd8b811 100644 (file)
@@ -50,6 +50,12 @@ For example, the parameters for a Maven release are as follows::
     USE_RELEASE_FILE = false
     DRY_RUN = false
 
+It's recommended to use Semantic Versions (SemVer) for releases. Refer to
+https://semver.org for more details on SemVer. For projects that do not
+follow SemVer can use a build parameter (OVERRIDE_SEMVER_REGEX) with the
+release job. This build param overrides the default SemVer regex.
+
+
 Maven Release Files
 -------------------
 
index 511e51d..f583181 100644 (file)
           name: LOG_DIR
           default: ""
           description: "Log dir, for example: project-maven-stage-master/17/"
+      - string:
+          name: OVERRIDE_SEMVER_REGEX
+          default: ""
+          description: "Override Semantic Version (SemVer) Regular Expression. Ex: '.*'"
       - choice:
           name: DISTRIBUTION_TYPE
           choices:
diff --git a/releasenotes/notes/release-version-regex-f4e82b48b3a01fee.yaml b/releasenotes/notes/release-version-regex-f4e82b48b3a01fee.yaml
new file mode 100644 (file)
index 0000000..6cdc4ee
--- /dev/null
@@ -0,0 +1,12 @@
+---
+fixes:
+  - |
+    Allow projects to override Semantic Version (SemVer).
+
+    It's recommended to use Semantic Versions (SemVer) for releases. Refer to
+    https://semver.org for more details on SemVer. For projects that do not
+    follow SemVer can use a job build parameter (OVERRIDE_SEMVER_REGEX) with the
+    release job. This build param overrides the default SemVer regex.
+
+    The default SemVer regex is taken from
+    https://github.com/fsaintjacques/semver-tool.
index 1c1b570..c7c3f0c 100644 (file)
@@ -81,6 +81,7 @@ set_variables_common(){
     printf "\t%-30s %s\n" PROJECT-DASHED: "${PROJECT//\//-}"
     printf "\t%-30s %s\n" TAG_RELEASE: "$TAG_RELEASE"
     printf "\t%-30s %s\n" DISTRIBUTION_TYPE: "$DISTRIBUTION_TYPE"
+    printf "\t%-30s %s\n" OVERRIDE_SEMVER_REGEX: "${OVERRIDE_SEMVER_REGEX:-None}"
 }
 
 set_variables_maven(){
@@ -216,15 +217,26 @@ verify_schema(){
 }
 
 verify_version(){
-    # Verify allowed patterns "#.#.#" (SemVer) or "v#.#.#"
+
+    # Override the regex for projects that do not follow https://semver.org
+    OVERRIDE_SEMVER_REGEX="${OVERRIDE_SEMVER_REGEX:-None}"
+    if [[ $OVERRIDE_SEMVER_REGEX == "None" ]]; then
+        # Use the semver regex taken from https://github.com/fsaintjacques/semver-tool
+        semver_regex="^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$"
+    else
+        semver_regex="${OVERRIDE_SEMVER_REGEX}"
+    fi
+
+    # Verify SemVer "#.#.#" (SemVer) or "v#.#.#"
     echo "INFO: Verifying version $VERSION"
-    allowed_version_regex="^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$"
-    if [[ $VERSION =~ $allowed_version_regex ]]; then
+    if [[ $VERSION =~ $semver_regex ]]; then
         echo "INFO: The version $VERSION is valid"
     else
         echo "ERROR: The version $VERSION is not valid"
         echo "ERROR: Valid versions are \"#.#.#\" (SemVer) or \"v#.#.#\""
-        echo "ERROR: See https://semver.org/ for more details on SemVer"
+        echo "ERROR: Valid version will be matched against \"${semver_regex}\""
+        echo "ERROR: Refer to https://semver.org/ for more details on SemVer"
+        echo "ERROR: Refer SemVer examples from https://github.com/fsaintjacques/semver-tool/#examples"
         exit 1
     fi
 }