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