This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 0dfa0c7d22c982bbad59ffb51e483145fe22ac0e
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon Jul 3 10:31:25 2023 +0200

    feat: create release task
    
    Closes #1056
---
 release.adoc              | 16 ++++++++--
 scripts/release-branch.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/release.adoc b/release.adoc
index 38a656bd..b55ddc3d 100644
--- a/release.adoc
+++ b/release.adoc
@@ -58,9 +58,21 @@ As you will be required to publish on Apache servers via 
Maven, you will need to
 
 == Release process
 
-As the process will do `git` operations, it is advisable that you clone the 
Camel K Runtime repository to some new location (ie /tmp/) in order to avoid to 
conflict with any other development in progress. Consider if you're about to 
release from `main` branch (generally a new major or minor version) or from a 
`release` branch (when you're about to release a patch version). In the latter 
case, you need to checkout to the proper release branch, ie `git checkout 
release-1.17.x`.
+As the process will do `git` operations, it is advisable that you clone the 
Camel K Runtime repository to some new location (ie /tmp/) in order to avoid to 
conflict with any other development in progress. If you're starting a major or 
a minor release version, you need to create the correspective `release-a.b.x` 
branch. It's highly advisable not to release directly from `main` branch.
 
-When you're in the project directory, you can start the release process.
+=== Create release branch from main branch
+
+We have a script that simplify this process. As we do not only want to create 
and push a new branch, we also need to provide the CI tasks required for all 
the supported releases.
+
+```
+./script/release-branch.sh
+```
+
+NOTE: you can run the script with `-d` option to dry run and evaluate the 
changes before pushing them to the repo.
+
+=== Start the release process
+
+You need to checkout to the proper release branch, ie `git checkout 
release-1.17.x`. You can start the release process.
 
 To prepare a release and check problems:
 ```
diff --git a/scripts/release-branch.sh b/scripts/release-branch.sh
new file mode 100755
index 00000000..3f5c097d
--- /dev/null
+++ b/scripts/release-branch.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+set -e
+
+display_usage() {
+
+cat <<EOF
+Create a new release branch, synchronizing all CI tasks and resources.
+
+Usage: ./script/release-branch.sh
+
+--help                    This help message
+-d                        Dry run, do not push to GIT repo
+
+Example: ./script/release-branch.sh
+EOF
+
+}
+
+DRYRUN="false"
+SEMVER="^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)(-SNAPSHOT)$"
+
+main() {
+  parse_args $@
+  location=$(dirname $0)
+
+  VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
+  if ! [[ $VERSION =~ $SEMVER ]]; then
+    echo "❗ POM version must match major.minor.patch(-SNAPSHOT) semantic 
version: $1"
+    exit 1
+  fi
+  VERSION_FULL="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
+  VERSION_MM="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
+
+  new_release_branch="release-$VERSION_MM.x"
+  # Create release branch
+  git checkout -b $new_release_branch
+
+  # Support nightly CI tasks
+  # pick the oldest release (we will replace it)
+  oldest_release_branch=$(yq '.jobs[] | key | select ( . !="main" )' 
$location/../.github/workflows/nightly-automatic-updates.yml | sort | head -1)
+  echo "Swapping GH actions tasks from $oldest_release_branch to 
$new_release_branch"
+
+  sed -i "s/$oldest_release_branch/$new_release_branch/g" 
$location/../.github/workflows/nightly-automatic-updates.yml
+
+  if [ $DRY_RUN == "true" ]
+  then
+    echo "❗ dry-run mode on, won't push any change!"
+  else
+    git add --all
+    git commit -m "chore: starting release branch for $new_release_branch" || 
true
+    git push
+    echo "🎉 Changes pushed correctly!"
+  fi
+}
+
+parse_args(){
+  while [ $# -gt 0 ]
+  do
+      arg="$1"
+      case $arg in
+        -h|--help)
+          display_usage
+          exit 0
+          ;;
+        -d)
+          DRYRUN="true"
+          ;;
+        *)
+          echo "❗ unknown argument: $1"
+          display_usage
+          exit 1
+          ;;
+      esac
+      shift
+  done
+}
+
+main $*

Reply via email to