release.sh 11.4 KB
Newer Older
1
#! /usr/bin/env bash
2 3 4

set -euo pipefail

5 6 7 8 9
if [ "$1" != "package" ]; then
  if (grep -r KJ_DBG c++/src | egrep -v '/debug(-test)?[.]' | grep -v 'See KJ_DBG\.$'); then
    echo '*** Error:  There are instances of KJ_DBG in the code.' >&2
    exit 1
  fi
10

11 12 13 14
  if (egrep -r 'TODO\((now|soon)\)' *); then
    echo '*** Error:  There are release-blocking TODOs in the code.' >&2
    exit 1
  fi
15 16
fi

17 18
doit() {
  echo "@@@@ $@"
Kenton Varda's avatar
Kenton Varda committed
19
  "$@"
Kenton Varda's avatar
Kenton Varda committed
20 21 22
}

get_version() {
Kenton Varda's avatar
Kenton Varda committed
23
  local VERSION=$(grep '^AC_INIT' c++/configure.ac | sed -e 's/^[^]]*],\[\([^]]*\)].*$/\1/g')
Kenton Varda's avatar
Kenton Varda committed
24 25 26 27 28 29 30 31
  if [[ ! "$VERSION" =~ $1 ]]; then
    echo "Couldn't parse version: $VERSION" >&2
    exit 1
  fi
  echo "$VERSION"
}

get_release_version() {
32
  get_version '^[0-9]+[.][0-9]+[.][0-9]+(-rc[0-9]+|[.][0-9]+)?$'
Kenton Varda's avatar
Kenton Varda committed
33 34 35 36 37 38 39 40
}

update_version() {
  local OLD=$1
  local NEW=$2
  local BRANCH_DESC=$3

  local OLD_REGEX=${OLD//./[.]}
41
  doit sed -i -e "s/$OLD_REGEX/$NEW/g" c++/configure.ac
42
  doit sed -i -e "s/set(VERSION.*)/set(VERSION $NEW)/g" c++/CMakeLists.txt
43 44 45 46 47 48 49 50 51

  local NEW_NOTAG=${NEW%%-*}
  declare -a NEW_ARR=(${NEW_NOTAG//./ })
  doit sed -i -re "
      s/^#define CAPNP_VERSION_MAJOR [0-9]+\$/#define CAPNP_VERSION_MAJOR ${NEW_ARR[0]}/g;
      s/^#define CAPNP_VERSION_MINOR [0-9]+\$/#define CAPNP_VERSION_MINOR ${NEW_ARR[1]}/g;
      s/^#define CAPNP_VERSION_MICRO [0-9]+\$/#define CAPNP_VERSION_MICRO ${NEW_ARR[2]:-0}/g" \
      c++/src/capnp/common.h

52 53
  local NEW_COMBINED=$(( ${NEW_ARR[0]} * 1000000 + ${NEW_ARR[1]} * 1000 + ${NEW_ARR[2]:-0 }))
  doit sed -i -re "s/^#if CAPNP_VERSION != [0-9]*\$/#if CAPNP_VERSION != $NEW_COMBINED/g" \
Kenton Varda's avatar
Kenton Varda committed
54
      c++/src/*/*.capnp.h c++/src/*/*/*.capnp.h
55

Kenton Varda's avatar
Kenton Varda committed
56 57 58 59 60 61 62 63
  doit git commit -a -m "Set $BRANCH_DESC version to $NEW."
}

build_packages() {
  local VERSION=$1
  local VERSION_BASE=${VERSION%%-*}

  echo "========================================================================="
64
  echo "Building C++ package..."
Kenton Varda's avatar
Kenton Varda committed
65
  echo "========================================================================="
66 67

  # make dist tarball and move into ..
Kenton Varda's avatar
Kenton Varda committed
68 69 70
  cd c++
  doit autoreconf -i
  doit ./configure
71
  doit make -j6 distcheck
Kenton Varda's avatar
Kenton Varda committed
72
  doit mv capnproto-c++-$VERSION.tar.gz ..
73
  doit make distclean
74 75

  # build windows executables
76 77 78
  doit ./configure --host=i686-w64-mingw32 --with-external-capnp \
      --disable-shared CXXFLAGS='-static-libgcc -static-libstdc++'
  doit make -j6 capnp.exe capnpc-c++.exe capnpc-capnp.exe
79
  doit i686-w64-mingw32-strip capnp.exe capnpc-c++.exe capnpc-capnp.exe
80 81
  doit mkdir capnproto-tools-win32-$VERSION
  doit mv capnp.exe capnpc-c++.exe capnpc-capnp.exe capnproto-tools-win32-$VERSION
Kenton Varda's avatar
Kenton Varda committed
82
  doit make maintainer-clean
83 84 85 86 87 88 89

  # repack dist tarball and win32 tools into win32 zip, with DOS line endings
  doit tar zxf ../capnproto-c++-$VERSION.tar.gz
  find capnproto-c++-$VERSION -name '*.c++' -o -name '*.h' -o -name '*.capnp' -o -name '*.md' -o -name '*.txt' | grep -v testdata | doit xargs unix2dos
  doit zip -r ../capnproto-c++-win32-$VERSION.zip capnproto-c++-$VERSION capnproto-tools-win32-$VERSION

  rm -rf capnproto-c++-$VERSION capnproto-tools-win32-$VERSION
Kenton Varda's avatar
Kenton Varda committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  cd ..
}

cherry_pick() {
  shift
  if [ $# -gt 0 ]; then
    echo "========================================================================="
    echo "Cherry-picking fixes"
    echo "========================================================================="
    doit git cherry-pick "$@"
  fi
}

done_banner() {
  local VERSION=$1
  local PUSH=$2
106
  local FINAL=$3
Kenton Varda's avatar
Kenton Varda committed
107 108 109 110 111
  echo "========================================================================="
  echo "Done"
  echo "========================================================================="
  echo "Ready to release:"
  echo "  capnproto-c++-$VERSION.tar.gz"
112
  echo "  capnproto-c++-win32-$VERSION.zip"
Kenton Varda's avatar
Kenton Varda committed
113 114
  echo "Don't forget to push changes:"
  echo "  git push origin $PUSH"
115

116
  read -s -n 1 -p "Shall I push to git and upload to capnproto.org now? (y/N)" YESNO
117 118 119 120 121

  echo
  case "$YESNO" in
    y | Y )
      doit git push origin $PUSH
122 123
      doit gce-ss copy-files capnproto-c++-$VERSION.tar.gz capnproto-c++-win32-$VERSION.zip \
          fe:/var/www/capnproto.org
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

      if [ "$FINAL" = yes ]; then
        echo "========================================================================="
        echo "Publishing docs"
        echo "========================================================================="
        cd doc
        doit ./push-site.sh
        cd ..
        echo "========================================================================="
        echo "Really done"
        echo "========================================================================="
      fi

      echo "Release is available at:"
      echo "  http://capnproto.org/capnproto-c++-$VERSION.tar.gz"
      ;;
    * )
      echo "OK, do it yourself then."
      ;;
  esac
144 145 146 147
}

BRANCH=$(git rev-parse --abbrev-ref HEAD)

Kenton Varda's avatar
Kenton Varda committed
148 149 150 151 152 153 154
case "${1-}:$BRANCH" in
  # ======================================================================================
  candidate:master )
    echo "New major release."

    if [ $# -gt 1 ]; then
      echo "Cannot cherry-pick when starting from master.  Do it yourself." >&2
155 156 157
      exit 1
    fi

Kenton Varda's avatar
Kenton Varda committed
158 159
    HEAD_VERSION=$(get_version '^[0-9]+[.][0-9]+-dev$')
    RELEASE_VERSION=${HEAD_VERSION%%-dev}.0
160

Kenton Varda's avatar
Kenton Varda committed
161
    echo "Version: $RELEASE_VERSION"
162 163 164 165

    echo "========================================================================="
    echo "Creating release branch..."
    echo "========================================================================="
Kenton Varda's avatar
Kenton Varda committed
166
    doit git checkout -b release-$RELEASE_VERSION
167

Kenton Varda's avatar
Kenton Varda committed
168
    update_version $HEAD_VERSION $RELEASE_VERSION-rc1 "release branch"
169

Kenton Varda's avatar
Kenton Varda committed
170
    build_packages $RELEASE_VERSION-rc1
171 172 173 174

    echo "========================================================================="
    echo "Updating version in master branch..."
    echo "========================================================================="
Kenton Varda's avatar
Kenton Varda committed
175

176
    doit git checkout master
Kenton Varda's avatar
Kenton Varda committed
177
    declare -a VERSION_ARR=(${RELEASE_VERSION//./ })
178
    NEXT_VERSION=${VERSION_ARR[0]}.$((VERSION_ARR[1] + 1))
Kenton Varda's avatar
Kenton Varda committed
179 180 181

    update_version $HEAD_VERSION $NEXT_VERSION-dev "mainlaine"

182
    done_banner $RELEASE_VERSION-rc1 "master release-$RELEASE_VERSION" no
Kenton Varda's avatar
Kenton Varda committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    ;;

  # ======================================================================================
  candidate:release-* )
    echo "New release candidate."
    OLD_VERSION=$(get_release_version)

    if [[ $OLD_VERSION == *-rc* ]]; then
      # New release candidate for existing release.

      RC=${OLD_VERSION##*-rc}
      BRANCH_VERSION=${OLD_VERSION%%-rc*}
      RC_VERSION=$BRANCH_VERSION-rc$(( RC + 1 ))

      echo "Version: $RC_VERSION"
    else
      # New micro release.

      declare -a VERSION_ARR=(${OLD_VERSION//./ })
      BRANCH_VERSION=${VERSION_ARR[0]}.${VERSION_ARR[1]}.$((VERSION_ARR[2] + 1))

      RC_VERSION=$BRANCH_VERSION-rc1
      echo "Version: $RC_VERSION"

      echo "========================================================================="
      echo "Creating new release branch..."
      echo "========================================================================="

      doit git checkout -b release-$BRANCH_VERSION
    fi
213 214

    echo "========================================================================="
Kenton Varda's avatar
Kenton Varda committed
215
    echo "Updating version number to $RC_VERSION..."
216
    echo "========================================================================="
Kenton Varda's avatar
Kenton Varda committed
217 218 219 220 221 222 223

    update_version $OLD_VERSION $RC_VERSION "release branch"

    cherry_pick "$@"

    build_packages $RC_VERSION

224
    done_banner $RC_VERSION release-$BRANCH_VERSION no
225 226
    ;;

Kenton Varda's avatar
Kenton Varda committed
227 228 229 230 231 232 233
  # ======================================================================================
  final:release-* )
    echo "Final release."
    OLD_VERSION=$(get_release_version)

    if [[ $OLD_VERSION != *-rc* ]]; then
      echo "Current version is already a final release.  You need to create a new candidate first." >&2
234
      exit 1
Kenton Varda's avatar
Kenton Varda committed
235 236 237 238
    fi

    if [ $# -gt 1 ]; then
      echo "Cannot cherry-pick into final release.  Make another candidate." >&2
239
      exit 1
Kenton Varda's avatar
Kenton Varda committed
240 241 242 243 244 245 246 247 248 249 250
    fi

    RC=${OLD_VERSION##*-rc}
    NEW_VERSION=${OLD_VERSION%%-rc*}

    echo "Version: $NEW_VERSION"

    echo "========================================================================="
    echo "Updating version number to $NEW_VERSION..."
    echo "========================================================================="

251 252 253
    doit sed -i -re "s/capnproto-c[+][+]-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-c++-$NEW_VERSION/g" doc/install.md
    doit sed -i -re "s/capnproto-c[+][+]-win32-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-c++-win32-$NEW_VERSION/g" doc/install.md
    doit sed -i -re "s/capnproto-tools-win32-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-tools-win32-$NEW_VERSION/g" doc/install.md
Kenton Varda's avatar
Kenton Varda committed
254 255
    update_version $OLD_VERSION $NEW_VERSION "release branch"

256 257
    doit git tag v$NEW_VERSION

Kenton Varda's avatar
Kenton Varda committed
258 259
    build_packages $NEW_VERSION

260
    done_banner $NEW_VERSION "v$NEW_VERSION release-$NEW_VERSION" yes
Kenton Varda's avatar
Kenton Varda committed
261 262
    ;;

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
  # ======================================================================================
  security:release-* )
    echo "Security release."
    OLD_VERSION=$(get_release_version)

    if [[ $OLD_VERSION == *-rc* ]]; then
      echo "Security releases don't have candidates." >&2
      exit 1
    fi

    declare -a VERSION_ARR=(${OLD_VERSION//./ } 0)
    NEW_VERSION=${VERSION_ARR[0]}.${VERSION_ARR[1]}.${VERSION_ARR[2]}.$((VERSION_ARR[3] + 1))

    echo "Version: $NEW_VERSION"

    echo "========================================================================="
    echo "Updating version number to $NEW_VERSION..."
    echo "========================================================================="

    doit sed -i -re "s/capnproto-c[+][+]-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-c++-$NEW_VERSION/g" doc/install.md
    doit sed -i -re "s/capnproto-c[+][+]-win32-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-c++-win32-$NEW_VERSION/g" doc/install.md
    doit sed -i -re "s/capnproto-tools-win32-[0-9]+[.][0-9]+[.][0-9]+([.][0-9]+)?\>/capnproto-tools-win32-$NEW_VERSION/g" doc/install.md
    update_version $OLD_VERSION $NEW_VERSION "release branch"

    cherry_pick "$@"

    doit git tag v$NEW_VERSION

    build_packages $NEW_VERSION

    done_banner $NEW_VERSION "v$NEW_VERSION release-$NEW_VERSION" yes
    ;;

Kenton Varda's avatar
Kenton Varda committed
296 297 298 299 300 301 302 303 304
  # ======================================================================================
  retry:release-* )
    echo "Retrying release."
    OLD_VERSION=$(get_release_version)
    echo "Version: $OLD_VERSION"

    if [[ $OLD_VERSION == *-rc* ]]; then
      # We can add more cherry-picks when retrying a candidate.
      cherry_pick "$@"
305
    else
Kenton Varda's avatar
Kenton Varda committed
306 307 308 309
      if [ $# -gt 1 ]; then
        echo "Cannot cherry-pick into final release.  Make another candidate." >&2
        exit 1
      fi
310
    fi
Kenton Varda's avatar
Kenton Varda committed
311 312 313

    OLD_VERSION=$(get_release_version)
    build_packages $OLD_VERSION
314 315 316 317 318 319 320 321

    if [[ $OLD_VERSION == *-rc* ]]; then
      BRANCH_VERSION=${OLD_VERSION%%-rc*}
      done_banner $OLD_VERSION release-$BRANCH_VERSION no
    else
      doit git tag v$OLD_VERSION
      done_banner $OLD_VERSION "v$OLD_VERSION release-$OLD_VERSION" no
    fi
Kenton Varda's avatar
Kenton Varda committed
322 323
    ;;

324 325 326 327 328 329
  # ======================================================================================
  package:* )
    echo "Just building a package."
    build_packages $(get_version '.*')
    ;;

Kenton Varda's avatar
Kenton Varda committed
330 331 332 333 334 335 336 337 338
  # ======================================================================================
  *:master )
    echo "Invalid command for mainline branch.  Only command is 'candidate'." >&2
    exit 1
    ;;

  *:release-* )
    echo "Invalid command for release branch.  Commands are 'candidate', 'final', and 'retry'." >&2
    exit 1
339 340 341 342 343
    ;;

  * )
    echo "Not a master or release branch." >&2
    exit 1
Kenton Varda's avatar
Kenton Varda committed
344
    ;;
345
esac