xref: /aosp_15_r20/external/cpu_features/scripts/make_release.sh (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1#!/usr/bin/env bash
2
3set -e # Fail on error
4set -u # Treat unset variables as an error and exit immediately
5
6ACTION='\033[1;90m'
7FINISHED='\033[1;96m'
8NOCOLOR='\033[0m'
9ERROR='\033[0;31m'
10
11echo -e "${ACTION}Checking environnement${NOCOLOR}"
12if [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
13then
14    echo -e "${ERROR}Invalid version number. Aborting. ${NOCOLOR}"
15    exit 1
16fi
17
18declare -r VERSION=$1
19declare -r GIT_TAG="v$1"
20
21BRANCH=$(git rev-parse --abbrev-ref HEAD)
22if [[ "${BRANCH}" != "main" ]]
23then
24    echo -e "${ERROR}Not on main. Aborting. ${NOCOLOR}"
25    echo
26    exit 1
27fi
28
29git fetch
30HEADHASH=$(git rev-parse HEAD)
31UPSTREAMHASH=$(git rev-parse main@{upstream})
32
33if [[ "${HEADHASH}" != "${UPSTREAMHASH}" ]]
34then
35    echo -e "${ERROR}Not up to date with origin. Aborting.${NOCOLOR}"
36    echo
37    exit 1
38fi
39
40git update-index -q --refresh
41if ! git diff-index --quiet HEAD --
42then
43    echo -e "${ERROR}Branch has uncommited changes. Aborting.${NOCOLOR}"
44    exit 1
45fi
46
47if [ ! -z "$(git ls-files --exclude-standard --others)" ]
48then
49    echo -e "${ERROR}Branch has untracked files. Aborting.${NOCOLOR}"
50    exit 1
51fi
52
53declare -r LATEST_GIT_TAG=$(git describe --tags --abbrev=0)
54declare -r LATEST_VERSION=${LATEST_GIT_TAG#"v"}
55
56if ! dpkg --compare-versions "${VERSION}" "gt" "${LATEST_VERSION}"
57then
58    echo -e "${ERROR}Invalid version ${VERSION} <= ${LATEST_VERSION} (latest). Aborting.${NOCOLOR}"
59    exit 1
60fi
61
62echo -e "${ACTION}Modifying CMakeLists.txt${NOCOLOR}"
63sed -i "s/CpuFeatures VERSION ${LATEST_VERSION}/CpuFeatures VERSION ${VERSION}/g" CMakeLists.txt
64
65echo -e "${ACTION}Commit new revision${NOCOLOR}"
66git add CMakeLists.txt
67git commit -m"Release ${GIT_TAG}"
68
69echo -e "${ACTION}Create new tag${NOCOLOR}"
70git tag ${GIT_TAG}
71
72echo -e "${FINISHED}Manual steps:${NOCOLOR}"
73echo -e "${FINISHED} - Push the tag upstream 'git push origin ${GIT_TAG}'${NOCOLOR}"
74echo -e "${FINISHED} - Create a new release https://github.com/google/cpu_features/releases/new${NOCOLOR}"
75echo -e "${FINISHED} - Update the Release Notes 'gren release --override'${NOCOLOR}"
76