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