github.com/hernad/nomad@v1.6.112/scripts/dist.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright (c) HashiCorp, Inc.
     3  # SPDX-License-Identifier: MPL-2.0
     4  
     5  set -e
     6  
     7  # Get the version from the command line
     8  VERSION=$1
     9  if [ -z "${VERSION}" ]; then
    10    echo "Please specify a version. (format: 0.4.0-rc1)"
    11    exit 1
    12  fi
    13  
    14  gpg_signing_key=348FFC4C
    15  
    16  verify_hc_releases() {
    17      if ! command -v  hc-releases 2>/dev/null >/dev/null
    18      then
    19          echo "hc-releases binary is not present" >&2
    20          exit 1
    21      fi
    22  }
    23  
    24  verify_gpg_key() {
    25      if ! gpg --list-keys "${gpg_signing_key}" >/dev/null 2>/dev/null
    26      then
    27          echo "gpg key ${gpg_signing_key} is not present" >&2
    28          exit 1
    29      fi
    30  }
    31  
    32  verify_s3_access() {
    33      if ! aws s3 ls s3://hc-releases/ >/dev/null 2>/dev/null
    34      then
    35          echo "AWS credentials is not configured" >&2
    36          exit 1
    37      fi
    38  }
    39  
    40  if [ -z "${NO_PREFLIGHT}" ]; then
    41      verify_hc_releases
    42      verify_gpg_key
    43      verify_s3_access
    44  fi
    45  
    46  # Get the parent directory of where this script is.
    47  SOURCE="${BASH_SOURCE[0]}"
    48  while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
    49  DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
    50  
    51  # Change into that dir because we expect that
    52  cd "${DIR}"
    53  
    54  # Generate the tag.
    55  if [ -z "${NOTAG}" ]; then
    56    echo "==> Tagging..."
    57    git commit --allow-empty -a --gpg-sign=${gpg_signing_key} -m "Release v$VERSION"
    58    git tag -a -m "Version $VERSION" -s -u ${gpg_signing_key} "v${VERSION}" HEAD
    59  fi
    60  
    61  # Zip all the files
    62  rm -rf ./pkg/dist
    63  mkdir -p ./pkg/dist
    64  
    65  #find ./pkg -mindepth 1 -maxdepth 1 -type f -exec cp ./pkg/{} ./pkg/dist/nomad_"${VERSION}"_{} \;
    66  #for FILENAME in $(find ./pkg -mindepth 1 -maxdepth 1 -type f); do
    67  find ./pkg -mindepth 1 -maxdepth 1 -type f -print0 | while read -d '' -r FILENAME; do
    68    FILENAME=$(basename "$FILENAME")
    69    cp "./pkg/${FILENAME}" "./pkg/dist/nomad_${VERSION}_${FILENAME}"
    70  done
    71  
    72  # Make the checksums
    73  pushd ./pkg/dist
    74  shasum -a256 ./* > "./nomad_${VERSION}_SHA256SUMS"
    75  if [ -z "${NOSIGN}" ]; then
    76    echo "==> Signing..."
    77    gpg --default-key 348FFC4C --detach-sig "./nomad_${VERSION}_SHA256SUMS"
    78  fi
    79  popd
    80  
    81  # Upload
    82  if [ -z "${HC_RELEASE}" ]; then
    83    hc-releases upload "${DIR}/pkg/dist" && hc-releases publish
    84  fi