github.com/pquerna/agent@v2.1.8+incompatible/scripts/utils/build-github-release.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  if [[ ${#} -lt 2 ]]
     5  then
     6    echo "Usage: ${0} [file] [version]" >&2
     7    exit 1
     8  fi
     9  
    10  function info {
    11    echo -e "\033[35m$1\033[0m"
    12  }
    13  
    14  BINARY_PATH=${1}
    15  
    16  BASE_DIRECTORY=`pwd`
    17  TEMPLATE_DIRECTORY=$BASE_DIRECTORY/templates
    18  PACKAGING_DIRECTORY=$BASE_DIRECTORY/packaging
    19  TMP_DIRECTORY=$BASE_DIRECTORY/tmp
    20  RELEASE_DIRECTORY=$BASE_DIRECTORY/releases
    21  
    22  # Make sure the template directory is there
    23  if [ ! -d "$TEMPLATE_DIRECTORY" ]; then
    24    echo "Missing templates directory."
    25    exit 1
    26  fi
    27  
    28  # Find the base name of the binary without the extension (if there is one)
    29  RELEASE_NAME=$(basename "$BINARY_PATH")
    30  RELEASE_NAME="${RELEASE_NAME%.*}-$2"
    31  
    32  # Where we will construct the release
    33  TMP_RELEASE_DIRECTORY=$TMP_DIRECTORY/$RELEASE_NAME
    34  
    35  # Ensure the tmp release directory exists
    36  rm -rf $TMP_RELEASE_DIRECTORY
    37  mkdir -p $TMP_RELEASE_DIRECTORY
    38  
    39  # We need to use .zip for windows builds
    40  if [[ "$BINARY_PATH" == *"windows"* ]]; then
    41    RELEASE_FILE_NAME="$RELEASE_NAME.zip"
    42  
    43    info "Copying binary"
    44    cp $BINARY_PATH $TMP_RELEASE_DIRECTORY/buildkite-agent.exe
    45  
    46    info "Copying templates"
    47    cp $TEMPLATE_DIRECTORY/bootstrap.bat $TMP_RELEASE_DIRECTORY
    48    cp $PACKAGING_DIRECTORY/github/windows/buildkite-agent.cfg $TMP_RELEASE_DIRECTORY
    49  
    50    info "Zipping up the files"
    51    cd $TMP_RELEASE_DIRECTORY
    52    zip -X -r "../$RELEASE_FILE_NAME" *
    53  else
    54    RELEASE_FILE_NAME="$RELEASE_NAME.tar.gz"
    55  
    56    info "Copying binary"
    57    cp $BINARY_PATH $TMP_RELEASE_DIRECTORY/buildkite-agent
    58    chmod +x $TMP_RELEASE_DIRECTORY/buildkite-agent
    59  
    60    info "Copying bootstrap"
    61    cp $TEMPLATE_DIRECTORY/bootstrap.sh $TMP_RELEASE_DIRECTORY
    62  
    63    info "Copying config"
    64    cp $PACKAGING_DIRECTORY/github/linux/buildkite-agent.cfg $TMP_RELEASE_DIRECTORY
    65  
    66    info "Copying hooks"
    67    mkdir -p $TMP_RELEASE_DIRECTORY/hooks
    68    cp $PACKAGING_DIRECTORY/github/linux/hooks/* $TMP_RELEASE_DIRECTORY/hooks
    69  
    70    info "Tarring up the files"
    71    cd $TMP_RELEASE_DIRECTORY
    72    tar cfvz ../$RELEASE_FILE_NAME .
    73  fi
    74  
    75  mkdir -p $RELEASE_DIRECTORY
    76  mv $TMP_DIRECTORY/$RELEASE_FILE_NAME $RELEASE_DIRECTORY/
    77  
    78  echo -e "👏 Created release \033[33m$RELEASE_DIRECTORY/$RELEASE_FILE_NAME\033[0m"