github.com/getgauge/gauge@v1.6.9/build/publish_deb_to_bintray.sh (about)

     1  #!/bin/sh
     2  
     3  # ----------------------------------------------------------------
     4  #   Copyright (c) ThoughtWorks, Inc.
     5  #   Licensed under the Apache License, Version 2.0
     6  #   See LICENSE.txt in the project root for license information.
     7  # ----------------------------------------------------------------
     8  
     9  set -e
    10  
    11  if [ -z "$REPO" ]; then
    12    REPO="gauge-deb"
    13  fi
    14  
    15  if [ -z "$PACKAGE" ]; then
    16      PACKAGE="gauge"
    17  fi
    18  
    19  if [ -z "$DISTRIBUTIONS" ]; then
    20    DISTRIBUTIONS="stable"
    21  fi
    22  
    23  if [ -z "$COMPONENTS" ]; then
    24    COMPONENTS="main"
    25  fi
    26  
    27  if [ -z "$USER" ]; then
    28    echo "USER is not set"
    29    exit 1
    30  fi
    31  
    32  if [ -z "$API_KEY" ]; then
    33    echo "API_KEY is not set"
    34    exit 1
    35  fi
    36  
    37  if [ -z "$PASSPHRASE" ]; then
    38    echo "PASSPHRASE is not set"
    39    exit 1
    40  fi
    41  
    42  PACKAGE_FILE_PREFIX=$(echo "$PACKAGE" | tr '[:upper:]' '[:lower:]');
    43  
    44  setVersion () {
    45      VERSION=$(ls $PACKAGE_FILE_PREFIX*.deb | head -1 | sed "s/\.[^\.]*$//" | sed "s/$PACKAGE_FILE_PREFIX-//" | sed "s/-[a-z]*\.[a-z0-9_]*$//" | rev | sed "s/^[a-z0-9]*-//" | rev);
    46  }
    47  
    48  getArchFromFileName () {
    49      ARCH=$(echo $1 | sed "s/$PACKAGE_FILE_PREFIX-//" | rev | cut -d '-' -f 1 | rev | cut -d '.' -f 1);
    50      echo $ARCH
    51  }
    52  
    53  setUploadDirPath () {
    54      UPLOADDIRPATH="pool/$COMPONENTS/$(echo $PACKAGE | head -c1)"
    55  }
    56  
    57  bintrayUpload () {
    58      for i in `ls $PACKAGE_FILE_PREFIX*.deb`; do
    59  		ARCH=$( getArchFromFileName $i )
    60          URL="https://api.bintray.com/content/gauge/$REPO/$PACKAGE/$VERSION/$UPLOADDIRPATH/$i;deb_distribution=$DISTRIBUTIONS;deb_component=$COMPONENTS;deb_architecture=$ARCH?publish=1&override=1"
    61  
    62          echo "Uploading:"
    63          echo "\tversion: $VERSION"
    64          echo "\tarch: $ARCH"
    65          echo "\tURL: $URL"
    66  
    67          RESPONSE_CODE=$(curl -H "X-GPG-PASSPHRASE: $PASSPHRASE" -T $i -u$USER:$API_KEY $URL -I -s -w "%{http_code}" -o /dev/null);
    68          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    69              echo "Unable to upload, HTTP response code: $RESPONSE_CODE"
    70              exit 1
    71          fi
    72          echo "HTTP response code: $RESPONSE_CODE"
    73      done;
    74  }
    75  
    76  bintraySetDownloads () {
    77      for i in `ls *.deb`; do
    78          ARCH=$( getArchFromFileName $i )
    79          URL="https://api.bintray.com/file_metadata/gauge/$REPO/$UPLOADDIRPATH/$i"
    80  
    81          echo "Putting $i in $PACKAGE's download list"
    82          RESPONSE_CODE=$(curl -X PUT -d "{ \"list_in_downloads\": true }" -H "Content-Type: application/json" -u$USER:$API_KEY $URL -s -w "%{http_code}" -o /dev/null);
    83  
    84          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    85              echo "Unable to put in download list, HTTP response code: $RESPONSE_CODE"
    86              exit 1
    87          fi
    88          echo "HTTP response code: $RESPONSE_CODE"
    89      done
    90  }
    91  
    92  snooze () {
    93      echo "\nSleeping for 30 seconds. Have a coffee..."
    94      sleep 30s;
    95      echo "Done sleeping\n"
    96  }
    97  
    98  printMeta () {
    99      echo "Publishing deb: $PACKAGE"
   100      echo "Version to be uploaded: $VERSION"
   101  }
   102  
   103  setVersion
   104  printMeta
   105  setUploadDirPath
   106  bintrayUpload
   107  snooze
   108  bintraySetDownloads