github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/scripts/release.sh (about)

     1  #!/bin/bash
     2  
     3  # Liferay Cloud Platform CLI Tool publishing script
     4  
     5  set -euo pipefail
     6  IFS=$'\n\t'
     7  
     8  cd $(dirname $0)/..
     9  
    10  skipIntegrationTests=false
    11  config=""
    12  
    13  function helpmenu() {
    14    echo "Liferay Cloud Platform CLI Tool publishing script:
    15  
    16  1) check if all changes are commited
    17  2) run tests on a local drone.io instance
    18  3) create and push a release tag
    19  5) build and push a new release to equinox
    20  
    21  Use ./release.sh [flags]
    22  
    23  Flags:
    24  --config: release configuration file
    25  --skip-integration-tests: skip integration tests (not recommended)"
    26    exit 1
    27  }
    28  
    29  if [ "$#" -eq 0 ] || [ $1 == "help" ]; then
    30    helpmenu
    31  fi
    32  
    33  while [ ! $# -eq 0 ]
    34  do
    35      case "$1" in
    36          --help | -h)
    37              helpmenu
    38              ;;
    39          --skip-integration-tests)
    40              skipIntegrationTests=true
    41              ;;
    42          --config)
    43              config=${2-}
    44              shift
    45              break
    46              ;;
    47      esac
    48      shift
    49  done
    50  
    51  function checkCONT() {
    52    if [[ $CONT != "y" && $CONT != "yes" ]]; then
    53      exit 1
    54    fi
    55  }
    56  
    57  function checkWorkingDir() {
    58    if [ $(git status --short | wc -l) -gt 0 ]; then
    59      echo "You have uncommited changes."
    60      git status --short
    61  
    62      echo -e "\x1B[101m\x1B[1mBy continuing you might release a build with incorrect content.\x1B[0m"
    63      read -p "Continue? [no]: " CONT < /dev/tty;
    64      checkCONT
    65    fi
    66  }
    67  
    68  function runTests() {
    69    ./scripts/static.sh
    70  
    71    echo "Running tests (may take a while)."
    72  
    73    go test $(go list ./... | grep -v /integration$) -race
    74    if [[ $skipIntegrationTests != true ]] ; then
    75      go test github.com/henvic/wedeploycli/integration
    76    fi
    77  }
    78  
    79  function runTestsOnDrone() {
    80    (which drone >> /dev/null) && ec=$? || ec=$?
    81  
    82    if [ ! $ec -eq 0 ] ; then
    83      >&2 echo "Error trying to run tests on drone."
    84      read -p "drone not found on your system: Release anyway? [no]: " CONT < /dev/tty
    85      checkCONT
    86      return
    87    fi
    88  
    89    echo "Running tests isolated on drone (docker based CI) locally."
    90    drone exec && ec=$? || ec=$?
    91  
    92    if [ $ec -eq 0 ] ; then
    93      return
    94    fi
    95  
    96    read -p "Tests on drone failed: Release anyway? [no]: " CONT < /dev/tty
    97    checkCONT
    98  }
    99  
   100  function publish() {
   101    cd cmd/lcp
   102    equinox release \
   103    --version=x \
   104    --channel=unstable \
   105    --config=$config \
   106    -- \
   107    -ldflags="-X 'github.com/henvic/wedeploycli/defaults.Version=$NEW_RELEASE_VERSION' \
   108    -X 'github.com/henvic/wedeploycli/defaults.Build=$BUILD_COMMIT' \
   109    -X 'github.com/henvic/wedeploycli/defaults.BuildTime=$BUILD_TIME'" \
   110    -gcflags=-trimpath=$GOPATH \
   111    -asmflags=-trimpath=$GOPATH \
   112    github.com/henvic/wedeploycli/cmd/lcp
   113    cd ~-
   114  }
   115  
   116  function prerelease() {
   117    checkWorkingDir
   118    runTests
   119    echo All tests and checks necessary for release passed.
   120  }
   121  
   122  function release() {
   123    read -p "Release channel [unstable]: " RELEASE_CHANNEL < /dev/tty;
   124    RELEASE_CHANNEL=${RELEASE_CHANNEL:-"unstable"}
   125  
   126    BUILD_COMMIT=$(git rev-list -n 1 HEAD)
   127    BUILD_TIME=$(date -u)
   128  
   129    echo "build commit $BUILD_COMMIT at $BUILD_TIME"
   130  
   131  #  runTestsOnDrone
   132    publish
   133  }
   134  
   135  function checkTag() {
   136    CURRENT_TAG=$(git describe --exact-match HEAD) || true
   137  
   138    if [[ $CURRENT_TAG == "" ]] ; then
   139      echo "Maybe you want to pull changes"
   140      exit 1
   141    fi
   142  
   143    read -p "Confirm release version (tag): " NEW_RELEASE_VERSION < /dev/tty;
   144    # normalize by removing leading v (i.e., v0.0.1)
   145    NEW_RELEASE_VERSION=$(echo $NEW_RELEASE_VERSION | sed 's/^v//')
   146  
   147    if [[ $CURRENT_TAG != "v$NEW_RELEASE_VERSION" ]] ; then
   148      echo "Current tag is $CURRENT_TAG, but you tried to release v$NEW_RELEASE_VERSION"
   149      exit 1
   150    fi
   151  }
   152  
   153  function run() {
   154    checkTag
   155    prerelease
   156    echo
   157    release
   158  }
   159  
   160  run