|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2025 MongoDB Inc |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +# Check if an argument is provided |
| 19 | +if [ -z "$1" ]; then |
| 20 | + echo "Error: No target specified." |
| 21 | + echo "Usage: $0 [all | <target_string>]" |
| 22 | + echo " all : Resets community, openshift, and certified operators." |
| 23 | + echo " <target_string> : Resets specific operators if the string contains:" |
| 24 | + echo " 'community', 'openshift', or 'certified'." |
| 25 | + echo "Example: $0 'community certified' (resets both)" |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +TARGET="$1" |
| 30 | + |
| 31 | +function reset_community() { |
| 32 | + echo "Remove prev version branch locally and remotely" |
| 33 | + pushd "${RH_COMMUNITY_OPERATORHUB_REPO_PATH}" |
| 34 | + git checkout main |
| 35 | + git branch -D "mongodb-atlas-operator-community-${VERSION}" |
| 36 | + git push origin ":mongodb-atlas-operator-community-${VERSION}" |
| 37 | + popd |
| 38 | +} |
| 39 | + |
| 40 | +function reset_openshift() { |
| 41 | + echo "Remove prev version branch locally and remotely" |
| 42 | + pushd "${RH_COMMUNITY_OPENSHIFT_REPO_PATH}" |
| 43 | + git checkout main |
| 44 | + git branch -D "mongodb-atlas-operator-community-${VERSION}" |
| 45 | + git push origin ":mongodb-atlas-operator-community-${VERSION}" |
| 46 | + popd |
| 47 | +} |
| 48 | + |
| 49 | +function reset_certified() { |
| 50 | + echo "Remove prev version branch locally and remotely" |
| 51 | + pushd "${RH_CERTIFIED_OPENSHIFT_REPO_PATH}" |
| 52 | + git checkout main |
| 53 | + git branch -D "mongodb-atlas-kubernetes-operator-${VERSION}" |
| 54 | + git push origin ":mongodb-atlas-kubernetes-operator-${VERSION}" |
| 55 | + popd |
| 56 | +} |
| 57 | + |
| 58 | +TARGET_LOWER=$(echo "$TARGET" | tr '[:upper:]' '[:lower:]') |
| 59 | + |
| 60 | +RUN_COMMUNITY=false |
| 61 | +RUN_OPENSHIFT=false |
| 62 | +RUN_CERTIFIED=false |
| 63 | + |
| 64 | +if [[ "$TARGET_LOWER" == "all" ]]; then |
| 65 | + RUN_COMMUNITY=true |
| 66 | + RUN_OPENSHIFT=true |
| 67 | + RUN_CERTIFIED=true |
| 68 | +else |
| 69 | + if [[ "$TARGET_LOWER" == *"community"* ]]; then |
| 70 | + RUN_COMMUNITY=true |
| 71 | + fi |
| 72 | + if [[ "$TARGET_LOWER" == *"openshift"* ]]; then |
| 73 | + RUN_OPENSHIFT=true |
| 74 | + fi |
| 75 | + if [[ "$TARGET_LOWER" == *"certified"* ]]; then |
| 76 | + RUN_CERTIFIED=true |
| 77 | + fi |
| 78 | + |
| 79 | + if [ "$RUN_COMMUNITY" = false ] && [ "$RUN_OPENSHIFT" = false ] && [ "$RUN_CERTIFIED" = false ]; then |
| 80 | + echo "Error: Invalid argument '$TARGET'." |
| 81 | + echo "Argument must be 'all' or contain 'community', 'openshift', or 'certified'." |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +fi |
| 85 | + |
| 86 | +# Execute the functions based on flags |
| 87 | +if [ "$RUN_COMMUNITY" = true ]; then |
| 88 | + reset_community |
| 89 | +fi |
| 90 | + |
| 91 | +if [ "$RUN_OPENSHIFT" = true ]; then |
| 92 | + reset_openshift |
| 93 | +fi |
| 94 | + |
| 95 | +if [ "$RUN_CERTIFIED" = true ]; then |
| 96 | + reset_certified |
| 97 | +fi |
| 98 | + |
0 commit comments