vitess.io/vitess@v0.16.2/tools/code_freeze.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2022 The Vitess Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  #############
    18  #
    19  # This script changes the code_freeze workflow to either fail or succeed.
    20  #
    21  # The first argument of the script is a string, which should be either: "freeze" or "unfreeze".
    22  #   - If the argument == "freeze" then the workflow will always fail.
    23  #   - If the argument == "unfreeze" then the workflow will always succeed.
    24  #
    25  # The second argument is the name of the branch you want to freeze or unfreeze.
    26  # The script takes care of creating a branch that is based on top of the branch
    27  # you want to freeze/unfreeze. A commit is then created on this new branch, allowing
    28  # you to push the commit and create a Pull Request that you merge against the input
    29  # branch.
    30  #
    31  #############
    32  
    33  freeze=$1
    34  branch=$2
    35  code_freeze_workflow="./.github/workflows/code_freeze.yml"
    36  
    37  if [ "$freeze" != "freeze" && "$freeze" != "unfreeze" ]; then
    38      echo "the first argument must be either 'freeze' or 'unfreeze'"
    39      exit 1
    40  fi
    41  
    42  new_branch_name=$branch-code-freeze-1
    43  git checkout -b $new_branch_name $branch
    44  for (( i = 2; $? != 0; i++ )); do
    45    new_branch_name=$branch-code-freeze-$i
    46    git checkout -b $new_branch_name $branch
    47  done
    48  
    49  if [ "$freeze" == "freeze" ]; then
    50      sed -i.bak -E "s/exit (.*)/exit 1/g" $code_freeze_workflow
    51  elif [ "$freeze" == "unfreeze" ]; then
    52      sed -i.bak -E "s/exit (.*)/exit 0/g" $code_freeze_workflow
    53  fi
    54  
    55  rm -f $code_freeze_workflow.bak
    56  
    57  git add --all
    58  git commit -n -s -m "Code $freeze of $branch"
    59  
    60  echo " ------------------------------ "
    61  echo " "
    62  echo "The branch is ready to be pushed. Push it using the following line and create a PR against ${branch}"
    63  echo "      git push upstream ${new_branch_name}"
    64  echo " "
    65  echo "(make sure to replace upstream with vitessio/vitess' remote)"