xref: /aosp_15_r20/external/executorch/scripts/release/cut-release-branch.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/usr/bin/env bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8: '
9So you are looking to cut a release branch? Well you came
10to the right script.
11
12This script can be used to cut any branch on any repository
13
14For `pytorch/executorch` usage would be like:
15> DRY_RUN=disabled ./scripts/release/cut-release-branch.sh
16
17or to cut from main branch:
18> DRY_RUN=disabled GIT_BRANCH_TO_CUT_FROM=main ./scripts/release/cut-release-branch.sh
19'
20
21set -eou pipefail
22
23GIT_TOP_DIR=$(git rev-parse --show-toplevel)
24GIT_REMOTE=${GIT_REMOTE:-origin}
25GIT_BRANCH_TO_CUT_FROM=${GIT_BRANCH_TO_CUT_FROM:-viable/strict}
26
27# should output something like 1.11
28RELEASE_VERSION=${RELEASE_VERSION:-$(cut -d'.' -f1-2 "${GIT_TOP_DIR}/version.txt")}
29
30DRY_RUN_FLAG="--dry-run"
31if [[ ${DRY_RUN:-enabled} == "disabled" ]]; then
32    DRY_RUN_FLAG=""
33fi
34
35
36(
37    set -x
38    git fetch --all
39    git checkout "${GIT_REMOTE}/${GIT_BRANCH_TO_CUT_FROM}"
40)
41
42for branch in "release/${RELEASE_VERSION}" "orig/release/${RELEASE_VERSION}"; do
43    if git rev-parse --verify "${branch}" >/dev/null 2>/dev/null; then
44        echo "+ Branch ${branch} already exists, skipping..."
45        continue
46    else
47        (
48            set -x
49            git checkout "${GIT_REMOTE}/${GIT_BRANCH_TO_CUT_FROM}"
50            git checkout -b "${branch}"
51            git push -q ${DRY_RUN_FLAG} "${GIT_REMOTE}" "${branch}"
52        )
53    fi
54done
55