blob: 3a5f01a844f2a82aeae8fa1bc39e8c3ab69bad84 [file] [log] [blame]
Philipp Wollermanna5afe952016-06-21 14:58:09 +00001#!/bin/bash
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +00002
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +00004#
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
Philipp Wollermanna5afe952016-06-21 14:58:09 +000017set -eu
18
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000019# Main deploy functions for the continous build system
20# Just source this file and use the various method:
21# bazel_build build bazel and run all its test
22# bazel_release use the artifact generated by bazel_build and push
23# them to github for a release and to GCS for a release candidate.
24# Also prepare an email for announcing the release.
25
26# Load common.sh
27SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
Damien Martin-Guillereze4ead962015-08-17 15:21:50 +000028source $(dirname ${SCRIPT_DIR})/release/common.sh
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000029
Kristina Chodorow2b1763a2015-09-01 09:15:54 +000030: ${GIT_REPOSITORY_URL:=https://github.com/bazelbuild/bazel}
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000031
32: ${GCS_BASE_URL:=https://storage.googleapis.com}
33: ${GCS_BUCKET:=bucket-o-bazel}
Yun Peng70b29f42016-05-24 18:04:37 +000034: ${GCS_APT_BUCKET:=bazel-apt}
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000035
36: ${EMAIL_TEMPLATE_RC:=${SCRIPT_DIR}/rc_email.txt}
37: ${EMAIL_TEMPLATE_RELEASE:=${SCRIPT_DIR}/release_email.txt}
38
39: ${RELEASE_CANDIDATE_URL:="${GCS_BASE_URL}/${GCS_BUCKET}/%release_name%/rc%rc%/index.html"}
40: ${RELEASE_URL="${GIT_REPOSITORY_URL}/releases/tag/%release_name%"}
41
Klaus Aehlig736c46d2016-11-10 16:09:34 +000042: ${BOOTSTRAP_BAZEL:=bazel}
43
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000044PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
45if [[ ${PLATFORM} == "darwin" ]]; then
46 function checksum() {
Damien Martin-Guillerezc375ea12015-09-10 09:58:44 +000047 (cd "$(dirname "$1")" && shasum -a 256 "$(basename "$1")")
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000048 }
49else
50 function checksum() {
Damien Martin-Guillerezc375ea12015-09-10 09:58:44 +000051 (cd "$(dirname "$1")" && sha256sum "$(basename "$1")")
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000052 }
53fi
54
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +000055# Returns the full release name in the form NAME(rcRC)?
56function get_full_release_name() {
57 local rc=$(get_release_candidate)
58 local name=$(get_release_name)
59 if [ -n "${rc}" ]; then
60 echo "${name}rc${rc}"
61 else
62 echo "${name}"
63 fi
64}
65
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000066function setup_android_repositories() {
67 if [ ! -f WORKSPACE.bak ] && [ -n "${ANDROID_SDK_PATH-}" ]; then
68 cp WORKSPACE WORKSPACE.bak
69 trap '[ -f WORKSPACE.bak ] && rm WORKSPACE && mv WORKSPACE.bak WORKSPACE' \
70 EXIT
Philipp Wollermann9d9657b2016-08-19 10:45:28 +000071 # Make sure that WORKSPACE ends with a newline, otherwise we'll end up with
72 # a syntax error.
73 echo >>WORKSPACE
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000074 cat >>WORKSPACE <<EOF
Lukacs Berki4e21d902015-09-07 09:59:50 +000075android_sdk_repository(
76 name = "androidsdk",
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000077 path = "${ANDROID_SDK_PATH}",
Lukacs Berki4e21d902015-09-07 09:59:50 +000078 build_tools_version = "${ANDROID_SDK_BUILD_TOOLS_VERSION:-22.0.1}",
79 api_level = ${ANDROID_SDK_API_LEVEL:-21},
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000080)
81
82bind(
83 name = "android_sdk_for_testing",
Lukacs Berki4e21d902015-09-07 09:59:50 +000084 actual = "@androidsdk//:files",
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000085)
86EOF
87 if [ -n "${ANDROID_NDK_PATH-}" ]; then
88 cat >>WORKSPACE <<EOF
Lukacs Berki4e21d902015-09-07 09:59:50 +000089android_ndk_repository(
90 name = "androidndk",
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000091 path = "${ANDROID_NDK_PATH}",
Lukacs Berki4e21d902015-09-07 09:59:50 +000092 api_level = ${ANDROID_NDK_API_LEVEL:-21},
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000093)
94
95bind(
96 name = "android_ndk_for_testing",
Lukacs Berki4e21d902015-09-07 09:59:50 +000097 actual = "@androidndk//:files",
Damien Martin-Guillerezdbf5cad2015-09-04 12:46:23 +000098)
99EOF
100 fi
101 fi
102}
Damien Martin-Guillerez9c5deb62015-09-15 07:38:26 +0000103
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000104# Main entry point for building bazel.
105# It sets the embed label to the release name if any, calls the whole
106# test suite, compile the various packages, then copy the artifacts
107# to the folder in $1
108function bazel_build() {
109 local release_label="$(get_full_release_name)"
110 local embed_label_opts=
Damien Martin-Guillerez9c5deb62015-09-15 07:38:26 +0000111
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000112 if [ -n "${release_label}" ]; then
113 export EMBED_LABEL="${release_label}"
114 fi
Damien Martin-Guillerez9c5deb62015-09-15 07:38:26 +0000115
116 if [[ "${JAVA_VERSION-}" =~ ^(1\.)?7$ ]]; then
Damien Martin-Guillerezb95995b2016-01-07 18:10:21 +0000117 JAVA_VERSION=1.7
Damien Martin-Guillerez9c5deb62015-09-15 07:38:26 +0000118 release_label="${release_label}-jdk7"
Damien Martin-Guillerezb95995b2016-01-07 18:10:21 +0000119 else
120 JAVA_VERSION=1.8
Damien Martin-Guillerez9c5deb62015-09-15 07:38:26 +0000121 fi
122
123 setup_android_repositories
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000124
125 # Build the packages
Damien Martin-Guillerez7a02e5d2016-01-11 16:47:54 +0000126 local ARGS=
127 if [[ $PLATFORM == "darwin" ]] && \
128 xcodebuild -showsdks 2> /dev/null | grep -q '\-sdk iphonesimulator'; then
129 ARGS="--define IPHONE_SDK=1"
130 fi
Klaus Aehlig736c46d2016-11-10 16:09:34 +0000131 ${BOOTSTRAP_BAZEL} --bazelrc=${BAZELRC:-/dev/null} --nomaster_bazelrc build \
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000132 --embed_label=${release_label} --stamp \
133 --workspace_status_command=scripts/ci/build_status_command.sh \
Damien Martin-Guillerezb95995b2016-01-07 18:10:21 +0000134 --define JAVA_VERSION=${JAVA_VERSION} \
Damien Martin-Guillerez7a02e5d2016-01-11 16:47:54 +0000135 ${ARGS} \
Klaus Aehlig736c46d2016-11-10 16:09:34 +0000136 //src:bazel \
Damien Martin-Guillerez1164a4f2016-05-24 18:22:22 +0000137 //site:jekyll-tree \
Yun Peng047b0e62016-07-27 12:50:15 +0000138 //scripts/packages || exit $?
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000139
Damien Martin-Guillerezf9b1c332015-09-14 16:27:14 +0000140 if [ -n "${1-}" ]; then
141 # Copy the results to the output directory
142 mkdir -p $1/packages
Klaus Aehlig736c46d2016-11-10 16:09:34 +0000143 cp bazel-bin/src/bazel $1/bazel
Damien Martin-Guillerez04d46ab2016-04-13 19:27:56 +0000144 cp bazel-bin/scripts/packages/install.sh $1/bazel-${release_label}-installer.sh
Damien Martin-Guillerez80245bc2015-10-09 14:10:42 +0000145 if [ "$PLATFORM" = "linux" ]; then
Damien Martin-Guillerez04d46ab2016-04-13 19:27:56 +0000146 cp bazel-bin/scripts/packages/bazel-debian.deb $1/bazel_${release_label}.deb
Yun Peng55e042a2016-07-26 13:36:42 +0000147 cp -f bazel-genfiles/scripts/packages/bazel.dsc $1/bazel.dsc
148 cp -f bazel-genfiles/scripts/packages/bazel.tar.gz $1/bazel.tar.gz
Klaus Aehlig034ad042016-11-11 10:53:30 +0000149 cp bazel-genfiles/bazel-distfile.zip $1/bazel-${release_label}-dist.zip
Damien Martin-Guillerez80245bc2015-10-09 14:10:42 +0000150 fi
Damien Martin-Guillerez4885eef2016-10-28 12:02:50 +0000151 cp bazel-genfiles/site/jekyll-tree.tar $1/www.bazel.build.tar
Damien Martin-Guillerezf9b1c332015-09-14 16:27:14 +0000152 cp bazel-genfiles/scripts/packages/README.md $1/README.md
153 fi
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000154}
155
156# Generate a string from a template and a list of substitutions.
157# The first parameter is the template name and each subsequent parameter
158# is taken as a couple: first is the string the substitute and the second
159# is the result of the substitution.
160function generate_from_template() {
161 local value="$1"
162 shift
163 while (( $# >= 2 )); do
164 value="${value//$1/$2}"
165 shift 2
166 done
167 echo "${value}"
168}
169
170# Generate the email for the release.
171# The first line of the output will be the recipient, the second line
172# the mail subjects and the subsequent lines the mail, its content.
173# If no planed release, then this function output will be empty.
174function generate_email() {
175 local release_name=$(get_release_name)
176 local rc=$(get_release_candidate)
177 local args=(
178 "%release_name%" "${release_name}"
179 "%rc%" "${rc}"
180 "%relnotes%" "# $(git_commit_msg)"
181 )
182 if [ -n "${rc}" ]; then
183 args+=(
184 "%url%"
185 "$(generate_from_template "${RELEASE_CANDIDATE_URL}" "${args[@]}")"
186 )
187 generate_from_template "$(cat ${EMAIL_TEMPLATE_RC})" "${args[@]}"
188 elif [ -n "${release_name}" ]; then
189 args+=(
190 "%url%"
191 "$(generate_from_template "${RELEASE_URL}" "${args[@]}")"
192 )
193 generate_from_template "$(cat ${EMAIL_TEMPLATE_RELEASE})" "${args[@]}"
194 fi
195}
196
197# Deploy a github release using a third party tool:
198# https://github.com/c4milo/github-release
199# This methods expects the following arguments:
200# $1..$n files generated by package_build (should not contains the README file)
201# Please set GITHUB_TOKEN to talk to the Github API and GITHUB_RELEASE
202# for the path to the https://github.com/c4milo/github-release tool.
203# This method is also affected by GIT_REPOSITORY_URL which should be the
Kristina Chodorow2b1763a2015-09-01 09:15:54 +0000204# URL to the github repository (defaulted to https://github.com/bazelbuild/bazel).
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000205function release_to_github() {
206 local url="${GIT_REPOSITORY_URL}"
207 local release_name=$(get_release_name)
208 local rc=$(get_release_candidate)
209 local release_tool="${GITHUB_RELEASE:-$(which github-release 2>/dev/null || true)}"
Damien Martin-Guillerezbf2e4ee2016-07-06 10:04:34 +0000210 local gpl_warning="
211
212_Notice_: Bazel installers contain binaries licensed under the GPLv2 with
213Classpath exception. Those installers should always be redistributed along with
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +0000214the source code.
215
216_Security_: All our binaries are signed with our
Klaus Aehligbaccf242016-10-28 17:37:35 +0000217[public key](https://bazel.build/bazel-release.pub.gpg) 48457EE0.
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +0000218"
Damien Martin-Guillerezbf2e4ee2016-07-06 10:04:34 +0000219
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000220 if [ ! -x "${release_tool}" ]; then
221 echo "Please set GITHUB_RELEASE to the path to the github-release binary." >&2
222 echo "This probably means you haven't installed https://github.com/c4milo/github-release " >&2
223 echo "on this machine." >&2
224 return 1
225 fi
226 local github_repo="$(echo "$url" | sed -E 's|https?://github.com/([^/]*/[^/]*).*$|\1|')"
227 if [ -n "${release_name}" ] && [ -z "${rc}" ]; then
Damien Martin-Guillerez7e6351a2015-09-09 09:45:20 +0000228 mkdir -p "${tmpdir}/to-github"
229 cp "${@}" "${tmpdir}/to-github"
Damien Martin-Guillerezbf2e4ee2016-07-06 10:04:34 +0000230 "${GITHUB_RELEASE}" "${github_repo}" "${release_name}" "" "# $(git_commit_msg) ${gpl_warning}" "${tmpdir}/to-github/"'*'
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000231 fi
232}
233
234# Creates an index of the files contained in folder $1 in mardown format
235function create_index_md() {
236 # First, add the README.md
237 local file=$1/__temp.md
238 if [ -f $1/README.md ]; then
239 cat $1/README.md
240 fi
241 # Then, add the list of files
242 echo
243 echo "## Index of files"
244 echo
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +0000245 # Security notice
246 echo "_Security_: All our binaries are signed with our"
Klaus Aehligbaccf242016-10-28 17:37:35 +0000247 echo "[public key](https://bazel.build/bazel-release.pub.gpg) 48457EE0."
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +0000248 echo
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000249 for f in $1/*.sha256; do # just list the sha256 ones
250 local filename=$(basename $f .sha256);
Damien Martin-Guillerez671045b2016-10-11 14:17:28 +0000251 echo " - [${filename}](${filename}) [[SHA-256](${filename}.sha256)] [[SIG](${filename}.sig)]"
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000252 done
253}
254
255# Creates an index of the files contained in folder $1 in HTML format
256# It supposes hoedown (https://github.com/hoedown/hoedown) is on the path,
257# if not, set the HOEDOWN environment variable to the good path.
258function create_index_html() {
259 local hoedown="${HOEDOWN:-$(which hoedown 2>/dev/null || true)}"
260 # Second line is to trick hoedown to behave as Github
261 create_index_md "${@}" \
262 | sed -E 's/^(Baseline.*)$/\1\
Damien Martin-Guillerez697c61d2015-11-24 19:19:03 +0000263/' | sed 's/^ + / - /' | sed 's/_/\\_/g' \
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000264 | "${hoedown}"
265}
266
Yun Peng70b29f42016-05-24 18:04:37 +0000267function get_gsutil() {
268 local gs="${GSUTIL:-$(which gsutil 2>/dev/null || true) -m}"
269 if [ ! -x "${gs}" ]; then
270 echo "Please set GSUTIL to the path the gsutil binary." >&2
271 echo "gsutil (https://cloud.google.com/storage/docs/gsutil/) is the" >&2
272 echo "command-line interface to google cloud." >&2
273 exit 1
274 fi
275 echo "${gs}"
276}
277
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000278# Deploy a release candidate to Google Cloud Storage.
279# It requires to have gsutil installed. You can force the path to gsutil
280# by setting the GSUTIL environment variable. The GCS_BUCKET should be the
281# name of the Google cloud bucket to deploy to.
282# This methods expects the following arguments:
283# $1..$n files generated by package_build
284function release_to_gcs() {
Yun Peng70b29f42016-05-24 18:04:37 +0000285 local gs="$(get_gsutil)"
286 local release_name="$(get_release_name)"
287 local rc="$(get_release_candidate)"
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000288 if [ -z "${GCS_BUCKET-}" ]; then
289 echo "Please set GCS_BUCKET to the name of your Google Cloud Storage bucket." >&2
290 return 1
291 fi
292 if [ -n "${release_name}" ] && [ -n "${rc}" ]; then
293 # Make a temporary folder with the desired structure
294 local dir="$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)"
295 local prev_dir="$PWD"
296 trap "{ cd ${prev_dir}; rm -fr ${dir}; }" EXIT
297 mkdir -p "${dir}/${release_name}/rc${rc}"
298 cp "${@}" "${dir}/${release_name}/rc${rc}"
299 # Add a index.html file:
300 create_index_html "${dir}/${release_name}/rc${rc}" \
301 >"${dir}/${release_name}/rc${rc}"/index.html
302 cd ${dir}
Laszlo Csomorf17fb3a2016-11-24 11:01:33 +0000303 "${gs}" cp -m -a public-read -r . "gs://${GCS_BUCKET}"
Yun Peng70b29f42016-05-24 18:04:37 +0000304 cd "${prev_dir}"
305 rm -fr "${dir}"
306 trap - EXIT
307 fi
308}
309
Yun Peng3d8ae222016-10-11 13:02:42 +0000310function ensure_gpg_secret_key_imported() {
311 (gpg --list-secret-keys | grep "${APT_GPG_KEY_ID}" > /dev/null) || \
312 gpg --allow-secret-key-import --import "${APT_GPG_KEY_PATH}"
Yun Peng2d1d4922016-11-15 13:33:47 +0000313 # Make sure we use stronger digest algorithm。
314 # We use reprepro to generate the debian repository,
315 # but there's no way to pass flags to gpg using reprepro, so writting it into
316 # ~/.gnupg/gpg.conf
317 (grep "digest-algo sha256" ~/.gnupg/gpg.conf > /dev/null) || \
318 echo "digest-algo sha256" >> ~/.gnupg/gpg.conf
Yun Peng3d8ae222016-10-11 13:02:42 +0000319}
320
Yun Peng70b29f42016-05-24 18:04:37 +0000321function create_apt_repository() {
322 mkdir conf
323 cat > conf/distributions <<EOF
324Origin: Bazel Authors
325Label: Bazel
326Codename: stable
Yun Peng55e042a2016-07-26 13:36:42 +0000327Architectures: amd64 source
Yun Peng70b29f42016-05-24 18:04:37 +0000328Components: jdk1.7 jdk1.8
329Description: Bazel APT Repository
330DebOverride: override.stable
331DscOverride: override.stable
332SignWith: ${APT_GPG_KEY_ID}
333
334Origin: Bazel Authors
335Label: Bazel
336Codename: testing
Yun Peng55e042a2016-07-26 13:36:42 +0000337Architectures: amd64 source
Yun Peng70b29f42016-05-24 18:04:37 +0000338Components: jdk1.7 jdk1.8
339Description: Bazel APT Repository
340DebOverride: override.testing
341DscOverride: override.testing
342SignWith: ${APT_GPG_KEY_ID}
343EOF
344
345 cat > conf/options <<EOF
346verbose
347ask-passphrase
348basedir .
349EOF
350
351 touch conf/override.stable
352 touch conf/override.testing
353
Yun Peng3d8ae222016-10-11 13:02:42 +0000354 ensure_gpg_secret_key_imported
Yun Peng70b29f42016-05-24 18:04:37 +0000355
356 local distribution="$1"
357 local deb_pkg_name_jdk8="$2"
358 local deb_pkg_name_jdk7="$3"
Yun Peng55e042a2016-07-26 13:36:42 +0000359 local deb_dsc_name="$4"
360
361 debsign -k ${APT_GPG_KEY_ID} "${deb_dsc_name}"
362
Yun Peng70b29f42016-05-24 18:04:37 +0000363 reprepro -C jdk1.8 includedeb "${distribution}" "${deb_pkg_name_jdk8}"
Yun Peng55e042a2016-07-26 13:36:42 +0000364 reprepro -C jdk1.8 includedsc "${distribution}" "${deb_dsc_name}"
Yun Peng70b29f42016-05-24 18:04:37 +0000365 reprepro -C jdk1.7 includedeb "${distribution}" "${deb_pkg_name_jdk7}"
Yun Peng55e042a2016-07-26 13:36:42 +0000366 reprepro -C jdk1.7 includedsc "${distribution}" "${deb_dsc_name}"
Yun Peng70b29f42016-05-24 18:04:37 +0000367
368 "${gs}" -m cp -a public-read -r dists "gs://${GCS_APT_BUCKET}/"
Yun Peng55e042a2016-07-26 13:36:42 +0000369 "${gs}" -m cp -a public-read -r pool "gs://${GCS_APT_BUCKET}/"
Yun Peng70b29f42016-05-24 18:04:37 +0000370}
371
372function release_to_apt() {
373 local gs="$(get_gsutil)"
374 local release_name="$(get_release_name)"
375 local rc="$(get_release_candidate)"
376 if [ -z "${GCS_APT_BUCKET-}" ]; then
377 echo "Please set GCS_APT_BUCKET to the name of your GCS bucket for apt repository." >&2
378 return 1
379 fi
380 if [ -z "${APT_GPG_KEY_ID-}" ]; then
381 echo "Please set APT_GPG_KEY_ID for apt repository." >&2
382 return 1
383 fi
384 if [ -n "${release_name}" ]; then
385 # Make a temporary folder with the desired structure
386 local dir="$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)"
387 local prev_dir="$PWD"
388 trap "{ cd ${prev_dir}; rm -fr ${dir}; }" EXIT
389 mkdir -p "${dir}/${release_name}"
390 local release_label="$(get_full_release_name)"
391 local deb_pkg_name_jdk8="${release_name}/bazel_${release_label}-linux-x86_64.deb"
392 local deb_pkg_name_jdk7="${release_name}/bazel_${release_label}-jdk7-linux-x86_64.deb"
Yun Peng55e042a2016-07-26 13:36:42 +0000393 local deb_dsc_name="${release_name}/bazel_$(get_release_name).dsc"
394 local deb_tar_name="${release_name}/bazel_$(get_release_name).tar.gz"
Yun Peng70b29f42016-05-24 18:04:37 +0000395 cp "${tmpdir}/bazel_${release_label}-linux-x86_64.deb" "${dir}/${deb_pkg_name_jdk8}"
396 cp "${tmpdir}/bazel_${release_label}-jdk7-linux-x86_64.deb" "${dir}/${deb_pkg_name_jdk7}"
Yun Peng55e042a2016-07-26 13:36:42 +0000397 cp "${tmpdir}/bazel.dsc" "${dir}/${deb_dsc_name}"
398 cp "${tmpdir}/bazel.tar.gz" "${dir}/${deb_tar_name}"
Yun Peng70b29f42016-05-24 18:04:37 +0000399 cd "${dir}"
400 if [ -n "${rc}" ]; then
Yun Peng55e042a2016-07-26 13:36:42 +0000401 create_apt_repository testing "${deb_pkg_name_jdk8}" "${deb_pkg_name_jdk7}" "${deb_dsc_name}"
Yun Peng70b29f42016-05-24 18:04:37 +0000402 else
Yun Peng55e042a2016-07-26 13:36:42 +0000403 create_apt_repository stable "${deb_pkg_name_jdk8}" "${deb_pkg_name_jdk7}" "${deb_dsc_name}"
Yun Peng70b29f42016-05-24 18:04:37 +0000404 fi
405 cd "${prev_dir}"
406 rm -fr "${dir}"
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000407 trap - EXIT
408 fi
409}
410
411# A wrapper around the release deployment methods.
412function deploy_release() {
413 local github_args=()
414 # Filters out README.md for github releases
415 for i in "$@"; do
Yun Peng55e042a2016-07-26 13:36:42 +0000416 if ! ( [[ "$i" =~ README.md$ ]] || [[ "$i" =~ bazel.dsc ]] || [[ "$i" =~ bazel.tar.gz ]] ) ; then
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000417 github_args+=("$i")
418 fi
419 done
420 release_to_github "${github_args[@]}"
421 release_to_gcs "$@"
Yun Peng70b29f42016-05-24 18:04:37 +0000422 release_to_apt
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000423}
424
425# A wrapper for the whole release phase:
426# Compute the SHA-256, and arrange the input
Yun Peng3d8ae222016-10-11 13:02:42 +0000427# Sign every binary using gpg and generating .sig files
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000428# Deploy the release
429# Generate the email
430# Input: $1 $2 [$3 $4 [$5 $6 ...]]
431# Each pair denotes a couple (platform, folder) where the platform
432# is the platform built for and the folder is the folder where the
433# artifacts for this platform are.
434# Ouputs:
435# RELEASE_EMAIL_RECIPIENT: who to send a mail to
436# RELEASE_EMAIL_SUBJECT: the subject of the email to be sent
437# RELEASE_EMAIL_CONTENT: the content of the email to be sent
438function bazel_release() {
439 local README=$2/README.md
Damien Martin-Guillerez7e6351a2015-09-09 09:45:20 +0000440 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000441 trap 'rm -fr ${tmpdir}' EXIT
Yun Peng3d8ae222016-10-11 13:02:42 +0000442 ensure_gpg_secret_key_imported
443
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000444 while (( $# > 1 )); do
445 local platform=$1
446 local folder=$2
447 shift 2
448 for file in $folder/*; do
Yun Peng55e042a2016-07-26 13:36:42 +0000449 local filename=$(basename $file)
450 if [ "$filename" != README.md ]; then
Klaus Aehlig279a0612016-11-11 09:51:44 +0000451 if [ "$filename" == "bazel.dsc" ] || [ "$filename" == "bazel.tar.gz" ] \
Klaus Aehlige626f742016-11-23 14:18:30 +0000452 || [[ "$filename" =~ bazel-(.*)-dist\.zip ]] ; then
Yun Peng55e042a2016-07-26 13:36:42 +0000453 local destfile=${tmpdir}/$filename
454 elif [[ "$file" =~ /([^/]*)(\.[^\./]+)$ ]]; then
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000455 local destfile=${tmpdir}/${BASH_REMATCH[1]}-${platform}${BASH_REMATCH[2]}
456 else
Yun Peng55e042a2016-07-26 13:36:42 +0000457 local destfile=${tmpdir}/$filename-${platform}
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000458 fi
Yun Peng6a3565e2016-10-26 11:54:40 +0000459 # bazel.tar.gz is duplicated under different platforms
460 # if the file is already there, skip signing and checksum it again.
461 if [ ! -f "$destfile" ]; then
462 mv $file $destfile
463 checksum $destfile > $destfile.sha256
464 gpg --no-tty --detach-sign -u "${APT_GPG_KEY_ID}" "$destfile"
465 fi
Damien Martin-Guillerezf7a39312015-08-17 08:32:09 +0000466 fi
467 done
468 done
469 deploy_release $README $(find ${tmpdir} -type f)
470
471 export RELEASE_EMAIL="$(generate_email)"
472
473 export RELEASE_EMAIL_RECIPIENT="$(echo "${RELEASE_EMAIL}" | head -1)"
474 export RELEASE_EMAIL_SUBJECT="$(echo "${RELEASE_EMAIL}" | head -2 | tail -1)"
475 export RELEASE_EMAIL_CONTENT="$(echo "${RELEASE_EMAIL}" | tail -n +3)"
476}
Damien Martin-Guillerez1164a4f2016-05-24 18:22:22 +0000477
478# Use jekyll build to build the site and then gsutil to copy it to GCS
479# Input: $1 tarball to the jekyll site
480# $2 name of the bucket to deploy the site to
481# It requires to have gsutil installed. You can force the path to gsutil
482# by setting the GSUTIL environment variable
483function build_and_publish_site() {
484 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXX)
485 trap 'rm -fr ${tmpdir}' EXIT
486 local gs="$(get_gsutil)"
487 local site="$1"
488 local bucket="$2"
489
490 if [ ! -f "${site}" ] || [ -z "${bucket}" ]; then
491 echo "Usage: build_and_publish_site <site-tarball> <bucket>" >&2
492 return 1
493 fi
494 tar xf "${site}" --exclude=CNAME -C "${tmpdir}"
495 jekyll build -s "${tmpdir}" -d "${tmpdir}/production"
Damien Martin-Guillerezd38ee632016-10-12 11:20:42 +0000496 # Rsync:
497 # -r: recursive
498 # -c: compute checksum even though the input is from the filesystem
499 "${gs}" rsync -r -c "${tmpdir}/production" "gs://${bucket}"
Damien Martin-Guillerez1164a4f2016-05-24 18:22:22 +0000500 "${gs}" web set -m index.html -e 404.html "gs://${bucket}"
501 "${gs}" -m acl ch -R -u AllUsers:R "gs://${bucket}"
502}