diff --git a/README.md b/README.md index baa1b77331f6ccfe8afedae00b2bb1aa78e022c9..476b15965f3543f77131e71140a4c14a934da40c 100644 --- a/README.md +++ b/README.md @@ -161,12 +161,40 @@ They are bound to the `publish` stage, and use the following variables: | `MAVEN_DEPLOY_ARGS` | Maven arguments for the Snapshot job | `deploy -DskipTests` | | `MAVEN_RELEASE_ARGS` | Maven arguments for the Release job | `release:prepare release:perform -DskipTests` | | `MAVEN_RELEASE_SCM_COMMENT_PREFIX` | Maven release plugin [scmCommentPrefix](https://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#scmCommentPrefix) parameter | `[ci skip][maven-release-plugin]` | +| `MVN_SEMREL_RELEASE_DISABLED` | Disable [semantic-release integration](#semantic-release-integration) | `[ci skip][maven-release-plugin]` | More info: * [Maven Deploy Plugin](https://maven.apache.org/plugins/maven-deploy-plugin/) * [Maven Release Plugin](http://maven.apache.org/maven-release/maven-release-plugin/index.html) +#### `semantic-release` integration + +If you activate the [`semantic-release-info` job from the `semantic-release` template](https://gitlab.com/Orange-OpenSource/tbc/semantic-release/#semantic-release-info-job), the `mvn-release` job will rely on the generated next version info. + +* the release will only be performed if a next semantic release is present +* the version is passed to the maven release plugin as release version argument adding `-DreleaseVersion=${SEMREL_INFO_NEXT_VERSION}` to the `MAVEN_RELEASE_ARGS` value + +:warning: Both maven release plugin and semantic-release use a dedicated tag format that need to be set accordingly. +By default maven release plugin uses `${artifactId}-${version}` and semantic-release uses `s${version}` +For exemple you can modify the semantic-release tag format with the `SEMREL_TAG_FORMAT` variable (see [semantic-release template variables](https://gitlab.com/Orange-OpenSource/tbc/semantic-release/#variables)). + +```yml +variables: + SEMREL_TAG_FORMAT: "myArtifactId-$${version}" +``` + +Or you can [override the maven release plugin tag format](http://maven.apache.org/maven-release/maven-release-plugin/examples/prepare-release.html#Overriding_the_default_tag_name_format). + +Note: You can disable the `semantic-release` job (as it's the `mvn-release` job that will perform the release and so we only need the `semantic-release-info` job) with the `SEMREL_RELEASE_DISABLED` variable. + +```yml +variables: + SEMREL_RELEASE_DISABLED: "true" +``` + +Finally, the semantic-release integration can be disable with the `MVN_SEMREL_RELEASE_DISABLED` variable. + #### Maven repository authentication Your Maven repository may require authentication credentials to publish artifacts. diff --git a/kicker.json b/kicker.json index 9ee8640f7aaa538a2a63e9416a4ebecf2dfb8d6a..248794a551e5a687c033032e8e14bec487d728ad 100644 --- a/kicker.json +++ b/kicker.json @@ -133,6 +133,11 @@ "default": "[ci skip][maven-release-plugin]", "advanced": true }, + { + "name": "MVN_SEMREL_RELEASE_DISABLED", + "description": "Disable semantic-release integration", + "advanced": true + }, { "name": "GIT_USERNAME", "description": "Git username (if you wish to release using Git credentials)", diff --git a/templates/gitlab-ci-maven.yml b/templates/gitlab-ci-maven.yml index 558700df4f600bb7a63b2e9d3b2a9fe9a90cac36..d27cc5b5c82ce648da84f57b74dcbab709123eb1 100644 --- a/templates/gitlab-ci-maven.yml +++ b/templates/gitlab-ci-maven.yml @@ -429,6 +429,12 @@ mvn-release: stage: publish before_script: - *mvn-scripts + - | + if [ "${SEMREL_INFO_ON}" ] && [ -z "${SEMREL_INFO_NEXT_VERSION}" ] + then + log_info "no new version to release" + exit 0 + fi - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - eval_java_proxy_args - log_info "Preparing Git repository for release..." @@ -438,7 +444,15 @@ mvn-release: script: - configure_scm_auth - maybe_set_version_from_git - - mvn ${TRACE+-X} $MAVEN_CLI_OPTS $java_proxy_args $scm_auth_args $MAVEN_RELEASE_ARGS -DscmCommentPrefix="$MAVEN_RELEASE_SCM_COMMENT_PREFIX" + - | + if [ "${SEMREL_INFO_ON}" ] && [ -z "${SEMREL_INFO_NEXT_VERSION}" ] + then + log_info "semantic-release info is activated, using computed next version for release \\e[1;94m${SEMREL_INFO_NEXT_VERSION}\\e[0m" + RELEASE_ARGS="${MAVEN_RELEASE_ARGS} -DreleaseVersion=${SEMREL_INFO_NEXT_VERSION}" + else + RELEASE_ARGS="${MAVEN_RELEASE_ARGS}" + fi + - mvn ${TRACE+-X} $MAVEN_CLI_OPTS $java_proxy_args $scm_auth_args $RELEASE_ARGS -DscmCommentPrefix="$MAVEN_RELEASE_SCM_COMMENT_PREFIX" rules: # exclude merge requests - if: $CI_MERGE_REQUEST_ID