Jim Rigsbee
2020-02-26 a88031495958d4341fb4782e2ba8ababc7303e2f
commit | author | age
295faf 1 #!/bin/bash
GC 2
3 usage() {
4     echo "$0 [CONFIG] [STAGE]"
5     echo
6     echo "CONFIG: ALL | ocp-workshop | ocp-demo-lab | ans-tower-lab | ..."
e66def 7     echo "STAGE: test | prod | rhte"
295faf 8 }
GC 9
10 if [ -z "${1}" ] || [ -z "${2}" ]; then
11     usage
12     exit 1
13 fi
14
15 set -u -o pipefail
16
17 ORIG=$(cd $(dirname $0); pwd)
18
19 prompt_continue() {
20     # call with a prompt string or use a default
21     read -r -p "${1:-Continue? [Y/n]} " response
22
23     if [ -z "${response}" ]; then
24         true
25     else
26         case "${response}" in
534b26 27             yes|y|Y|Yes|YES) true ;;
295faf 28             *) false ;;
GC 29         esac
30     fi
31 }
32
33 configs=$1
34 stage=$2
35
36 if [ "${configs}" = "ALL" ]; then
37     configs=$(ls ${ORIG}/../ansible/configs)
38 fi
39
40 git log -1
41 echo
42 echo "About to tag this commit."
43 prompt_continue || exit 0
44
45 for config in ${configs}; do
88aa81 46     last=$(git tag -l|grep ^${config}-${stage} |sort -V|tail -n 1|egrep -o '[0-9]+\.[0-9]+$')
295faf 47     if [ -z "${last}" ]; then
GC 48         echo "INFO: no version found for ${config}, skipping"
78fc1d 49         echo "Do you want to create it ?"
GC 50         prompt_continue || continue
51
52         next_tag=${config}-${stage}-0.1
53     else
54         major=$(echo $last|egrep -o '^[0-9]+')
55         minor=$(echo $last|egrep -o '[0-9]+$')
56         next_tag=${config}-${stage}-${major}.$(( minor + 1))
295faf 57     fi
GC 58
59     echo "will now perform 'git tag ${next_tag}'"
60     prompt_continue || continue
61
62     git tag ${next_tag}
63
64     echo "will now perform 'git push origin ${next_tag}"
65     prompt_continue || continue
66     git push origin ${next_tag}
67 done