Philipp Wollermann | a5afe95 | 2016-06-21 14:58:09 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 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 | |
Philipp Wollermann | a5afe95 | 2016-06-21 14:58:09 +0000 | [diff] [blame] | 17 | set -eu |
| 18 | |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 19 | # 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 |
Yun Peng | 123f2b9 | 2020-02-12 04:34:00 -0800 | [diff] [blame] | 27 | BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 28 | source "$(dirname ${BUILD_SCRIPT_DIR})/release/common.sh" |
| 29 | source "$(dirname ${BUILD_SCRIPT_DIR})/release/relnotes.sh" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 30 | |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 31 | if ! command -v gsutil &>/dev/null; then |
| 32 | echo "Required tool 'gsutil' not found. Please install it:" |
| 33 | echo "See https://cloud.google.com/sdk/downloads for instructions." |
| 34 | exit 1 |
| 35 | fi |
| 36 | if ! command -v github-release &>/dev/null; then |
| 37 | echo "Required tool 'github-release' not found. Download it from here:" |
| 38 | echo "https://github.com/c4milo/github-release/releases" |
| 39 | echo "Just extract the archive and put the binary on your PATH." |
| 40 | exit 1 |
| 41 | fi |
| 42 | if ! command -v debsign &>/dev/null; then |
| 43 | echo "Required tool 'debsign' not found. Please install it via apt-get:" |
| 44 | echo "apt-get install devscripts" |
| 45 | exit 1 |
| 46 | fi |
| 47 | if ! command -v reprepro &>/dev/null; then |
| 48 | echo "Required tool 'reprepro' not found. Please install it via apt-get:" |
| 49 | echo "apt-get install reprepro" |
| 50 | exit 1 |
| 51 | fi |
| 52 | if ! command -v gpg &>/dev/null; then |
| 53 | echo "Required tool 'gpg' not found. Please install it via apt-get:" |
| 54 | echo "apt-get install gnupg" |
| 55 | exit 1 |
| 56 | fi |
| 57 | if ! command -v pandoc &>/dev/null; then |
| 58 | echo "Required tool 'pandoc' not found. Please install it via apt-get:" |
| 59 | echo "apt-get install pandoc" |
| 60 | exit 1 |
| 61 | fi |
| 62 | # if ! command -v ssmtp &>/dev/null; then |
| 63 | # echo "Required tool 'ssmtp' not found. Please install it via apt-get:" |
| 64 | # echo "apt-get install ssmtp" |
| 65 | # exit 1 |
| 66 | # fi |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 67 | |
philwo | ead5847 | 2019-05-10 08:23:25 -0700 | [diff] [blame] | 68 | export APT_GPG_KEY_ID=$(gsutil cat gs://bazel-trusted-encrypted-secrets/release-key.gpg.id) |
Klaus Aehlig | 736c46d | 2016-11-10 16:09:34 +0000 | [diff] [blame] | 69 | |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 70 | # Generate a string from a template and a list of substitutions. |
| 71 | # The first parameter is the template name and each subsequent parameter |
| 72 | # is taken as a couple: first is the string the substitute and the second |
| 73 | # is the result of the substitution. |
| 74 | function generate_from_template() { |
| 75 | local value="$1" |
| 76 | shift |
| 77 | while (( $# >= 2 )); do |
| 78 | value="${value//$1/$2}" |
| 79 | shift 2 |
| 80 | done |
| 81 | echo "${value}" |
| 82 | } |
| 83 | |
| 84 | # Generate the email for the release. |
| 85 | # The first line of the output will be the recipient, the second line |
| 86 | # the mail subjects and the subsequent lines the mail, its content. |
| 87 | # If no planed release, then this function output will be empty. |
| 88 | function generate_email() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 89 | RELEASE_CANDIDATE_URL="https://releases.bazel.build/%release_name%/rc%rc%/index.html" |
| 90 | RELEASE_URL="https://github.com/bazelbuild/bazel/releases/tag/%release_name%" |
| 91 | |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 92 | local release_name=$(get_release_name) |
| 93 | local rc=$(get_release_candidate) |
| 94 | local args=( |
| 95 | "%release_name%" "${release_name}" |
| 96 | "%rc%" "${rc}" |
Damien Martin-Guillerez | acbcbc2 | 2016-12-20 07:40:42 +0000 | [diff] [blame] | 97 | "%relnotes%" "# $(get_full_release_notes)" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 98 | ) |
| 99 | if [ -n "${rc}" ]; then |
| 100 | args+=( |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 101 | "%url%" "$(generate_from_template "${RELEASE_CANDIDATE_URL}" "${args[@]}")" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 102 | ) |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 103 | generate_from_template \ |
Yun Peng | 123f2b9 | 2020-02-12 04:34:00 -0800 | [diff] [blame] | 104 | "$(cat "${BUILD_SCRIPT_DIR}/rc_email.txt")" \ |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 105 | "${args[@]}" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 106 | elif [ -n "${release_name}" ]; then |
| 107 | args+=( |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 108 | "%url%" "$(generate_from_template "${RELEASE_URL}" "${args[@]}")" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 109 | ) |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 110 | generate_from_template \ |
Yun Peng | 123f2b9 | 2020-02-12 04:34:00 -0800 | [diff] [blame] | 111 | "$(cat "${BUILD_SCRIPT_DIR}/release_email.txt")" "${args[@]}" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 112 | fi |
| 113 | } |
| 114 | |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 115 | function get_release_page() { |
Damien Martin-Guillerez | b6e29ca | 2017-07-26 16:06:44 +0200 | [diff] [blame] | 116 | echo "# $(get_full_release_notes)"' |
Damien Martin-Guillerez | bf2e4ee | 2016-07-06 10:04:34 +0000 | [diff] [blame] | 117 | |
| 118 | _Notice_: Bazel installers contain binaries licensed under the GPLv2 with |
| 119 | Classpath exception. Those installers should always be redistributed along with |
Damien Martin-Guillerez | 671045b | 2016-10-11 14:17:28 +0000 | [diff] [blame] | 120 | the source code. |
| 121 | |
Philipp Wollermann | 9504827 | 2017-03-17 15:11:58 +0000 | [diff] [blame] | 122 | Some versions of Bazel contain a bundled version of OpenJDK. The license of the |
| 123 | bundled OpenJDK and other open-source components can be displayed by running |
| 124 | the command `bazel license`. The vendor and version information of the bundled |
| 125 | OpenJDK can be displayed by running the command `bazel info java-runtime`. |
| 126 | The binaries and source-code of the bundled OpenJDK can be |
dmarting | e17f890 | 2017-07-27 13:55:10 +0200 | [diff] [blame] | 127 | [downloaded from our mirror server](https://mirror.bazel.build/openjdk/index.html). |
Philipp Wollermann | 9504827 | 2017-03-17 15:11:58 +0000 | [diff] [blame] | 128 | |
Damien Martin-Guillerez | 671045b | 2016-10-11 14:17:28 +0000 | [diff] [blame] | 129 | _Security_: All our binaries are signed with our |
Klaus Aehlig | 552cf56 | 2019-10-11 04:20:41 -0700 | [diff] [blame] | 130 | [public key](https://bazel.build/bazel-release.pub.gpg) 3D5919B448457EE0. |
Damien Martin-Guillerez | 24795d4 | 2017-06-27 11:01:29 +0200 | [diff] [blame] | 131 | ' |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 132 | } |
Damien Martin-Guillerez | bf2e4ee | 2016-07-06 10:04:34 +0000 | [diff] [blame] | 133 | |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 134 | # Deploy a github release using a third party tool: |
| 135 | # https://github.com/c4milo/github-release |
| 136 | # This methods expects the following arguments: |
| 137 | # $1..$n files generated by package_build (should not contains the README file) |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 138 | # Please set GITHUB_TOKEN to talk to the Github API. |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 139 | function release_to_github() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 140 | local artifact_dir="$1" |
| 141 | |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 142 | local release_name=$(get_release_name) |
| 143 | local rc=$(get_release_candidate) |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 144 | |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 145 | if [ -n "${release_name}" ] && [ -z "${rc}" ]; then |
philwo | b8d0e1b | 2019-01-17 04:12:08 -0800 | [diff] [blame] | 146 | local github_token="$(gsutil cat gs://bazel-trusted-encrypted-secrets/github-trusted-token.enc | \ |
| 147 | gcloud kms decrypt --project bazel-public --location global --keyring buildkite --key github-trusted-token --ciphertext-file - --plaintext-file -)" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 148 | |
philwo | b8d0e1b | 2019-01-17 04:12:08 -0800 | [diff] [blame] | 149 | GITHUB_TOKEN="${github_token}" github-release "bazelbuild/bazel" "${release_name}" "" "$(get_release_page)" "${artifact_dir}/*" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 150 | fi |
| 151 | } |
| 152 | |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 153 | # Creates an index of the files contained in folder $1 in Markdown format. |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 154 | function create_index_md() { |
dmarting | 5e57663 | 2017-07-24 19:01:08 +0200 | [diff] [blame] | 155 | # First, add the release notes |
| 156 | get_release_page |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 157 | # Then, add the list of files |
| 158 | echo |
| 159 | echo "## Index of files" |
| 160 | echo |
| 161 | for f in $1/*.sha256; do # just list the sha256 ones |
| 162 | local filename=$(basename $f .sha256); |
Damien Martin-Guillerez | 671045b | 2016-10-11 14:17:28 +0000 | [diff] [blame] | 163 | echo " - [${filename}](${filename}) [[SHA-256](${filename}.sha256)] [[SIG](${filename}.sig)]" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 164 | done |
| 165 | } |
| 166 | |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 167 | # Creates an index of the files contained in folder $1 in HTML format. |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 168 | function create_index_html() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 169 | create_index_md "${@}" | pandoc -f markdown -t html |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 172 | # Deploy a release candidate to Google Cloud Storage. |
| 173 | # It requires to have gsutil installed. You can force the path to gsutil |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 174 | # by setting the GSUTIL environment variable. |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 175 | # This methods expects the following arguments: |
| 176 | # $1..$n files generated by package_build |
| 177 | function release_to_gcs() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 178 | local artifact_dir="$1" |
| 179 | |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 180 | local release_name="$(get_release_name)" |
| 181 | local rc="$(get_release_candidate)" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 182 | |
dmarting | ebe36f2 | 2017-03-29 12:25:01 +0000 | [diff] [blame] | 183 | if [ -n "${release_name}" ]; then |
dmarting | c58ba09 | 2017-05-04 12:38:16 +0200 | [diff] [blame] | 184 | local release_path="${release_name}/release" |
dmarting | ebe36f2 | 2017-03-29 12:25:01 +0000 | [diff] [blame] | 185 | if [ -n "${rc}" ]; then |
| 186 | release_path="${release_name}/rc${rc}" |
| 187 | fi |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 188 | create_index_html "${artifact_dir}" > "${artifact_dir}/index.html" |
philwo | 3bbf9b9d | 2019-04-17 07:05:01 -0700 | [diff] [blame] | 189 | gsutil -m cp "${artifact_dir}/**" "gs://bazel/${release_path}" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 190 | fi |
| 191 | } |
| 192 | |
Yun Peng | 3d8ae22 | 2016-10-11 13:02:42 +0000 | [diff] [blame] | 193 | function ensure_gpg_secret_key_imported() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 194 | if ! gpg --list-secret-keys | grep "${APT_GPG_KEY_ID}" > /dev/null; then |
| 195 | keyfile=$(mktemp --tmpdir) |
| 196 | chmod 0600 "${keyfile}" |
philwo | ead5847 | 2019-05-10 08:23:25 -0700 | [diff] [blame] | 197 | gsutil cat "gs://bazel-trusted-encrypted-secrets/release-key.gpg.enc" | \ |
philwo | 8ab0907 | 2018-04-25 12:57:20 -0700 | [diff] [blame] | 198 | gcloud kms decrypt --location "global" --keyring "buildkite" --key "bazel-release-key" --ciphertext-file "-" --plaintext-file "${keyfile}" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 199 | gpg --allow-secret-key-import --import "${keyfile}" |
| 200 | rm -f "${keyfile}" |
| 201 | fi |
| 202 | |
Yun Peng | 2d1d492 | 2016-11-15 13:33:47 +0000 | [diff] [blame] | 203 | # Make sure we use stronger digest algorithm。 |
| 204 | # We use reprepro to generate the debian repository, |
| 205 | # but there's no way to pass flags to gpg using reprepro, so writting it into |
| 206 | # ~/.gnupg/gpg.conf |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 207 | if ! grep "digest-algo sha256" ~/.gnupg/gpg.conf > /dev/null; then |
| 208 | echo "digest-algo sha256" >> ~/.gnupg/gpg.conf |
| 209 | fi |
Yun Peng | 3d8ae22 | 2016-10-11 13:02:42 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Yun Peng | 3162705 | 2019-11-21 04:46:11 -0800 | [diff] [blame] | 212 | # Generate new content of Release file |
| 213 | function print_new_release_content() { |
| 214 | local distribution="$1" |
| 215 | # Print the headers of the original Release file |
| 216 | cat <<EOF |
| 217 | Origin: Bazel Authors |
| 218 | Label: Bazel |
| 219 | Codename: $1 |
| 220 | Date: $(date -u "+%a, %d %b %Y %H:%M:%S UTC") |
| 221 | Architectures: amd64 |
| 222 | Components: jdk1.8 |
| 223 | Description: Bazel APT Repository |
| 224 | EOF |
| 225 | metadata_files=("jdk1.8/binary-amd64/Packages" "jdk1.8/binary-amd64/Packages.gz" "jdk1.8/binary-amd64/Release" "jdk1.8/source/Sources.gz" "jdk1.8/source/Release") |
| 226 | # Re-generate hashes for all metadata fiels |
| 227 | echo MD5Sum: |
| 228 | for file in ${metadata_files[*]}; do |
| 229 | path="dists/${distribution}/$file" |
| 230 | echo "" "$(md5sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file" |
| 231 | done |
| 232 | echo SHA1: |
| 233 | for file in ${metadata_files[*]}; do |
| 234 | path="dists/${distribution}/$file" |
| 235 | echo "" "$(sha1sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file" |
| 236 | done |
| 237 | echo SHA256: |
| 238 | for file in ${metadata_files[*]}; do |
| 239 | path="dists/${distribution}/$file" |
| 240 | echo "" "$(sha256sum ${path} | cut -d " " -f1)" "$(ls -l ${path} | cut -d " " -f5)" "$file" |
| 241 | done |
| 242 | } |
| 243 | |
| 244 | # Merge metadata with previous distribution |
| 245 | function merge_previous_dists() { |
| 246 | local distribution="$1" |
Yun Peng | db0e32c | 2019-12-02 06:13:48 -0800 | [diff] [blame] | 247 | # Download the metadata info from previous distribution |
Yun Peng | 3162705 | 2019-11-21 04:46:11 -0800 | [diff] [blame] | 248 | mkdir -p previous |
| 249 | gsutil -m cp -r "gs://bazel-apt/dists" "./previous" |
| 250 | |
| 251 | # Merge Packages and Packages.gz file |
| 252 | cat "previous/dists/${distribution}/jdk1.8/binary-amd64/Packages" >> "dists/${distribution}/jdk1.8/binary-amd64/Packages" |
| 253 | gzip -9c "dists/${distribution}/jdk1.8/binary-amd64/Packages" > "dists/${distribution}/jdk1.8/binary-amd64/Packages.gz" |
| 254 | |
| 255 | # Merge Sources.gz file |
| 256 | gunzip "previous/dists/${distribution}/jdk1.8/source/Sources.gz" |
| 257 | gunzip "dists/${distribution}/jdk1.8/source/Sources.gz" |
| 258 | cat "previous/dists/${distribution}/jdk1.8/source/Sources" >> "dists/${distribution}/jdk1.8/source/Sources" |
| 259 | gzip -9c "dists/${distribution}/jdk1.8/source/Sources" > "dists/${distribution}/jdk1.8/source/Sources.gz" |
| 260 | rm -f "dists/${distribution}/jdk1.8/source/Sources" |
| 261 | |
| 262 | # Update Release file |
| 263 | print_new_release_content "${distribution}" > "dists/${distribution}/Release.new" |
| 264 | mv "dists/${distribution}/Release.new" "dists/${distribution}/Release" |
| 265 | |
| 266 | # Generate new signatures for Release file |
Yun Peng | db0e32c | 2019-12-02 06:13:48 -0800 | [diff] [blame] | 267 | rm -f "dists/${distribution}/InRelease" "dists/${distribution}/Release.gpg" |
Yun Peng | 63f0b36 | 2020-01-28 07:18:18 -0800 | [diff] [blame] | 268 | gpg --output "dists/${distribution}/InRelease" --clearsign "dists/${distribution}/Release" |
Yun Peng | db0e32c | 2019-12-02 06:13:48 -0800 | [diff] [blame] | 269 | gpg --output "dists/${distribution}/Release.gpg" --detach-sign "dists/${distribution}/Release" |
Yun Peng | 3162705 | 2019-11-21 04:46:11 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | # Create a debian package with version in package name and add it to the repo |
| 273 | function add_versioned_deb_pkg() { |
| 274 | local distribution="$1" |
| 275 | local deb_pkg_name="$2" |
| 276 | # Extract the original package |
| 277 | mkdir -p deb-old |
| 278 | dpkg-deb -R "${deb_pkg_name}" deb-old |
| 279 | |
| 280 | # Get bazel version |
| 281 | bazel_version=$(grep "Version:" deb-old/DEBIAN/control | cut -d " " -f2) |
| 282 | bazel_version=${bazel_version/\~/} |
| 283 | |
| 284 | # Generate new control file |
| 285 | mkdir -p deb-new/DEBIAN |
| 286 | sed "s/Package:\ bazel/Package:\ bazel-${bazel_version}/g" "deb-old/DEBIAN/control" > "deb-new/DEBIAN/control" |
| 287 | |
| 288 | # Rename the actual Bazel binary to bazel-${bazel_version} |
| 289 | mkdir -p deb-new/usr/bin |
| 290 | cp "deb-old/usr/bin/bazel-real" "deb-new/usr/bin/bazel-${bazel_version}" |
| 291 | |
| 292 | # Re-pack the debian package and add it to the repo |
| 293 | versioned_deb_pkg_name="bazel-${bazel_version}-versioned-package-amd64.deb" |
| 294 | chmod -R 0755 deb-new |
| 295 | dpkg-deb -b deb-new "${versioned_deb_pkg_name}" |
| 296 | reprepro -C jdk1.8 includedeb "${distribution}" "${versioned_deb_pkg_name}" |
| 297 | } |
| 298 | |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 299 | function create_apt_repository() { |
| 300 | mkdir conf |
| 301 | cat > conf/distributions <<EOF |
| 302 | Origin: Bazel Authors |
| 303 | Label: Bazel |
| 304 | Codename: stable |
Yun Peng | 55e042a | 2016-07-26 13:36:42 +0000 | [diff] [blame] | 305 | Architectures: amd64 source |
Damien Martin-Guillerez | c616acc | 2017-06-27 10:49:01 +0200 | [diff] [blame] | 306 | Components: jdk1.8 |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 307 | Description: Bazel APT Repository |
| 308 | DebOverride: override.stable |
| 309 | DscOverride: override.stable |
| 310 | SignWith: ${APT_GPG_KEY_ID} |
| 311 | |
| 312 | Origin: Bazel Authors |
| 313 | Label: Bazel |
| 314 | Codename: testing |
Yun Peng | 55e042a | 2016-07-26 13:36:42 +0000 | [diff] [blame] | 315 | Architectures: amd64 source |
Damien Martin-Guillerez | c616acc | 2017-06-27 10:49:01 +0200 | [diff] [blame] | 316 | Components: jdk1.8 |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 317 | Description: Bazel APT Repository |
| 318 | DebOverride: override.testing |
| 319 | DscOverride: override.testing |
| 320 | SignWith: ${APT_GPG_KEY_ID} |
| 321 | EOF |
| 322 | |
| 323 | cat > conf/options <<EOF |
| 324 | verbose |
| 325 | ask-passphrase |
| 326 | basedir . |
| 327 | EOF |
| 328 | |
Damien Martin-Guillerez | 4fb378c | 2016-12-20 11:04:02 +0000 | [diff] [blame] | 329 | # TODO(#2264): this is a quick workaround #2256, figure out a correct fix. |
| 330 | cat > conf/override.stable <<EOF |
| 331 | bazel Section contrib/devel |
| 332 | bazel Priority optional |
| 333 | EOF |
| 334 | cat > conf/override.testing <<EOF |
| 335 | bazel Section contrib/devel |
| 336 | bazel Priority optional |
| 337 | EOF |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 338 | |
Yun Peng | 3d8ae22 | 2016-10-11 13:02:42 +0000 | [diff] [blame] | 339 | ensure_gpg_secret_key_imported |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 340 | |
| 341 | local distribution="$1" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 342 | local deb_pkg_name="$2" |
Damien Martin-Guillerez | c616acc | 2017-06-27 10:49:01 +0200 | [diff] [blame] | 343 | local deb_dsc_name="$3" |
Yun Peng | 55e042a | 2016-07-26 13:36:42 +0000 | [diff] [blame] | 344 | |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 345 | debsign -k "${APT_GPG_KEY_ID}" "${deb_dsc_name}" |
Yun Peng | 55e042a | 2016-07-26 13:36:42 +0000 | [diff] [blame] | 346 | |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 347 | reprepro -C jdk1.8 includedeb "${distribution}" "${deb_pkg_name}" |
Yun Peng | 55e042a | 2016-07-26 13:36:42 +0000 | [diff] [blame] | 348 | reprepro -C jdk1.8 includedsc "${distribution}" "${deb_dsc_name}" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 349 | |
Yun Peng | 3162705 | 2019-11-21 04:46:11 -0800 | [diff] [blame] | 350 | add_versioned_deb_pkg "${distribution}" "${deb_pkg_name}" |
| 351 | |
| 352 | merge_previous_dists "${distribution}" |
| 353 | |
philwo | 3bbf9b9d | 2019-04-17 07:05:01 -0700 | [diff] [blame] | 354 | gsutil -m cp -r dists pool "gs://bazel-apt" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | function release_to_apt() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 358 | local artifact_dir="$1" |
| 359 | |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 360 | local release_name="$(get_release_name)" |
| 361 | local rc="$(get_release_candidate)" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 362 | |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 363 | if [ -n "${release_name}" ]; then |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 364 | local release_label="$(get_full_release_name)" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 365 | local deb_pkg_name="${release_name}/bazel_${release_label}-linux-x86_64.deb" |
Damien Martin-Guillerez | 4fb378c | 2016-12-20 11:04:02 +0000 | [diff] [blame] | 366 | local deb_dsc_name="${release_name}/bazel_${release_label}.dsc" |
| 367 | local deb_tar_name="${release_name}/bazel_${release_label}.tar.gz" |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 368 | |
| 369 | pushd "${artifact_dir}" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 370 | if [ -n "${rc}" ]; then |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 371 | create_apt_repository testing "${deb_pkg_name}" "${deb_dsc_name}" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 372 | else |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 373 | create_apt_repository stable "${deb_pkg_name}" "${deb_dsc_name}" |
Yun Peng | 70b29f4 | 2016-05-24 18:04:37 +0000 | [diff] [blame] | 374 | fi |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 375 | popd |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 376 | fi |
| 377 | } |
| 378 | |
| 379 | # A wrapper around the release deployment methods. |
| 380 | function deploy_release() { |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 381 | local release_label="$(get_full_release_name)" |
| 382 | local release_name="$(get_release_name)" |
| 383 | |
| 384 | if [[ ! -d $1 ]]; then |
| 385 | echo "Usage: deploy_release ARTIFACT_DIR" |
| 386 | exit 1 |
| 387 | fi |
| 388 | artifact_dir="$1" |
| 389 | |
| 390 | if [[ -z $release_name ]]; then |
| 391 | echo "Could not get the release name - are you in a release branch directory?" |
| 392 | exit 1 |
| 393 | fi |
| 394 | |
| 395 | ensure_gpg_secret_key_imported |
| 396 | |
| 397 | rm -f "${artifact_dir}"/*.{sha256,sig} |
| 398 | for file in "${artifact_dir}"/*; do |
| 399 | (cd "${artifact_dir}" && sha256sum "$(basename "${file}")" > "${file}.sha256") |
| 400 | gpg --no-tty --detach-sign -u "${APT_GPG_KEY_ID}" "${file}" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 401 | done |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 402 | |
| 403 | apt_working_dir="$(mktemp -d --tmpdir)" |
| 404 | echo "apt_working_dir = ${apt_working_dir}" |
| 405 | mkdir "${apt_working_dir}/${release_name}" |
| 406 | cp "${artifact_dir}/bazel_${release_label}-linux-x86_64.deb" "${apt_working_dir}/${release_name}" |
| 407 | cp "${artifact_dir}/bazel_${release_label}.dsc" "${apt_working_dir}/${release_name}" |
| 408 | cp "${artifact_dir}/bazel_${release_label}.tar.gz" "${apt_working_dir}/${release_name}" |
| 409 | release_to_apt "${apt_working_dir}" |
| 410 | |
| 411 | gcs_working_dir="$(mktemp -d --tmpdir)" |
| 412 | echo "gcs_working_dir = ${gcs_working_dir}" |
| 413 | cp "${artifact_dir}"/* "${gcs_working_dir}" |
| 414 | release_to_gcs "${gcs_working_dir}" |
| 415 | |
| 416 | github_working_dir="$(mktemp -d --tmpdir)" |
| 417 | echo "github_working_dir = ${github_working_dir}" |
| 418 | cp "${artifact_dir}"/* "${github_working_dir}" |
philwo | 2b59370 | 2018-04-20 04:49:20 -0700 | [diff] [blame] | 419 | rm -f "${github_working_dir}/bazel_${release_label}"*.{dsc,tar.gz}{,.sha256,.sig} |
Philipp Wollermann | 5fabb43 | 2018-03-27 04:37:23 -0700 | [diff] [blame] | 420 | release_to_github "${github_working_dir}" |
Damien Martin-Guillerez | f7a3931 | 2015-08-17 08:32:09 +0000 | [diff] [blame] | 421 | } |