summaryrefslogtreecommitdiffstats
path: root/makerelease38.sh
blob: aad16d26d7a48199dec5e4dda74b4a6a37ab0436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# This script automates the steps required to "cut" a GlusterFS release
# Before running this script it assumes:
# - You've run all prove tests and they all pass, or have very good reasons for
#   ignoring any failures.
# - You have a working GlusterFS repo
# - You've installed any libraries which are required to build GlusterFS
# - You are _authorized_ by the storage to to cut a release, e-mail storage@fb.com
#   if you are unsure.
#

PUBLISH_REPO=false
TAG_RELEASE=true
BUILD_FROM_TAG=false
GFS_VER="3.8.15_fb"
function usage {
cat << EOF
Usage $0 [-p|-t|-n] <release tag>,

Where,
    -p     publish the RPMs to the site-packages repo.
    -n     suppress making git tag for this release (cannot be used with -p).
    -t     checkout tag and publish RPMs from this tag

e.g. "$0 1" creates a release called v3.6.3_fb-1

HINT: If you just want to create "test" RPMs, this isn't the script you are
      looking for; use buildrpm.sh for this.  This script is intended for
      releasing _production_ quality RPMs.

EOF
exit 1
}

(( $# == 0 )) && usage
while getopts ":apnt" options; do
  case $options in
    a )  echo "Hey Mr. Old-skool, '-a' is deprecated; use '-p' to publish your RPMs."
         echo "NB: unlike '-a', '-p' publishes RPMs *immediately*. Be sure that's what you want!"
         exit 1
         ;;
    p ) PUBLISH_REPO=true;;
    n ) TAG_RELEASE=false;;
    t ) BUILD_FROM_TAG=true;; 
   \? ) usage;;
    * )  usage;;
  esac
done

if [ $PUBLISH_REPO -a ! $TAG_RELEASE ]; then
   echo "Cannot publish release without tagging."
   exit 1
fi

if $BUILD_FROM_TAG; then 
    TAG_RELEASE=false
fi

RELEASE_TAG=${@:$OPTIND:1}

echo -n "Checking if user is root..."
if [ $USER == "root" ]; then
  echo yes
  echo "This script is not intended to be run by root, aborting!" && exit 1
else
  echo DONE
fi

echo -n "Checking if $USER is in storage group..."
if ! getent group storage | grep -q $USER; then
  echo "$USER not in storage group, aborting!" && exit 1
else
  echo DONE
fi

echo -n "Checking OS version..."
REDHAT_MAJOR=$(/usr/lib/rpm/redhat/dist.sh --distnum)

if [ "$REDHAT_MAJOR" = "6" -o "$REDHAT_MAJOR" = "7" ]; then
   echo DONE
else
   echo "You are treading unknown ground with Centos $REDHAT_MAJOR! You are likely to be eaten by a grue!"
   read -p "Press forward (y/n)? " yesno
   if [ "$yesno" != "y" ]; then
     exit 1
   fi
fi

echo -n "Checking for uncommitted changes..."
UNCOMMITTED_CHANGES=$(git status -s | grep -v "??")
if [ ! -z "$UNCOMMITTED_CHANGES" ]; then
    echo "FAILED"
    echo "You have changes in your repo. Commit them or stash them before building."
    exit 1;
fi

#echo "Updating repo..."
#if ! ( git fetch && git rebase ); then
#  echo "Unable to update GIT repo, aborting!" && exit 1
#fi
#if ! BUILD_VERSION=$(grep AC_INIT.*glusterfs configure.ac | cut -d, -f2 | grep -Eo "[0-9A-Za-z._]+"); then
#  echo "Unable to find build version, aborting!" && exit 1
#fi
BUILD_VERSION=3.8.15_fb
echo "Build version is $BUILD_VERSION..."
echo "Release tag is $RELEASE_TAG..."
GIT_TAG="v$BUILD_VERSION-$RELEASE_TAG"
if [ $TAG_RELEASE -o $BUILD_FROM_TAG ]; then
    echo -n "Checking for conflicts for tag $GIT_TAG..."
    if git tag | grep -qw $GIT_TAG; then
      if ! $BUILD_FROM_TAG; then
        echo "FAILED"
        echo "Gluster release $GIT_TAG already exists, please try again, or pass -t to build from this tag!" && exit 1
      else
        if ! git checkout $GIT_TAG; then
            echo "FAILED"
            echo "Failed to checkout $GIT_TAG."
            exit 1
        fi
      fi
    fi
    echo DONE
fi
echo "Building RPMs..."
if ! ./buildrpm38.sh $RELEASE_TAG; then
  echo "Failed to build RPMs, aborting!" && exit 1
fi

if $TAG_RELEASE; then
    echo "Creating GIT tag for this build..."
    if ! git tag -a $GIT_TAG -m "GlusterFS build $GIT_TAG"; then
      echo "Unable to tag build, aborting!" && exit 1
    fi
fi

if $PUBLISH_REPO; then
  echo "Publishing RPMs..."
  if ! svnyum -y publish site-packages/${REDHAT_MAJOR}/x86_64 ~/local/rpmbuild/RPMS/x86_64/glusterfs*${GFS_VER}_fb-${RELEASE_TAG}.el${REDHAT_MAJOR}.x86_64.rpm; then
    echo "ERROR: Unable to publish RPMs!"
    echo "Removing GIT tag ($GIT_TAG) from GFS (local) git repo..."
    git tag -d $GIT_TAG && echo "Removing tag $GIT_TAG, and aborting."
    exit 1
  fi
fi

if $TAG_RELEASE; then
    echo "Pushing tag to remote repo..."
    if ! git push origin $GIT_TAG; then
      echo "Unable to push tag to repo, aborting!" && exit 1
    fi
fi

echo "Successfully released GlusterFS $GIT_TAG!"