gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/tools/make_release.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2018 The gVisor Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #   http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  if [[ "$#" -le 2 ]]; then
    18    echo "usage: $0 <private-key> <root> <binaries & packages...>"
    19    echo "The environment variable NIGHTLY may be set to control"
    20    echo "whether the nightly packages are produced or not."
    21    exit 1
    22  fi
    23  
    24  set -xeo pipefail
    25  declare -r private_key="$1"
    26  shift
    27  declare -r root="$1"
    28  shift
    29  declare -a binaries
    30  declare -a pkgs
    31  
    32  # Collect binaries & packages.
    33  for arg in "$@"; do
    34    if [[ "${arg}" == *.deb ]] || [[ "${arg}" == *.changes ]]; then
    35      pkgs+=("${arg}")
    36    else
    37      binaries+=("${arg}")
    38    fi
    39  done
    40  
    41  export DEBIAN_FRONTEND=noninteractive
    42  # install_raw installs raw artifacts.
    43  install_raw() {
    44    for binary in "${binaries[@]}"; do
    45      local arch name
    46      # Copy the raw file & generate a sha512sum, sorted by architecture.
    47      arch=$(file "${binary}" | cut -d',' -f2 | awk '{print $NF}' | tr '-' '_')
    48      name=$(basename "${binary}")
    49      mkdir -p "${root}/$1/${arch}"
    50      cp -f "${binary}" "${root}/$1/${arch}"
    51      (cd "${root}/$1/${arch}" && sha512sum "${name}" >"${name}.sha512")
    52    done
    53  }
    54  
    55  # install_apt installs an apt repository.
    56  install_apt() {
    57    tools/make_apt.sh "${private_key}" "$1" "${root}" "${pkgs[@]}"
    58  }
    59  
    60  # If nightly, install only nightly artifacts.
    61  if [[ "${NIGHTLY:-false}" == "true" ]]; then
    62    # Install the nightly release.
    63    # https://gvisor.dev/docs/user_guide/install/#nightly
    64    stamp="$(date -Idate)"
    65    install_raw "nightly/latest"
    66    install_raw "nightly/${stamp}"
    67    install_apt "nightly"
    68  else
    69    # Is it a tagged release? Build that.
    70    tags="$(git tag --points-at HEAD 2>/dev/null || true)"
    71    if ! [[ -z "${tags}" ]]; then
    72      # Note that a given commit can match any number of tags. We have to iterate
    73      # through all possible tags and produce associated artifacts.
    74      for tag in ${tags}; do
    75        # LINT.IfChange
    76        if [[ "$tag" == "buildkite-test-branch" ]]; then
    77          continue
    78        fi
    79        # LINT.ThenChange(../.buildkite/hooks/pre-command)
    80        name=$(echo "${tag}" | cut -d'-' -f2)
    81        base=$(echo "${name}" | cut -d'.' -f1)
    82        # Install the "specific" release. This is the latest release with the
    83        # given date.
    84        # https://gvisor.dev/docs/user_guide/install/#specific-release
    85        install_raw "release/${base}"
    86        # Install the "point release".
    87        # https://gvisor.dev/docs/user_guide/install/#point-release
    88        install_raw "release/${name}"
    89        # Install the latest release.
    90        # https://gvisor.dev/docs/user_guide/install/#latest-release
    91        install_raw "release/latest"
    92  
    93        install_apt "release"
    94        install_apt "${base}"
    95      done
    96    else
    97      # Otherwise, assume it is a raw master commit.
    98      # https://gvisor.dev/docs/user_guide/install/#head
    99      install_raw "master/latest"
   100      install_apt "master"
   101    fi
   102  fi