diff --git a/scripts/lib.sh b/scripts/lib.sh new file mode 100644 index 000000000..38f5e2be7 --- /dev/null +++ b/scripts/lib.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Common functions for Kubeflow manifest synchronization scripts + +setup_error_handling() { + set -euxo pipefail + IFS=$'\n\t' +} + +# Check if the git repository has uncommitted changes +check_uncommitted_changes() { + if [ -n "$(git status --porcelain)" ]; then + echo "WARNING: You have uncommitted changes" + fi +} + +# Create a new git branch if it doesn't exist +create_branch() { + local branch="$1" + + check_uncommitted_changes + + if [ $(git branch --list "$branch") ]; then + echo "WARNING: Branch $branch already exists." + fi + + if ! git show-ref --verify --quiet refs/heads/$branch; then + git checkout -b "$branch" + else + echo "Branch $branch already exists." + fi +} + +clone_and_checkout() { + local source_directory="$1" + local repository_url="$2" + local repository_directory="$3" + local commit="$4" + + echo "Checking out in $source_directory to $commit..." + + mkdir -p "$source_directory" + cd "$source_directory" + + # Clone repository if it doesn't exist + if [ ! -d "$repository_directory/.git" ]; then + git clone "$repository_url" "$repository_directory" + fi + + # Checkout to specific commit + cd "$source_directory/$repository_directory" + if ! git rev-parse --verify --quiet "$commit"; then + git checkout -b "$commit" + else + git checkout "$commit" + fi + + check_uncommitted_changes +} + +# Copy manifests from source to destination +copy_manifests() { + local source="$1" + local destination="$2" + + echo "Copying manifests..." + + if [ -d "$destination" ]; then + rm -r "$destination" + fi + + cp "$source" "$destination" -r + echo "Successfully copied all manifests." +} + +# Update README with new commit reference +update_readme() { + local manifests_directory="$1" + local source_text="$2" + local destination_text="$3" + + sed -i "s|$source_text|$destination_text|g" "${manifests_directory}/README.md" +} + +# Commit changes to git repository +commit_changes() { + local manifests_directory="$1" + local commit_message="$2" + local paths_to_add=("${@:3}") + + cd "$manifests_directory" + + for path in "${paths_to_add[@]}"; do + git add "$path" + done + + git commit -s -m "$commit_message" +} \ No newline at end of file diff --git a/scripts/synchronize-istio-cni-manifests.sh b/scripts/synchronize-istio-cni-manifests.sh index 20c06f176..d51c3dcb7 100644 --- a/scripts/synchronize-istio-cni-manifests.sh +++ b/scripts/synchronize-istio-cni-manifests.sh @@ -1,54 +1,38 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Istio CNI manifests +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="istio-cni" COMMIT="1.24.3" CURRENT_VERSION="1-24" NEW_VERSION="1-24" # Must be a release +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=${COMPONENT_NAME}-${COMMIT?}} -SRC_DIR=${SRC_DIR:=/tmp/istio-cni} -BRANCH=${BRANCH:=istio-cni-${COMMIT?}} - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) - -ISTIO_OLD=$MANIFESTS_DIR/common/istio-cni-${CURRENT_VERSION} -ISTIO_NEW=$MANIFESTS_DIR/common/istio-cni-${NEW_VERSION} +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +ISTIO_OLD=$MANIFESTS_DIRECTORY/common/${COMPONENT_NAME}-${CURRENT_VERSION} +ISTIO_NEW=$MANIFESTS_DIRECTORY/common/${COMPONENT_NAME}-${NEW_VERSION} if [ ! -d "$ISTIO_NEW" ]; then -cp -a $ISTIO_OLD $ISTIO_NEW -fi - -echo "Creating branch: ${BRANCH}" - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." + cp -a $ISTIO_OLD $ISTIO_NEW fi -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +create_branch "$BRANCH_NAME" -# Checkout the istio repository -if [ ! -d "$SRC_DIR" ]; then -mkdir -p $SRC_DIR -fi -cd $SRC_DIR +echo "Checking out in $SOURCE_DIRECTORY to $COMMIT..." +mkdir -p $SOURCE_DIRECTORY +cd $SOURCE_DIRECTORY if [ ! -d "istio-${COMMIT}" ]; then wget "https://github.com/istio/istio/releases/download/${COMMIT}/istio-${COMMIT}-linux-amd64.tar.gz" tar xvfz istio-${COMMIT}-linux-amd64.tar.gz fi -ISTIOCTL=$SRC_DIR/istio-${COMMIT}/bin/istioctl +ISTIOCTL=$SOURCE_DIRECTORY/istio-${COMMIT}/bin/istioctl cd $ISTIO_NEW $ISTIOCTL manifest generate -f profile.yaml -f profile-overlay.yaml --set components.cni.enabled=true --set components.cni.namespace=kube-system > dump.yaml @@ -58,22 +42,20 @@ mv $ISTIO_NEW/install.yaml $ISTIO_NEW/istio-install/base mv $ISTIO_NEW/cluster-local-gateway.yaml $ISTIO_NEW/cluster-local-gateway/base rm dump.yaml -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" +check_uncommitted_changes + +SOURCE_TEXT="\[.*\](https://github.com/istio/istio/releases/tag/.*)" +DESTINATION_TEXT="\[$COMMIT\](https://github.com/istio/istio/releases/tag/$COMMIT)" + +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" + +echo "Synchronizing directory names..." +find "$MANIFESTS_DIRECTORY" -type f -not -path '*/.git/*' -exec sed -i "s/istio-cni-${CURRENT_VERSION}/istio-cni-${NEW_VERSION}/g" {} + + +cd "$MANIFESTS_DIRECTORY" +if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then + rm -rf $ISTIO_OLD fi +commit_changes "$MANIFESTS_DIRECTORY" "Upgrade istio-cni to v.${COMMIT}" "." -# Update README.md to synchronize with the upgraded Istio version -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/istio/istio/releases/tag/.*)" -DST_TXT="\[$COMMIT\](https://github.com/istio/istio/releases/tag/$COMMIT)" - -sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md - -#Synchronize the updated directory names with other files -find "$MANIFESTS_DIR" -type f -not -path '*/.git/*' -exec sed -i "s/istio-cni-${CURRENT_VERSION}/istio-cni-${NEW_VERSION}/g" {} + - -echo "Committing the changes..." -cd "$MANIFESTS_DIR" -rm -rf $ISTIO_OLD -git add . -git commit -s -m "Upgrade istio-cni to v.${COMMIT}" \ No newline at end of file +echo "Synchronization completed successfully." \ No newline at end of file diff --git a/scripts/synchronize-istio-manifests.sh b/scripts/synchronize-istio-manifests.sh index 30b02e7e6..68484daa4 100644 --- a/scripts/synchronize-istio-manifests.sh +++ b/scripts/synchronize-istio-manifests.sh @@ -1,54 +1,39 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Istio manifests +# Source the common library functions +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="istio" COMMIT="1.24.3" CURRENT_VERSION="1-24" NEW_VERSION="1-24" # Must be a release +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=${COMPONENT_NAME}-${COMMIT?}} -SRC_DIR=${SRC_DIR:=/tmp/istio} # Must be a release -BRANCH=${BRANCH:=istio-${COMMIT?}} - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) - -ISTIO_OLD=$MANIFESTS_DIR/common/istio-${CURRENT_VERSION} -ISTIO_NEW=$MANIFESTS_DIR/common/istio-${NEW_VERSION} +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +ISTIO_OLD=$MANIFESTS_DIRECTORY/common/${COMPONENT_NAME}-${CURRENT_VERSION} +ISTIO_NEW=$MANIFESTS_DIRECTORY/common/${COMPONENT_NAME}-${NEW_VERSION} if [ ! -d "$ISTIO_NEW" ]; then -cp -a $ISTIO_OLD $ISTIO_NEW -fi - -echo "Creating branch: ${BRANCH}" - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." + cp -a $ISTIO_OLD $ISTIO_NEW fi -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +create_branch "$BRANCH_NAME" -# Checkout the istio repository -if [ ! -d "$SRC_DIR" ]; then -mkdir -p $SRC_DIR -fi -cd $SRC_DIR +echo "Checking out in $SOURCE_DIRECTORY to $COMMIT..." +mkdir -p $SOURCE_DIRECTORY +cd $SOURCE_DIRECTORY if [ ! -d "istio-${COMMIT}" ]; then wget "https://github.com/istio/istio/releases/download/${COMMIT}/istio-${COMMIT}-linux-amd64.tar.gz" tar xvfz istio-${COMMIT}-linux-amd64.tar.gz fi -ISTIOCTL=$SRC_DIR/istio-${COMMIT}/bin/istioctl +ISTIOCTL=$SOURCE_DIRECTORY/istio-${COMMIT}/bin/istioctl cd $ISTIO_NEW $ISTIOCTL manifest generate -f profile.yaml -f profile-overlay.yaml > dump.yaml @@ -58,22 +43,19 @@ mv $ISTIO_NEW/install.yaml $ISTIO_NEW/istio-install/base mv $ISTIO_NEW/cluster-local-gateway.yaml $ISTIO_NEW/cluster-local-gateway/base rm dump.yaml -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" +check_uncommitted_changes + +SOURCE_TEXT="\[.*\](https://github.com/istio/istio/releases/tag/.*)" +DESTINATION_TEXT="\[$COMMIT\](https://github.com/istio/istio/releases/tag/$COMMIT)" + +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" + +find "$MANIFESTS_DIRECTORY" -type f -not -path '*/.git/*' -exec sed -i "s/istio-${CURRENT_VERSION}/istio-${NEW_VERSION}/g" {} + + +cd "$MANIFESTS_DIRECTORY" +if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then + rm -rf $ISTIO_OLD fi +commit_changes "$MANIFESTS_DIRECTORY" "Upgrade istio to v.${COMMIT}" "." -# Update README.md to synchronize with the upgraded Istio version -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/istio/istio/releases/tag/.*)" -DST_TXT="\[$COMMIT\](https://github.com/istio/istio/releases/tag/$COMMIT)" - -sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md - -#Synchronize the updated directory names with other files -find "$MANIFESTS_DIR" -type f -not -path '*/.git/*' -exec sed -i "s/istio-${CURRENT_VERSION}/istio-${NEW_VERSION}/g" {} + - -echo "Committing the changes..." -cd "$MANIFESTS_DIR" -rm -rf $ISTIO_OLD -git add . -git commit -s -m "Upgrade istio to v.${COMMIT}" \ No newline at end of file +echo "Synchronization completed successfully." \ No newline at end of file diff --git a/scripts/synchronize-katib-manifests.sh b/scripts/synchronize-katib-manifests.sh index ea8ed9dce..92e09f5af 100644 --- a/scripts/synchronize-katib-manifests.sh +++ b/scripts/synchronize-katib-manifests.sh @@ -1,69 +1,38 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Katib manifests -COMMIT="v0.18.0" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kubeflow-katib} -BRANCH=${BRANCH:=synchronize-kubeflow-katib-manifests-${COMMIT?}} +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +setup_error_handling -echo "Creating branch: ${BRANCH}" +COMPONENT_NAME="katib" +REPOSITORY_NAME="kubeflow/katib" +REPOSITORY_URL="https://github.com/kubeflow/katib.git" +COMMIT="v0.18.0" +REPOSITORY_DIRECTORY="katib" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kubeflow-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${COMMIT?}} -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="manifests/v1beta1" +DESTINATION_MANIFESTS_PATH="apps/${COMPONENT_NAME}/upstream" -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/manifests/v1beta1)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/manifests/v1beta1)" -# Checkout the KFP repositorysitory -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "katib/.git" ]; then - git clone https://github.com/kubeflow/katib.git -fi -cd $SRC_DIR/katib -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi +create_branch "$BRANCH_NAME" +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +copy_manifests "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${SOURCE_MANIFESTS_PATH}" "${MANIFESTS_DIRECTORY}/${DESTINATION_MANIFESTS_PATH}" -echo "Copying katib manifests..." -DST_DIR=$MANIFESTS_DIR/apps/katib/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -cp $SRC_DIR/katib/manifests/v1beta1 $DST_DIR -r +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "apps" \ + "README.md" -echo "Successfully copied all manifests." - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/katib/tree/.*/manifests/v1beta1)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/katib/tree/$COMMIT/manifests/v1beta1)" - -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps -git add README.md -git commit -s -m "Update kubeflow/katib manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-knative-manifests.sh b/scripts/synchronize-knative-manifests.sh index 893337baa..17bea5c5b 100644 --- a/scripts/synchronize-knative-manifests.sh +++ b/scripts/synchronize-knative-manifests.sh @@ -1,133 +1,110 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Knative manifests +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="knative" KN_SERVING_RELEASE="v1.16.2" # Must be a release KN_EXTENSION_RELEASE="v1.16.0" # Must be a release KN_EVENTING_RELEASE="v1.16.4" # Must be a release -BRANCH=${BRANCH:=synchronize-knative-manifests-${KN_SERVING_RELEASE?}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${KN_SERVING_RELEASE?}} -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +DESTINATION_DIRECTORY=$MANIFESTS_DIRECTORY/common/${COMPONENT_NAME} -# replace source regex ($1) with target regex ($2) -# in file ($3) -replace_in_file() { - SRC_TXT=$1 - DST_TXT=$2 - sed -i "s|$SRC_TXT|$DST_TXT|g" $3 -} +create_branch "$BRANCH_NAME" -echo "Creating branch: ${BRANCH}" +check_uncommitted_changes -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." +# Clean up existing files (keep README and OWNERS) +if [ -d "$DESTINATION_DIRECTORY" ]; then + rm -r "$DESTINATION_DIRECTORY/knative-serving/base/upstream" + rm "$DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml" + rm -r "$DESTINATION_DIRECTORY/knative-eventing/base/upstream" + rm "$DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base/eventing-post-install.yaml" fi -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi - -DST_DIR=$MANIFESTS_DIR/common/knative -if [ -d "$DST_DIR" ]; then - # keep README and OWNERS file - rm -r "$DST_DIR/knative-serving/base/upstream" - rm "$DST_DIR/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml" - rm -r "$DST_DIR/knative-eventing/base/upstream" - rm "$DST_DIR/knative-eventing-post-install-jobs/base/eventing-post-install.yaml" -fi - -mkdir -p "$DST_DIR/knative-serving/base/upstream" -mkdir -p "$DST_DIR/knative-serving-post-install-jobs/base" -mkdir -p "$DST_DIR/knative-eventing/base/upstream" -mkdir -p "$DST_DIR/knative-eventing-post-install-jobs/base" +# Create required directories +mkdir -p "$DESTINATION_DIRECTORY/knative-serving/base/upstream" +mkdir -p "$DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base" +mkdir -p "$DESTINATION_DIRECTORY/knative-eventing/base/upstream" +mkdir -p "$DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base" echo "Downloading knative-serving manifests..." -# No need to install serving-crds. -# See: https://github.com/knative/serving/issues/9945 -wget -O $DST_DIR/knative-serving/base/upstream/serving-core.yaml "https://github.com/knative/serving/releases/download/knative-$KN_SERVING_RELEASE/serving-core.yaml" -wget -O $DST_DIR/knative-serving/base/upstream/net-istio.yaml "https://github.com/knative-extensions/net-istio/releases/download/knative-$KN_EXTENSION_RELEASE/net-istio.yaml" -wget -O $DST_DIR/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml "https://github.com/knative/serving/releases/download/knative-$KN_SERVING_RELEASE/serving-post-install-jobs.yaml" +wget -O $DESTINATION_DIRECTORY/knative-serving/base/upstream/serving-core.yaml "https://github.com/knative/serving/releases/download/knative-$KN_SERVING_RELEASE/serving-core.yaml" +wget -O $DESTINATION_DIRECTORY/knative-serving/base/upstream/net-istio.yaml "https://github.com/knative-extensions/net-istio/releases/download/knative-$KN_EXTENSION_RELEASE/net-istio.yaml" +wget -O $DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml "https://github.com/knative/serving/releases/download/knative-$KN_SERVING_RELEASE/serving-post-install-jobs.yaml" -yq eval -i '... comments=""' $DST_DIR/knative-serving/base/upstream/serving-core.yaml -yq eval -i '... comments=""' $DST_DIR/knative-serving/base/upstream/net-istio.yaml -yq eval -i '... comments=""' $DST_DIR/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-serving/base/upstream/serving-core.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-serving/base/upstream/net-istio.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-serving/base/upstream/serving-core.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-serving/base/upstream/net-istio.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-serving/base/upstream/serving-core.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-serving/base/upstream/net-istio.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml -# We are not using the '|=' operator because it generates an empty object -# ({}) which crashes kustomize. -yq eval -i 'select(.kind == "Job" and .metadata.generateName == "storage-version-migration-serving-") | .metadata.name = "storage-version-migration-serving"' $DST_DIR/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml +yq eval -i 'select(.kind == "Job" and .metadata.generateName == "storage-version-migration-serving-") | .metadata.name = "storage-version-migration-serving"' $DESTINATION_DIRECTORY/knative-serving-post-install-jobs/base/serving-post-install-jobs.yaml echo "Downloading knative-eventing manifests..." +wget -O $DESTINATION_DIRECTORY/knative-eventing/base/upstream/eventing-core.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/eventing-core.yaml" +wget -O $DESTINATION_DIRECTORY/knative-eventing/base/upstream/in-memory-channel.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/in-memory-channel.yaml" +wget -O $DESTINATION_DIRECTORY/knative-eventing/base/upstream/mt-channel-broker.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/mt-channel-broker.yaml" +wget -O $DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base/eventing-post-install.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/eventing-post-install.yaml" -wget -O $DST_DIR/knative-eventing/base/upstream/eventing-core.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/eventing-core.yaml" -wget -O $DST_DIR/knative-eventing/base/upstream/in-memory-channel.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/in-memory-channel.yaml" -wget -O $DST_DIR/knative-eventing/base/upstream/mt-channel-broker.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/mt-channel-broker.yaml" -wget -O $DST_DIR/knative-eventing-post-install-jobs/base/eventing-post-install.yaml "https://github.com/knative/eventing/releases/download/knative-$KN_EVENTING_RELEASE/eventing-post-install.yaml" +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/eventing-core.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/in-memory-channel.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/mt-channel-broker.yaml +yq eval -i '... comments=""' $DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base/eventing-post-install.yaml -yq eval -i '... comments=""' $DST_DIR/knative-eventing/base/upstream/eventing-core.yaml -yq eval -i '... comments=""' $DST_DIR/knative-eventing/base/upstream/in-memory-channel.yaml -yq eval -i '... comments=""' $DST_DIR/knative-eventing/base/upstream/mt-channel-broker.yaml -yq eval -i '... comments=""' $DST_DIR/knative-eventing-post-install-jobs/base/eventing-post-install.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/eventing-core.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/in-memory-channel.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/mt-channel-broker.yaml +yq eval -i 'explode(.)' $DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base/eventing-post-install.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-eventing/base/upstream/eventing-core.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-eventing/base/upstream/in-memory-channel.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-eventing/base/upstream/mt-channel-broker.yaml -yq eval -i 'explode(.)' $DST_DIR/knative-eventing-post-install-jobs/base/eventing-post-install.yaml +yq eval -i 'select(.kind == "Job" and .metadata.generateName == "storage-version-migration-eventing-") | .metadata.name = "storage-version-migration-eventing"' $DESTINATION_DIRECTORY/knative-eventing-post-install-jobs/base/eventing-post-install.yaml -# We are not using the '|=' operator because it generates an empty object -# ({}) which crashes kustomize. -yq eval -i 'select(.kind == "Job" and .metadata.generateName == "storage-version-migration-eventing-") | .metadata.name = "storage-version-migration-eventing"' $DST_DIR/knative-eventing-post-install-jobs/base/eventing-post-install.yaml +yq eval -i 'select((.kind == "ConfigMap" and .metadata.name == "config-observability") | not)' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/in-memory-channel.yaml +yq eval -i 'select((.kind == "ConfigMap" and .metadata.name == "config-tracing") | not)' $DESTINATION_DIRECTORY/knative-eventing/base/upstream/in-memory-channel.yaml -yq eval -i 'select((.kind == "ConfigMap" and .metadata.name == "config-observability") | not)' $DST_DIR/knative-eventing/base/upstream/in-memory-channel.yaml -yq eval -i 'select((.kind == "ConfigMap" and .metadata.name == "config-tracing") | not)' $DST_DIR/knative-eventing/base/upstream/in-memory-channel.yaml - -echo "Successfully copied all manifests." - -echo "Updating README..." +# Helper function to replace text in files +replace_in_file() { + local SOURCE_TEXT=$1 + local DESTINATION_TEXT=$2 + local FILE=$3 + sed -i "s|$SOURCE_TEXT|$DESTINATION_TEXT|g" $FILE +} replace_in_file \ "\[.*\](https://github.com/knative/serving/releases/tag/knative-.*) <" \ "\[$KN_SERVING_RELEASE\](https://github.com/knative/serving/releases/tag/knative-$KN_SERVING_RELEASE) <" \ - ${MANIFESTS_DIR}/README.md + ${MANIFESTS_DIRECTORY}/README.md replace_in_file \ "> \[.*\](https://github.com/knative/eventing/releases/tag/knative-.*)" \ "> \[$KN_EVENTING_RELEASE\](https://github.com/knative/eventing/releases/tag/knative-$KN_EVENTING_RELEASE)" \ - ${MANIFESTS_DIR}/README.md + ${MANIFESTS_DIRECTORY}/README.md replace_in_file \ "\[Knative serving (v.*)\](https://github.com/knative/serving/releases/tag/knative-v.*)" \ "\[Knative serving ($KN_SERVING_RELEASE)\](https://github.com/knative/serving/releases/tag/knative-$KN_SERVING_RELEASE)" \ - $DST_DIR/README.md + $DESTINATION_DIRECTORY/README.md replace_in_file \ "\[Knative ingress controller for Istio (v.*)\](https://github.com/knative-extensions/net-istio/releases/tag/knative-v.*)" \ "\[Knative ingress controller for Istio ($KN_EXTENSION_RELEASE)\](https://github.com/knative-extensions/net-istio/releases/tag/knative-$KN_EXTENSION_RELEASE)" \ - $DST_DIR/README.md + $DESTINATION_DIRECTORY/README.md replace_in_file \ "The manifests for Knative Eventing are based off the \[v.* release\](https://github.com/knative/eventing/releases/tag/knative-v.*)" \ "The manifests for Knative Eventing are based off the \[$KN_EVENTING_RELEASE release\](https://github.com/knative/eventing/releases/tag/knative-$KN_EVENTING_RELEASE)" \ - $DST_DIR/README.md + $DESTINATION_DIRECTORY/README.md -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add $DST_DIR -git add README.md -git commit -s -m "Update common/knative manifests from ${KN_SERVING_RELEASE}/${KN_EVENTING_RELEASE}" +commit_changes "$MANIFESTS_DIRECTORY" "Update common/knative manifests from ${KN_SERVING_RELEASE}/${KN_EVENTING_RELEASE}" \ + "$DESTINATION_DIRECTORY" \ + "README.md" + +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-kserve-kserve-manifests.sh b/scripts/synchronize-kserve-kserve-manifests.sh index df2bab991..d1c260f78 100644 --- a/scripts/synchronize-kserve-kserve-manifests.sh +++ b/scripts/synchronize-kserve-kserve-manifests.sh @@ -1,71 +1,46 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the KServe manifests +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="kserve" +REPOSITORY_NAME="kserve/kserve" +REPOSITORY_URL="https://github.com/kserve/kserve.git" KSERVE_VERSION="v0.15.0" -COMMIT="v0.15.0" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kserve} -BRANCH=${BRANCH:=synchronize-kserve-manifests-${COMMIT?}} +COMMIT="v0.15.0" +REPOSITORY_DIRECTORY="kserve" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${COMMIT?}} -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="install/${KSERVE_VERSION}" +DESTINATION_MANIFESTS_PATH="apps/${COMPONENT_NAME}/${COMPONENT_NAME}" -echo "Creating branch: ${BRANCH}" +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/releases/tag/.*)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/releases/tag/${COMMIT}/install/${KSERVE_VERSION})" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +create_branch "$BRANCH_NAME" -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." - -# Checkout the kserve repository -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "kserve/.git" ]; then - git clone https://github.com/kserve/kserve.git -fi -cd $SRC_DIR/kserve -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi - - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" echo "Copying kserve manifests..." -DST_DIR=$MANIFESTS_DIR/apps/kserve/kserve -if [ -d "$DST_DIR" ]; then - rm -rf "$DST_DIR"/kserve* +DESTINATION_DIRECTORY=$MANIFESTS_DIRECTORY/$DESTINATION_MANIFESTS_PATH +if [ -d "$DESTINATION_DIRECTORY" ]; then + rm -rf "$DESTINATION_DIRECTORY"/kserve* fi -cp $SRC_DIR/kserve/install/"$KSERVE_VERSION"/* $DST_DIR -r +cp $SOURCE_DIRECTORY/$REPOSITORY_DIRECTORY/$SOURCE_MANIFESTS_PATH/* $DESTINATION_DIRECTORY -r -echo "Successfully copied all manifests." +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kserve/kserve/releases/tag/.*)" -DST_TXT="\[$COMMIT\](https://github.com/kserve/kserve/releases/tag/$COMMIT/install/$KSERVE_VERSION)" +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${KSERVE_VERSION}" \ + "apps/${COMPONENT_NAME}" \ + "README.md" \ + "scripts" -sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md - -echo "Committing the changes..." -cd "$MANIFESTS_DIR" -git add apps/kserve -git add README.md -git add scripts -git commit -s -m "Update kserve manifests from ${KSERVE_VERSION}" -m "Update kserve/kserve manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-kserve-web-application-manifests.sh b/scripts/synchronize-kserve-web-application-manifests.sh index 03bfaeffd..6f0ade506 100644 --- a/scripts/synchronize-kserve-web-application-manifests.sh +++ b/scripts/synchronize-kserve-web-application-manifests.sh @@ -1,69 +1,39 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the KServe Models Web App manifests -COMMIT="v0.14.0" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kserve-models-web-app} -BRANCH=${BRANCH:=synchronize-kserve-web-application-manifests-${COMMIT?}} +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +setup_error_handling -echo "Creating branch: ${BRANCH}" +COMPONENT_NAME="models-web-app" +REPOSITORY_NAME="kserve/models-web-app" +REPOSITORY_URL="https://github.com/kserve/models-web-app.git" +COMMIT="v0.14.0" +REPOSITORY_DIRECTORY="models-web-app" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kserve-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-kserve-${COMPONENT_NAME}-manifests-${COMMIT?}} -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="config" +DESTINATION_MANIFESTS_PATH="apps/kserve/${COMPONENT_NAME}" -if [ "$(git branch --list $BRANCH)" ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/${SOURCE_MANIFESTS_PATH})" -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +create_branch "$BRANCH_NAME" -# Checkout the Kserve Models Web Application repository -mkdir -p $SRC_DIR -cd $SRC_DIR || exit -if [ ! -d "models-web-app/.git" ]; then - git clone https://github.com/kserve/models-web-app.git -fi -cd $SRC_DIR/models-web-app || exit -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" echo "Copying manifests" -DST_DIR=$MANIFESTS_DIR/apps/kserve/models-web-app -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/models-web-app/config/* $DST_DIR -r +copy_manifests "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${SOURCE_MANIFESTS_PATH}" "${MANIFESTS_DIRECTORY}/${DESTINATION_MANIFESTS_PATH}" -echo "Successfully copied all manifests." +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kserve/models-web-app/tree/.*)" -DST_TXT="\[$COMMIT\](https://github.com/kserve/models-web-app/tree/$COMMIT/config)" +commit_changes "$MANIFESTS_DIRECTORY" "Update kserve models web application manifests from ${COMMIT}" \ + "${DESTINATION_MANIFESTS_PATH}" \ + "README.md" -sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md - -echo "Committing the changes..." -cd $MANIFESTS_DIR || exit -git add apps/kserve/models-web-app -git add README.md -git commit -s -m "Update kserve models web application manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-kubeflow-manifests.sh b/scripts/synchronize-kubeflow-manifests.sh index 977db20fb..493b0962b 100644 --- a/scripts/synchronize-kubeflow-manifests.sh +++ b/scripts/synchronize-kubeflow-manifests.sh @@ -1,172 +1,99 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Kubeflow manifests -COMMIT="v1.10.0" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kubeflow-kubeflow} -BRANCH=${BRANCH:=synchronize-kubeflow-kubeflow-manifests-${COMMIT?}} +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +setup_error_handling -echo "Creating branch: ${BRANCH}" +COMPONENT_NAME="kubeflow" +REPOSITORY_NAME="kubeflow/kubeflow" +REPOSITORY_URL="https://github.com/kubeflow/kubeflow.git" +COMMIT="v1.10.0" +REPOSITORY_DIRECTORY="kubeflow" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/${COMPONENT_NAME}-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-${COMPONENT_NAME}-manifests-${COMMIT?}} -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +create_branch "$BRANCH_NAME" -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" -# Checkout the upstream repository -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "kubeflow/.git" ]; then - git clone https://github.com/kubeflow/kubeflow.git -fi -cd $SRC_DIR/kubeflow -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi +# Function to copy manifests for a specific component +copy_component_manifests() { + local component_name=$1 + local source_path=$2 + local destination_path=$3 + local readme_path_pattern=$4 + + echo "Copying ${component_name} manifests..." + + local destination_directory="${MANIFESTS_DIRECTORY}/${destination_path}" + if [ -d "$destination_directory" ]; then + rm -r "$destination_directory" + fi + mkdir -p "$destination_directory" + + cp "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${source_path}/"* "$destination_directory" -r + + echo "Updating README for ${component_name}..." + local source_text="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/components/${readme_path_pattern})" + local destination_text="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/components/${readme_path_pattern})" + + update_readme "$MANIFESTS_DIRECTORY" "$source_text" "$destination_text" +} -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +copy_component_manifests "admission-webhook" \ + "components/admission-webhook/manifests" \ + "apps/admission-webhook/upstream" \ + "admission-webhook/manifests" -echo "Copying admission-webhook manifests..." -DST_DIR=$MANIFESTS_DIR/apps/admission-webhook/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/admission-webhook/manifests/* $DST_DIR -r +copy_component_manifests "centraldashboard" \ + "components/centraldashboard/manifests" \ + "apps/centraldashboard/upstream" \ + "centraldashboard/manifests" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/admission-webhook/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/admission-webhook/manifests)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md +copy_component_manifests "jupyter-web-app" \ + "components/crud-web-apps/jupyter/manifests" \ + "apps/jupyter/jupyter-web-app/upstream" \ + "crud-web-apps/jupyter/manifests" -echo "Copying centraldashboard manifests..." -DST_DIR=$MANIFESTS_DIR/apps/centraldashboard/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/centraldashboard/manifests/* $DST_DIR -r +copy_component_manifests "volumes-web-app" \ + "components/crud-web-apps/volumes/manifests" \ + "apps/volumes-web-app/upstream" \ + "crud-web-apps/volumes/manifests" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/centraldashboard/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/centraldashboard/manifests)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md +copy_component_manifests "tensorboards-web-app" \ + "components/crud-web-apps/tensorboards/manifests" \ + "apps/tensorboard/tensorboards-web-app/upstream" \ + "crud-web-apps/tensorboards/manifests" -echo "Copying jupyter-web-app manifests..." -DST_DIR=$MANIFESTS_DIR/apps/jupyter/jupyter-web-app/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/crud-web-apps/jupyter/manifests/* $DST_DIR -r +copy_component_manifests "profile-controller" \ + "components/profile-controller/config" \ + "apps/profiles/upstream" \ + "profile-controller/config" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/crud-web-apps/jupyter/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/crud-web-apps/jupyter/manifests)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md +copy_component_manifests "notebook-controller" \ + "components/notebook-controller/config" \ + "apps/jupyter/notebook-controller/upstream" \ + "notebook-controller/config" -echo "Copying volumes-web-app manifests..." -DST_DIR=$MANIFESTS_DIR/apps/volumes-web-app/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/crud-web-apps/volumes/manifests/* $DST_DIR -r +copy_component_manifests "tensorboard-controller" \ + "components/tensorboard-controller/config" \ + "apps/tensorboard/tensorboard-controller/upstream" \ + "tensorboard-controller/config" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/crud-web-apps/volumes/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/crud-web-apps/volumes/manifests)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Copying tensorboards-web-app manifests..." -DST_DIR=$MANIFESTS_DIR/apps/tensorboard/tensorboards-web-app/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/crud-web-apps/tensorboards/manifests/* $DST_DIR -r - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/crud-web-apps/tensorboards/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/crud-web-apps/tensorboards/manifests)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Copying profile-controller manifests..." -DST_DIR=$MANIFESTS_DIR/apps/profiles/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/profile-controller/config/* $DST_DIR -r - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/profile-controller/config)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/profile-controller/config)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Copying notebook-controller manifests..." -DST_DIR=$MANIFESTS_DIR/apps/jupyter/notebook-controller/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/notebook-controller/config/* $DST_DIR -r - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/notebook-controller/config)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/notebook-controller/config)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Copying tensorboard-controller manifests..." -DST_DIR=$MANIFESTS_DIR/apps/tensorboard/tensorboard-controller/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/tensorboard-controller/config/* $DST_DIR -r - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/tensorboard-controller/config)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/tensorboard-controller/config)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Copying pvcviewer-controller manifests..." -DST_DIR=$MANIFESTS_DIR/apps/pvcviewer-controller/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp $SRC_DIR/kubeflow/components/pvcviewer-controller/config/* $DST_DIR -r - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/kubeflow/tree/.*/components/pvcviewer-controller/config)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/kubeflow/tree/$COMMIT/components/pvcviewer-controller/config)" -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md +copy_component_manifests "pvcviewer-controller" \ + "components/pvcviewer-controller/config" \ + "apps/pvcviewer-controller/upstream" \ + "pvcviewer-controller/config" echo "Successfully copied all manifests." -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps -git add README.md -git commit -s -m "Update kubeflow/kubeflow manifests from ${COMMIT}" +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "apps" \ + "README.md" + +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-model-registry-manifests.sh b/scripts/synchronize-model-registry-manifests.sh index 72c5938fa..ae55ed222 100644 --- a/scripts/synchronize-model-registry-manifests.sh +++ b/scripts/synchronize-model-registry-manifests.sh @@ -1,70 +1,47 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Model Registry manifests -COMMIT="v0.2.13" # You can use tags as well +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="model-registry" +REPOSITORY_NAME="kubeflow/model-registry" +REPOSITORY_URL="https://github.com/kubeflow/model-registry.git" +COMMIT="v0.2.13" +REPOSITORY_DIRECTORY="model-registry" DEV_MODE=${DEV_MODE:=false} -SRC_DIR=${SRC_DIR:=/tmp/kubeflow-model-registry} -BRANCH=${BRANCH:=synchronize-kubeflow-model-registry-manifests-${COMMIT?}} +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kubeflow-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-kubeflow-${COMPONENT_NAME}-manifests-${COMMIT?}} -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="manifests/kustomize" +DESTINATION_MANIFESTS_PATH="apps/${COMPONENT_NAME}/upstream" -echo "Creating branch: ${BRANCH}" +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/manifests/kustomize)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/manifests/kustomize)" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" +create_branch "$BRANCH_NAME" + +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" + +echo "Copying ${COMPONENT_NAME} manifests..." +DESTINATION_DIRECTORY=$MANIFESTS_DIRECTORY/$DESTINATION_MANIFESTS_PATH +if [ -d "$DESTINATION_DIRECTORY" ]; then + rm -r "$DESTINATION_DIRECTORY" fi - -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi - -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." - -# Checkout the Model Registry repository -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "model-registry/.git" ]; then - git clone https://github.com/kubeflow/model-registry.git -fi -cd $SRC_DIR/model-registry -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi - -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi - -echo "Copying model-registry manifests..." -DST_DIR=$MANIFESTS_DIR/apps/model-registry/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -mkdir -p $DST_DIR -cp -r "$SRC_DIR/model-registry/manifests/kustomize/"* "$DST_DIR" +mkdir -p $DESTINATION_DIRECTORY +cp -r "$SOURCE_DIRECTORY/$REPOSITORY_DIRECTORY/$SOURCE_MANIFESTS_PATH/"* "$DESTINATION_DIRECTORY" echo "Successfully copied all manifests." -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/model-registry/tree/.*/manifests/kustomize)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/model-registry/tree/$COMMIT/manifests/kustomize)" +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" -sed -i "" "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}/README.md" +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "apps" \ + "README.md" -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps -git add README.md -git commit -s -m "Update kubeflow/model-registry manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-pipelines-manifests.sh b/scripts/synchronize-pipelines-manifests.sh index 3dac613fb..6c2a82f4d 100644 --- a/scripts/synchronize-pipelines-manifests.sh +++ b/scripts/synchronize-pipelines-manifests.sh @@ -1,68 +1,39 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' -COMMIT="2.4.1" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kubeflow-pipelines} -BRANCH=${BRANCH:=synchronize-kubeflow-pipelines-manifests-${COMMIT?}} +# This script helps to create a PR to update the Kubeflow Pipelines manifests -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" -echo "Creating branch: ${BRANCH}" +setup_error_handling -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +COMPONENT_NAME="pipelines" +REPOSITORY_NAME="kubeflow/pipelines" +REPOSITORY_URL="https://github.com/kubeflow/pipelines.git" +COMMIT="2.4.1" +REPOSITORY_DIRECTORY="pipelines" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kubeflow-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-kubeflow-${COMPONENT_NAME}-manifests-${COMMIT?}} -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi -echo "Checking out in $SRC_DIR to $COMMIT..." +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="manifests/kustomize" +DESTINATION_MANIFESTS_PATH="apps/pipeline/upstream" -# Checkout the KFP repository -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "pipelines/.git" ]; then - git clone https://github.com/kubeflow/pipelines.git -fi -cd $SRC_DIR/pipelines -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/manifests/kustomize)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/manifests/kustomize)" +create_branch "$BRANCH_NAME" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" -echo "Copying pipelines manifests..." -DST_DIR=$MANIFESTS_DIR/apps/pipeline/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -cp $SRC_DIR/pipelines/manifests/kustomize $DST_DIR -r +echo "Copying ${COMPONENT_NAME} manifests..." +copy_manifests "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${SOURCE_MANIFESTS_PATH}" "${MANIFESTS_DIRECTORY}/${DESTINATION_MANIFESTS_PATH}" +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" -echo "Successfully copied all manifests." +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "apps" \ + "README.md" -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/pipelines/tree/.*/manifests/kustomize)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/pipelines/tree/$COMMIT/manifests/kustomize)" - -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps -git add README.md -git commit -s -m "Update kubeflow/pipelines manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-spark-operator-manifests.sh b/scripts/synchronize-spark-operator-manifests.sh index 6f24292cd..21379113f 100755 --- a/scripts/synchronize-spark-operator-manifests.sh +++ b/scripts/synchronize-spark-operator-manifests.sh @@ -1,35 +1,28 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Spark Operator manifests -# You can use tags or commit hashes +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +COMPONENT_NAME="spark-operator" SPARK_OPERATOR_VERSION=${SPARK_OPERATOR_VERSION:="2.1.1"} SPARK_OPERATOR_HELM_CHART_REPO=${SPARK_OPERATOR_HELM_CHART_REPO:="https://kubeflow.github.io/spark-operator"} DEV_MODE=${DEV_MODE:=false} -BRANCH=${BRANCH:=synchronize-spark-operator-manifests-${SPARK_OPERATOR_VERSION?}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${SPARK_OPERATOR_VERSION?}} -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +DESTINATION_MANIFESTS_PATH="apps/spark/${COMPONENT_NAME}/base" -echo "Creating branch: ${BRANCH}" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi - -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi +create_branch "$BRANCH_NAME" echo "Generating manifests from Helm chart version ${SPARK_OPERATOR_VERSION}..." -# Generate the manifests using Helm -DST_DIR=$MANIFESTS_DIR/apps/spark/spark-operator/base -mkdir -p $DST_DIR -cd $DST_DIR +DESTINATION_DIRECTORY=$MANIFESTS_DIRECTORY/$DESTINATION_MANIFESTS_PATH +mkdir -p $DESTINATION_DIRECTORY +cd $DESTINATION_DIRECTORY # Create a kustomization.yaml file if it doesn't exist if [ ! -f kustomization.yaml ]; then @@ -41,7 +34,6 @@ resources: EOF fi -# Generate the manifests using Helm helm template -n kubeflow --include-crds spark-operator spark-operator \ --set "spark.jobNamespaces={}" \ --set webhook.enable=true \ @@ -51,19 +43,16 @@ helm template -n kubeflow --include-crds spark-operator spark-operator \ echo "Successfully generated manifests." -echo "Updating README..." # Use OS-compatible sed command if [[ "$OSTYPE" == "darwin"* ]]; then - # macOS version - sed -i '' 's/Spark Operator[^|]*|[^|]*apps\/spark\/spark-operator[^|]*|[^|]*[0-9]\.[0-9]\.[0-9]/Spark Operator | apps\/spark\/spark-operator | '"${SPARK_OPERATOR_VERSION}"'/g' "${MANIFESTS_DIR}/README.md" + sed -i '' 's/Spark Operator[^|]*|[^|]*apps\/spark\/spark-operator[^|]*|[^|]*[0-9]\.[0-9]\.[0-9]/Spark Operator | apps\/spark\/spark-operator | '"${SPARK_OPERATOR_VERSION}"'/g' "${MANIFESTS_DIRECTORY}/README.md" else - # Linux version - sed -i 's/Spark Operator.*|.*apps\/spark\/spark-operator[^|]*|.*[0-9]\.[0-9]\.[0-9]/Spark Operator | apps\/spark\/spark-operator | '"${SPARK_OPERATOR_VERSION}"'/g' "${MANIFESTS_DIR}/README.md" + sed -i 's/Spark Operator.*|.*apps\/spark\/spark-operator[^|]*|.*[0-9]\.[0-9]\.[0-9]/Spark Operator | apps\/spark\/spark-operator | '"${SPARK_OPERATOR_VERSION}"'/g' "${MANIFESTS_DIRECTORY}/README.md" fi -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps/spark -git add README.md -git add scripts -git commit -s -m "Update kubeflow/spark-operator manifests to ${SPARK_OPERATOR_VERSION}" +commit_changes "$MANIFESTS_DIRECTORY" "Update kubeflow/${COMPONENT_NAME} manifests to ${SPARK_OPERATOR_VERSION}" \ + "apps/spark" \ + "README.md" \ + "scripts" + +echo "Synchronization completed successfully." diff --git a/scripts/synchronize-training-operator-manifests.sh b/scripts/synchronize-training-operator-manifests.sh index 3ac311c3f..9e863d1ee 100644 --- a/scripts/synchronize-training-operator-manifests.sh +++ b/scripts/synchronize-training-operator-manifests.sh @@ -1,71 +1,38 @@ #!/usr/bin/env bash -# This script helps to create a PR to update the manifests -set -euxo pipefail -IFS=$'\n\t' +# This script helps to create a PR to update the Training Operator manifests -COMMIT="v1.9.1" # You can use tags as well -SRC_DIR=${SRC_DIR:=/tmp/kubeflow-training-operator} -BRANCH=${BRANCH:=synchronize-kubeflow-training-operator-manifests-${COMMIT?}} +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -MANIFESTS_DIR=$(dirname $SCRIPT_DIR) +setup_error_handling -echo "Creating branch: ${BRANCH}" +COMPONENT_NAME="training-operator" +REPOSITORY_NAME="kubeflow/training-operator" +REPOSITORY_URL="https://github.com/kubeflow/training-operator.git" +COMMIT="v1.9.1" +REPOSITORY_DIRECTORY="training-operator" +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kubeflow-${COMPONENT_NAME}} +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${COMMIT?}} -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +# Path configurations +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="manifests" +DESTINATION_MANIFESTS_PATH="apps/${COMPONENT_NAME}/upstream" -if [ `git branch --list $BRANCH` ] -then - echo "WARNING: Branch $BRANCH already exists." -fi +# README update patterns +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/manifests)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/manifests)" -# Create the branch in the manifests repository -if ! git show-ref --verify --quiet refs/heads/$BRANCH; then - git checkout -b $BRANCH -else - echo "Branch $BRANCH already exists." -fi +create_branch "$BRANCH_NAME" -echo "Checking out in $SRC_DIR to $COMMIT..." +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" -# Checkout the Training Operator repository -mkdir -p $SRC_DIR -cd $SRC_DIR -if [ ! -d "training-operator/.git" ]; then - git clone https://github.com/kubeflow/training-operator.git -fi -cd $SRC_DIR/training-operator -if ! git rev-parse --verify --quiet $COMMIT; then - git checkout -b $COMMIT -else - git checkout $COMMIT -fi +copy_manifests "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${SOURCE_MANIFESTS_PATH}" "${MANIFESTS_DIRECTORY}/${DESTINATION_MANIFESTS_PATH}" -if [ -n "$(git status --porcelain)" ]; then - echo "WARNING: You have uncommitted changes" -fi +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" -echo "Copying training-operator manifests..." -DST_DIR=$MANIFESTS_DIR/apps/training-operator/upstream -if [ -d "$DST_DIR" ]; then - rm -r "$DST_DIR" -fi -cp $SRC_DIR/training-operator/manifests $DST_DIR -r +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "apps" \ + "README.md" - -echo "Successfully copied all manifests." - -echo "Updating README..." -SRC_TXT="\[.*\](https://github.com/kubeflow/training-operator/tree/.*/manifests)" -DST_TXT="\[$COMMIT\](https://github.com/kubeflow/training-operator/tree/$COMMIT/manifests)" - -sed -i "s|$SRC_TXT|$DST_TXT|g" ${MANIFESTS_DIR}/README.md - -# DEV: Comment out these commands if you are testing locally -echo "Committing the changes..." -cd $MANIFESTS_DIR -git add apps -git add README.md -git commit -s -m "Update kubeflow/training-operator manifests from ${COMMIT}" +echo "Synchronization completed successfully." diff --git a/scripts/template.sh b/scripts/template.sh new file mode 100644 index 000000000..1a0c21ee5 --- /dev/null +++ b/scripts/template.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Template for Kubeflow manifests synchronization scripts +# Usage: Copy this file and adjust the variables for your specific component + +# Source the common library functions +SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIRECTORY}/lib.sh" + +setup_error_handling + +# Configuration variables (adjust these for your specific component) +COMPONENT_NAME="component-name" # Name of the component (e.g., katib, training-operator) +REPOSITORY_NAME="repo-name" # Repository name (e.g., kubeflow/katib) +REPOSITORY_URL="https://github.com/org/repo.git" # Repository URL to clone from +COMMIT="v0.0.0" # Version/commit to synchronize +REPOSITORY_DIRECTORY="${COMPONENT_NAME}" # Directory name within SOURCE_DIRECTORY +SOURCE_DIRECTORY=${SOURCE_DIRECTORY:=/tmp/kubeflow-${COMPONENT_NAME}} # Where to clone the source repo +BRANCH_NAME=${BRANCH_NAME:=synchronize-${COMPONENT_NAME}-manifests-${COMMIT?}} # Branch name for the PR + +MANIFESTS_DIRECTORY=$(dirname $SCRIPT_DIRECTORY) +SOURCE_MANIFESTS_PATH="manifests" # Path within source repo where manifests are +DESTINATION_MANIFESTS_PATH="apps/${COMPONENT_NAME}/upstream" # Destination path within manifests repo + +SOURCE_TEXT="\[.*\](https://github.com/${REPOSITORY_NAME}/tree/.*/manifests)" +DESTINATION_TEXT="\[${COMMIT}\](https://github.com/${REPOSITORY_NAME}/tree/${COMMIT}/manifests)" + +create_branch "$BRANCH_NAME" + +clone_and_checkout "$SOURCE_DIRECTORY" "$REPOSITORY_URL" "$REPOSITORY_DIRECTORY" "$COMMIT" + +copy_manifests "${SOURCE_DIRECTORY}/${REPOSITORY_DIRECTORY}/${SOURCE_MANIFESTS_PATH}" "${MANIFESTS_DIRECTORY}/${DESTINATION_MANIFESTS_PATH}" + +update_readme "$MANIFESTS_DIRECTORY" "$SOURCE_TEXT" "$DESTINATION_TEXT" + +commit_changes "$MANIFESTS_DIRECTORY" "Update ${REPOSITORY_NAME} manifests from ${COMMIT}" \ + "${DESTINATION_MANIFESTS_PATH}" \ + "README.md" + +echo "Synchronization completed successfully." \ No newline at end of file