xref: /aosp_15_r20/external/pytorch/scripts/release/promote/common_utils.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env bash
2
3exit_if_not_on_git_tag() {
4    # Have an override for debugging purposes
5    if [[ -n "${TEST_WITHOUT_GIT_TAG-}" ]] ;then
6        >&2 echo "+ WARN: Continuing without being on a git tag"
7        exit 0
8    fi
9    # Exit if we're not currently on a git tag
10    if ! git describe --tags --exact >/dev/null 2>/dev/null; then
11        >&2 echo "- ERROR: Attempting to promote on a non-git tag, must have tagged current commit locally first"
12        exit 1
13    fi
14    # Exit if we're currently on an RC
15    if git describe --tags | grep "-rc" >/dev/null 2>/dev/null; then
16        >&2 echo "- ERROR: Attempting to promote on a non GA git tag, current tag must be a GA tag"
17        >&2 echo "         Example: v1.5.0"
18        exit 1
19    fi
20}
21
22get_pytorch_version() {
23    if [[ -n "${TEST_WITHOUT_GIT_TAG-}" ]];then
24        if  [[ -z "${TEST_PYTORCH_PROMOTE_VERSION-}" ]]; then
25            >&2 echo "- ERROR: Specified TEST_WITHOUT_GIT_TAG without specifying TEST_PYTORCH_PROMOTE_VERSION"
26            >&2 echo "-        TEST_PYTORCH_PROMOTE_VERSION must be specified"
27            exit 1
28        else
29            echo "${TEST_PYTORCH_PROMOTE_VERSION}"
30            exit 0
31        fi
32    fi
33    exit_if_not_on_git_tag
34    # Echo git tag, strip leading v
35    git describe --tags | sed -e 's/^v//'
36}
37
38aws_promote() {
39    package_name=$1
40    pytorch_version=$(get_pytorch_version)
41    # Dry run by default
42    DRY_RUN=${DRY_RUN:-enabled}
43    DRY_RUN_FLAG="--dryrun"
44    if [[ $DRY_RUN = "disabled" ]]; then
45        DRY_RUN_FLAG=""
46    fi
47    AWS=${AWS:-aws}
48    (
49        set -x
50        ${AWS} s3 cp ${DRY_RUN_FLAG} \
51            --only-show-errors \
52            --acl public-read \
53            --recursive \
54            --exclude '*' \
55            --include "*${package_name}-${pytorch_version}*" \
56            "${PYTORCH_S3_FROM/\/$//}" \
57            "${PYTORCH_S3_TO/\/$//}"
58    )
59    # ^ We grep for package_name-.*pytorch_version to avoid any situations where domain libraries have
60    #   the same version on our S3 buckets
61}
62