This is an automated email from the ASF dual-hosted git repository. chesnay pushed a commit to branch release_utils in repository https://gitbox.apache.org/repos/asf/flink-connector-shared-utils.git
The following commit(s) were added to refs/heads/release_utils by this push: new 606d8b8 [FLINK-29472] Add first version of release scripts 606d8b8 is described below commit 606d8b8c56c3aa77e2262b25107c5f911d0ce2ac Author: Chesnay Schepler <ches...@apache.org> AuthorDate: Thu Nov 10 13:22:54 2022 +0100 [FLINK-29472] Add first version of release scripts --- README.md | 92 +++++++++++++++++++++++++++++++++++++- _init.sh | 48 ++++++++++++++++++++ _utils.sh | 68 +++++++++++++++++++++++++++++ check_environment.sh | 67 ++++++++++++++++++++++++++++ release_git_tag.sh | 50 +++++++++++++++++++++ release_snapshot_branch.sh | 36 +++++++++++++++ release_source_release.sh | 35 +++++++++++++++ stage_jars.sh | 57 ++++++++++++++++++++++++ stage_source_release.sh | 85 ++++++++++++++++++++++++++++++++++++ update_branch_version.sh | 41 +++++++++++++++++ update_japicmp_configuration.sh | 97 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 675 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b65ae7..e4571d7 100644 --- a/README.md +++ b/README.md @@ -1 +1,91 @@ -This repository contains utilities for [Apache Flink](https://flink.apache.org/) connectors. \ No newline at end of file +This is a collection of release utils for [Apache Flink](https://flink.apache.org/) connectors. + +# Integration + +The scripts assume that they are integrated into a connector repo as a submodule into the connector repo +under `tools/releasing/shared`. + +# Usage + +Some scripts rely on environment variables to be set. +These are checked at the start of each script. +Any instance of `${some_variable}` in this document refers to an environment variable that is used by the respective +script. + +## check_environment.sh + +Runs some pre-release checks for the current environment, for example that all required programs are available. +This should be run once at the start of the release process. + +## publish_snapshot_branch.sh + +Creates (and pushes!) a new snapshot branch for the current commit. +The branch name is automatically determined from the version in the pom. +This script should be called when work on a new major/minor version of the connector has started. + +## update_branch_version.sh + +Updates the version in the poms of the current branch to `${NEW_VERSION}`. + +## stage_source_release.sh + +Creates a source release from the current branch and pushes it via `svn` +to [dist.apache.org](https://dist.apache.org/repos/dist/dev/flink). +The version is automatically determined from the version in the pom. +The created `svn` directory will contain a `-rc${RC_NUM}` suffix. + +## stage_jars.sh + +Creates the jars from the current branch and deploys them to [repository.apache.org](https://repository.apache.org). +The version will be suffixed with `-${FLINK_MINOR_VERSION}` to indicate the supported Flink version. +If a particular version of a connector supports multiple Flink versions then this script should be called multiple +times. + +## release_source_release.sh + +Copies the source release from the [SVN release directory](https://dist.apache.org/repops/dist/dev/flink) to the +[SVN release directory](https://dist.apache.org/repops/dist/release/flink) on [dist.apache.org](https://dist.apache.org). + +For safety purposes this script does not automatically determine the project and version from the current directory/branch/tag. + +``` +PROJECT=flink-connector-elasticsearch VERSION=3.0.0 RC_NUM=2 ./release_source_release.sh +``` + +## publish_git_tag.sh + +Creates a release tag for the current branch and pushes it to GitHub. +The tag will be suffixed with `-rc${RC_NUM}`, if `${RC_NUM}` was set. +This script should only be used _after_ the `-SNAPSHOT` version suffix was removd via `update_branch_version.sh`. + +## update_japicmp_configuration.sh + +Sets the japicmp reference version in the pom of the current branch to `${NEW_VERSION}`, enables compatibility checks +for `@PublicEvolving` when used on snapshot branches an clears the list of exclusions. +This should be called after a release on the associated snapshot branch. If it was a minor release it should +additionally be called on the `main` branch. + +# Common workflow + +1. run `release_snapshot_branch.sh` +2. do some development work on the created snapshot branch +3. checkout a specific commit to create a release from +4. run `check_environment.sh` +5. run `update_branch_version.sh` +6. run `stage_source_release.sh` +7. run `stage_jars.sh` (once for each supported Flink version) +8. run `release_git_tag.sh` (with `RC_NUM`) +9. vote on release +10. finalize release or cancel and go back to step 2 +11. run `release_source_release.sh` +12. run `release_git_tag.sh` (without `RC_NUM`) +13. run `update_japicmp_configuration.sh` (on snapshot branch, and maybe `main`) + +# Script naming conventions + +| Prefix | Meaning | +|---------|------------------------------------------------------------------------| +| check | Verifies conditions without making any changes. | +| update | Applies modifications locally to the current branch. | +| stage | Publishes an artifact to an intermediate location for voting purposes. | +| release | Publishes an artifact to a user-facing location. | \ No newline at end of file diff --git a/_init.sh b/_init.sh new file mode 100644 index 0000000..35b3111 --- /dev/null +++ b/_init.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# all scripts should contain this line + source ${SCRIPT_DIR}/_init.sh +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +set -o errexit +set -o nounset +set -o pipefail + +export SHELLOPTS + +########################### + +MVN=${MVN:-mvn} + +if [ "$(uname)" == "Darwin" ]; then + SHASUM="shasum -a 512" +else + SHASUM="sha512sum" +fi + +REMOTE=${REMOTE:-upstream} + +########################## + +SOURCE_DIR=$( cd -- "$( dirname -- "${SCRIPT_DIR}/../../../.." )" &> /dev/null && pwd ) +RELEASE_DIR=${SOURCE_DIR}/tools/releasing/release +ARTIFACTS_DIR=${SOURCE_DIR}/tools/releasing/release/artifacts + +SVN_DEV_DIR="https://dist.apache.org/repos/dist/dev/flink" +SVN_RELEASE_DIR="https://dist.apache.org/repos/dist/release/flink" \ No newline at end of file diff --git a/_utils.sh b/_utils.sh new file mode 100644 index 0000000..b63379a --- /dev/null +++ b/_utils.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +function check_variables_set { + any_missing=false + + for variable in "$@" + do + if [ -z "${!variable:-}" ]; then + echo "${variable} was not set." + any_missing=true + fi + done + + if [ ${any_missing} == true ]; then + exit 1 + fi +} + +function create_pristine_source { + source_dir=$1 + release_dir=$2 + + clone_dir="${release_dir}/tmp-clone" + clean_dir="${release_dir}/tmp-clean-clone" + rm -rf ${clone_dir} + rm -rf ${clean_dir} + # create a temporary git clone to ensure that we have a pristine source release + git clone "${source_dir}" "${clone_dir}" + + rsync -a \ + --exclude ".git" --exclude ".gitignore" --exclude ".gitattributes" --exclude ".gitmodules" --exclude ".github" \ + --exclude ".idea" --exclude "*.iml" \ + --exclude ".DS_Store" \ + --exclude ".asf.yaml" \ + --exclude "target" --exclude "tools/releasing/shared" \ + "${clone_dir}/" "${clean_dir}" + + rm -rf "${clone_dir}" + + echo "${clean_dir}" +} + +function get_pom_version { + echo $(${MVN} help:evaluate -Dexpression="project.version" -q -DforceStdout) +} + +function set_pom_version { + new_version=$1 + + ${MVN} org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion=${new_version} -DgenerateBackupPoms=false --quiet +} \ No newline at end of file diff --git a/check_environment.sh b/check_environment.sh new file mode 100755 index 0000000..b2ad38c --- /dev/null +++ b/check_environment.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" + +EXIT_CODE=0 + +function check_program_available { + if program=$(command -v ${1}); then + printf "\t%-10s%s\n" "${1}" "using ${program}" + else + printf "\t%-10s%s\n" "${1}" "is not available." + EXIT_CODE=1 + fi +} + +echo "Checking program availability:" +check_program_available git +check_program_available tar +check_program_available rsync +check_program_available gpg +check_program_available perl +check_program_available sed +check_program_available svn +check_program_available ${MVN} +check_program_available ${SHASUM} + +function check_git_connectivity { + cd "${SOURCE_DIR}" + if git ls-remote --exit-code ${REMOTE} &> /dev/null; then + printf "\tUsing git remote '${REMOTE}'.\n" + else + printf "\tGit remote '${REMOTE}' is not available.\n" + printf "\tRun 'git remote add upstream https://github.com/apache/<repo>' or set a custom remote with the 'REMOTE' env variable.\n" + exit 1 + fi +} + +echo "Checking git remote availability:" +if ! (check_git_connectivity); then + EXIT_CODE=1 +fi + +if [ ${EXIT_CODE} == 0 ]; then + echo "All set! :)" +else + echo "At least one problem was found!" +fi +exit ${EXIT_CODE} diff --git a/release_git_tag.sh b/release_git_tag.sh new file mode 100755 index 0000000..6418282 --- /dev/null +++ b/release_git_tag.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source ${SCRIPT_DIR}/_init.sh +source ${SCRIPT_DIR}/_utils.sh + +########################### + +RC_NUM=${RC_NUM:-none} + +########################### + +function create_release_tag { + cd "${SOURCE_DIR}" + + version=$(get_pom_version) + if [[ ${version} =~ -SNAPSHOT$ ]]; then + echo "Tags should not be created for SNAPSHOT versions. Use 'update_branch_version.sh' first." + exit 1 + fi + + tag=v${version} + if [ "$RC_NUM" != "none" ]; then + tag=${tag}-rc${RC_NUM} + fi + + git tag -s -m "v${tag}" ${tag} + + git push ${REMOTE} ${tag} +} + +(create_release_tag) diff --git a/release_snapshot_branch.sh b/release_snapshot_branch.sh new file mode 100755 index 0000000..5a4d274 --- /dev/null +++ b/release_snapshot_branch.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" + +########################### + +function create_snapshot_branch { + cd "${SOURCE_DIR}" + + version=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout | sed "s/-SNAPSHOT//") + branch="v${version}" + + git checkout -b ${branch} + git push ${REMOTE} ${branch}:${branch} +} + +(create_snapshot_branch) diff --git a/release_source_release.sh b/release_source_release.sh new file mode 100755 index 0000000..4ee2342 --- /dev/null +++ b/release_source_release.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" +source "${SCRIPT_DIR}/_utils.sh" + +########################### + +check_variables_set PROJECT VERSION RC_NUM + +########################### + +function release_source_release { + svn move -m "Release ${PROJECT} ${VERSION}" ${SVN_DEV_DIR}/${PROJECT}-${VERSION}-rc${RC_NUM} ${SVN_RELEASE_DIR}/${PROJECT}-${VERSION} +} + +(release_source_release) diff --git a/stage_jars.sh b/stage_jars.sh new file mode 100755 index 0000000..0dd180c --- /dev/null +++ b/stage_jars.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" +source "${SCRIPT_DIR}/_utils.sh" + +########################### + +check_variables_set FLINK_VERSION + +########################### + +function deploy_staging_jars { + cd "${SOURCE_DIR}" + mkdir -p "${RELEASE_DIR}" + + project_version=$(get_pom_version) + if [[ ${project_version} =~ -SNAPSHOT$ ]]; then + echo "Jars should not be created for SNAPSHOT versions. Use 'update_branch_version.sh' first." + exit 1 + fi + flink_minor_version=$(echo ${FLINK_VERSION} | sed "s/.[0-9]\+$//") + version=${project_version}-${flink_minor_version} + + echo "Deploying jars v${version} to repository.apache.org" + echo "To revert this step, login to 'https://repository.apache.org' -> 'Staging repositories' -> Select repository -> 'Drop'" + + clone_dir=$(create_pristine_source "${SOURCE_DIR}" "${RELEASE_DIR}") + cd "${clone_dir}" + set_pom_version "${version}" + + options="-Prelease,docs-and-source -DskipTests -DretryFailedDeploymentCount=10" + ${MVN} clean deploy ${options} -Dflink.version=${FLINK_VERSION} + + cd "${RELEASE_DIR}" + rm -rf "${clone_dir}" +} + +(deploy_staging_jars) diff --git a/stage_source_release.sh b/stage_source_release.sh new file mode 100755 index 0000000..b8e659f --- /dev/null +++ b/stage_source_release.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" +source "${SCRIPT_DIR}/_utils.sh" + +########################### + +check_variables_set RC_NUM + +########################### + +function create_source_release { + cd ${SOURCE_DIR} + mkdir -p ${RELEASE_DIR} + mkdir -p ${ARTIFACTS_DIR} + + project=${PWD##*/} + version=$(get_pom_version) + if [[ ${version} =~ -SNAPSHOT$ ]]; then + echo "Source releases should not be created for SNAPSHOT versions. Use 'update_branch_version.sh' first." + exit 1 + fi + + echo "Creating source release v${version}" + echo "To revert this step, run 'rm ${ARTIFACTS_DIR}'" + + clone_dir=$(create_pristine_source "${SOURCE_DIR}" "${RELEASE_DIR}") + versioned_dir="${ARTIFACTS_DIR}/${project}-${version}" + mv ${clone_dir} ${versioned_dir} + + cd "${ARTIFACTS_DIR}" + tar czf ${ARTIFACTS_DIR}/${project}-${version}-src.tgz ${versioned_dir##*/} + gpg --armor --detach-sig ${ARTIFACTS_DIR}/${project}-${version}-src.tgz + ${SHASUM} ${project}-${version}-src.tgz >${project}-${version}-src.tgz.sha512 + + rm -rf ${versioned_dir} +} + +function deploy_source_release { + cd ${SOURCE_DIR} + project=${PWD##*/} + version=$(get_pom_version)-rc${RC_NUM} + + release=${project}-${version} + + echo "Deploying source release v${version}" + echo "To revert this step, run 'svn delete ${SVN_DEV_DIR}/${release}'" + + svn_dir=${RELEASE_DIR}/svn + rm -rf ${svn_dir} + mkdir -p ${svn_dir} + cd ${svn_dir} + + svn checkout ${SVN_DEV_DIR} --depth=immediates + cd flink + mkdir ${release} + mv ${ARTIFACTS_DIR}/* ${release} + svn add ${release} + svn commit -m "Add ${release}" + + cd ${RELEASE_DIR} + rm -rf ${svn_dir} +} + +(create_source_release) +(deploy_source_release) diff --git a/update_branch_version.sh b/update_branch_version.sh new file mode 100755 index 0000000..dc793da --- /dev/null +++ b/update_branch_version.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + +source "${SCRIPT_DIR}/_init.sh" +source "${SCRIPT_DIR}/_utils.sh" + +########################## + +check_variables_set NEW_VERSION + +########################### + +function update_branch_version { + cd "${SOURCE_DIR}" + + set_pom_version "${NEW_VERSION}" + + git commit -am "Update version to $NEW_VERSION" + + echo "Done. Don't forget to push the change." +} + +(update_branch_version) diff --git a/update_japicmp_configuration.sh b/update_japicmp_configuration.sh new file mode 100755 index 0000000..ce3784f --- /dev/null +++ b/update_japicmp_configuration.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +source ${SCRIPT_DIR}/_init.sh +source ${SCRIPT_DIR}/_utils.sh + +########################### + +check_variables_set NEW_VERSION + +########################### + +# Idealized use-cases: +# Scenario A) New major release X.0.0 +# Premise: +# There is a main branch a version X.0-SNAPSHOT, with a japimp reference version of (X-1).Y.Z +# Release flow: +# - update the main to (X+1).0-SNAPSHOT, but keep the reference version intact since X.0.0 is not released (yet) +# - create X.0-SNAPSHOT branch, but keep the reference version intact since X.0.0 is not released (yet) +# - release X.0.0 +# - update the japicmp reference version of both main and X.0-SNAPSHOT to X.0.0 +# - enable stronger compatibility constraints for X.0-SNAPSHOT to ensure compatibility for PublicEvolving +# Scenario A) New minor release X.Y.0 +# Premise: +# There is a main branch with a version X.Y-SNAPSHOT, with a japicmp reference version of X.(Y-1).0 . +# Release flow: +# - update the main branch to X.(Y+1)-SNAPSHOT, but keep the reference version intact since X.Y.0 is not released (yet) +# - create X.Y-SNAPSHOT branch, but keep the reference version intact since X.Y.0 is not released (yet) +# - release X.Y.0 +# - update the japicmp reference version of both main and X.Y-SNAPSHOT to X.Y.0 +# - enable stronger compatibility constraints for X.Y-SNAPSHOT to ensure compatibility for PublicEvolving +# Scenario C) New patch release X.Y.Z +# Premise: +# There is a snapshot branch with a version X.Y-SNAPSHOT, with a japicmp reference version of X.Y.(Z-1) +# Release flow: +# - release X.Y.Z +# - update the japicmp reference version of X.Y-SNAPSHOT to X.Y.Z + +function enable_public_evolving_compatibility_checks() { + perl -pi -e 's#<!--(<include>\@org.apache.flink.annotation.PublicEvolving</include>)-->#${1}#' pom.xml + perl -pi -e 's#\t+<exclude>\@org.apache.flink.annotation.PublicEvolving.*\n##' pom.xml +} + +function set_japicmp_reference_version() { + local version=$1 + + perl -pi -e 's#(<japicmp.referenceVersion>).*(</japicmp.referenceVersion>)#${1}'${version}'${2}#' pom.xml +} + +function clear_exclusions() { + exclusion_start=$(($(sed -n '/<!-- MARKER: start exclusions/=' pom.xml) + 1)) + exclusion_end=$(($(sed -n '/<!-- MARKER: end exclusions/=' pom.xml) - 1)) + + if [[ $exclusion_start -lt $exclusion_end ]]; then + sed -i "${exclusion_start},${exclusion_end}d" pom.xml + fi +} + +function update_japicmp_configuration() { + cd "${SOURCE_DIR}" + + current_branch=$(git branch --show-current) + + if [[ ${current_branch} =~ ^main$ ]]; then + # main branch + set_japicmp_reference_version ${NEW_VERSION} + clear_exclusions + elif [[ ${current_branch} =~ ^v ]]; then + # snapshot branch + set_japicmp_reference_version ${NEW_VERSION} + enable_public_evolving_compatibility_checks + clear_exclusions + else + echo "Script was called from unexpected branch ${current_branch}; should be snapshot/main branch." + exit 1 + fi +} + +(update_japicmp_configuration) \ No newline at end of file