From: Anil Belur Date: Wed, 4 Nov 2020 23:36:59 +0000 (+1000) Subject: Override semver regex for projects X-Git-Tag: v0.58.0^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=3b2df8d227667ad2545a99979daae006c656372d;p=releng%2Fglobal-jjb.git Override semver regex for projects 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 --- diff --git a/docs/jjb/lf-release-jobs.rst b/docs/jjb/lf-release-jobs.rst index 02e73129..dd8b811d 100644 --- a/docs/jjb/lf-release-jobs.rst +++ b/docs/jjb/lf-release-jobs.rst @@ -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 ------------------- diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index 511e51d7..f583181b 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -594,6 +594,10 @@ 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 index 00000000..6cdc4ee4 --- /dev/null +++ b/releasenotes/notes/release-version-regex-f4e82b48b3a01fee.yaml @@ -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. diff --git a/shell/release-job.sh b/shell/release-job.sh index 1c1b5707..c7c3f0ce 100644 --- a/shell/release-job.sh +++ b/shell/release-job.sh @@ -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 }