You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/07/14 08:28:14 UTC

[camel-k] branch main updated: feat(ci): release branch automation

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.git


The following commit(s) were added to refs/heads/main by this push:
     new e57842730 feat(ci): release branch automation
e57842730 is described below

commit e5784273076c7a5729306e5f24f9fa3a2514011a
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Jul 14 10:24:55 2023 +0200

    feat(ci): release branch automation
---
 .github/workflows/manual-release-branch.yml | 43 ++++++++++++++++
 release.adoc                                |  8 ++-
 script/Makefile                             |  1 -
 script/bump_actions.sh                      | 45 ----------------
 script/release-branch.sh                    | 80 +++++++++++++++++++++++++++++
 5 files changed, 130 insertions(+), 47 deletions(-)

diff --git a/.github/workflows/manual-release-branch.yml b/.github/workflows/manual-release-branch.yml
new file mode 100644
index 000000000..296db1275
--- /dev/null
+++ b/.github/workflows/manual-release-branch.yml
@@ -0,0 +1,43 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+name: release-branch
+
+on:
+  workflow_dispatch:
+    inputs:
+
+jobs:
+  release-branch:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout code
+      uses: actions/checkout@v3
+      with:
+        persist-credentials: false
+        submodules: recursive
+    - name: Create branch
+      shell: bash
+      env:
+        CI_USER: "github-actions[bot]"
+        CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
+        CI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      run: |
+        ./script/release-branch.sh
+
+
+
diff --git a/release.adoc b/release.adoc
index 119504a6f..da04d9221 100644
--- a/release.adoc
+++ b/release.adoc
@@ -18,7 +18,13 @@ This project staging is hosted on https://hub.docker.com/orgs/camelk/repositorie
 [[releasing-camel-k]]
 == Release Camel K
 
-As the process will do `git` operations, it is advisable that you clone the Camel K 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.12.x`.
+As the process will do git operations, it is advisable that you clone the Camel K 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 respective `release-a.b.x` branch. It’s highly advisable not to release directly from `main` branch.
+
+=== Create release branch from main branch
+
+Use the `release-branch` action in order to create a new branch from the `main` at a given moment. The action is in charge to scrape the actual version (it will remove any snapshot suffix) and to create the release branch accordingly. It also takes care to setup the required nightly actions in the new branch created.
+
+Once the action is over, you can checkout the newly created release branch and continue with the release process.
 
 [[releasing-camel-k-crds]]
 === Release Camel K CRD dependency
diff --git a/script/Makefile b/script/Makefile
index 5afb2eeda..b2ec8e0d6 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -159,7 +159,6 @@ bump-replace:
 	@sed -i 's/^KAMELET_CATALOG_REPO_TAG :=.*$//KAMELET_CATALOG_REPO_TAG := main/' ./script/Makefile
 
 bump: bump-replace codegen bundle
-	./script/bump_actions.sh $(LAST_RELEASED_VERSION)
 
 # Generates the version file
 codegen:
diff --git a/script/bump_actions.sh b/script/bump_actions.sh
deleted file mode 100755
index 77cf87d23..000000000
--- a/script/bump_actions.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/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.
-
-if [ "$#" -lt 1 ]; then
-  echo "usage: $0 <Camel K version>"
-  exit 1
-fi
-
-location=$(dirname $0)
-version="$1"
-
-re="^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$"
-if ! [[ $version =~ $re ]]; then
-    echo "❗ argument must match semantic version: $version"
-    exit 1
-fi
-version_mm="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
-
-new_release="v$(echo "$version_mm" | tr \. _)_x"
-new_release_branch="release-$version_mm.x"
-
-# pick the oldest release (we will replace it)
-oldest_release=$(yq '.jobs[] | key | select ( . !="main" )' $location/../.github/workflows/release.yml | sort | head -1)
-oldest_release_branch=$(yq ".jobs[\"$oldest_release\"].steps[0].with.branch-ref" $location/../.github/workflows/release.yml)
-echo "Swapping GH actions tasks from $oldest_release to $new_release, $oldest_release_branch to $new_release_branch"
-# Nightly release action
-sed -i "s/$oldest_release/$new_release/g" $location/../.github/workflows/release.yml
-sed -i "s/$oldest_release_branch/$new_release_branch/g" $location/../.github/workflows/release.yml
-# Automatic updates action
-sed -i "s/$oldest_release/$new_release/g" $location/../.github/workflows/automatic-updates.yml
-sed -i "s/$oldest_release_branch/$new_release_branch/g" $location/../.github/workflows/automatic-updates.yml
\ No newline at end of file
diff --git a/script/release-branch.sh b/script/release-branch.sh
new file mode 100755
index 000000000..510395bb3
--- /dev/null
+++ b/script/release-branch.sh
@@ -0,0 +1,80 @@
+#!/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=$(make get-version)
+  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"
+
+  # Support nightly CI tasks
+  # pick the oldest release assuming they all use the same strategy convention
+  oldest_release_branch=$(yq '.jobs.auto-updates.strategy.matrix.ref-branch[] | 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
+  sed -i "s/$oldest_release_branch/$new_release_branch/g" $location/../.github/workflows/nightly-native-test.yml
+  sed -i "s/$oldest_release_branch/$new_release_branch/g" $location/../.github/workflows/nightly-release.yml
+
+  if [ $DRYRUN == "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 "https://$CI_USER:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:main
+    git push "https://$CI_USER:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:$new_release_branch
+    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 $*