iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2019 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | # A script that creates java_tools release candidates or release artifacts. |
| 17 | # |
| 18 | # Before creating a release candidate the script assumes that the java_tools |
| 19 | # binaries pipeline was previously run and generated java_tools artifacts at |
| 20 | # a commit hash. |
| 21 | # |
| 22 | # The script is using gsutil to copy artifacts. |
| 23 | # |
| 24 | # Mandatory flags: |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 25 | # --java_tools_version The version number of the java_tools to be released. |
| 26 | # --rc The release candidate number of current release. |
| 27 | # If --release true then --rc is the number of the rc to |
| 28 | # be released. |
| 29 | # If --release false then --rc is the number of the rc to |
| 30 | # be created. |
| 31 | # --release "true" if the script has to create the release artifact |
| 32 | # or "false" if the script has to create a release |
| 33 | # candidate. |
| 34 | # --commit_hash The commit hash where the java_tools binaries pipeline |
| 35 | # was run. Mandatory only if --release false. |
| 36 | # |
| 37 | # Usage examples: |
| 38 | # |
| 39 | # To create the first release candidate for a new java_tools version 2.1 and |
| 40 | # JDK11, that was built at commit_hash 123456: |
| 41 | # |
| 42 | # src/create_java_tools_release.sh --commit_hash 123456 \ |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 43 | # --java_tools_version 2.1 --rc 1 --release false |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 44 | # |
| 45 | # To release the release candidate created above: |
| 46 | # |
| 47 | # src/create_java_tools_release.sh \ |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 48 | # --java_tools_version 2.1 --rc 1 --release true |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 49 | |
| 50 | set -euo pipefail |
| 51 | |
| 52 | # Parsing the flags. |
| 53 | while [[ -n "$@" ]]; do |
| 54 | arg="$1"; shift |
| 55 | val="$1"; shift |
| 56 | case "$arg" in |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 57 | "--java_tools_version") java_tools_version="$val" ;; |
| 58 | "--commit_hash") commit_hash="$val" ;; |
| 59 | "--rc") rc="$val" ;; |
| 60 | "--release") release="$val" ;; |
| 61 | *) echo "Flag $arg is not recognized." && exit 1 ;; |
| 62 | esac |
| 63 | done |
| 64 | |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 65 | # Create a tmp directory to download the artifacts from GCS and compute their |
| 66 | # sha256sum. |
Googler | b0172be | 2020-06-09 05:05:08 -0700 | [diff] [blame] | 67 | tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXXX') |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 68 | trap "rm -fr $tmp_dir" EXIT |
| 69 | |
| 70 | gcs_bucket="gs://bazel-mirror/bazel_java_tools" |
| 71 | |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 72 | for platform in "linux" "windows" "darwin"; do |
| 73 | rc_url="release_candidates/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}-rc${rc}.zip" |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 74 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 75 | if [[ $release == "true" ]]; then |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 76 | release_artifact="releases/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 77 | # Make release candidate the release artifact for the current platform. |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 78 | # Don't overwrite existing file. |
| 79 | gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 80 | else |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 81 | tmp_url=$(gsutil ls -lh ${gcs_bucket}/tmp/build/${commit_hash}/java/java_tools_${platform}* | sort -k 2 | grep gs -m 1 | awk '{print $4}') |
iirina | 0c8260b | 2019-07-24 08:35:56 -0700 | [diff] [blame] | 82 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 83 | # Make the generated artifact a release candidate for the current platform. |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 84 | # Don't overwrite existing file. |
| 85 | gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}" |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 86 | release_artifact="${rc_url}" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 87 | fi |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 88 | |
| 89 | # Download the file locally to compute its sha256sum (needed to update the |
| 90 | # java_tools in Bazel). |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 91 | # Don't overwrite existing file. |
Ivo List | 6202271 | 2020-11-27 07:24:36 -0800 | [diff] [blame] | 92 | local_zip="$tmp_dir/java_tools$platform.zip" |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 93 | gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip} |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 94 | file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1) |
| 95 | echo "${release_artifact} ${file_hash}" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 96 | done |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 97 | |
| 98 | rc_url="release_candidates/java/v${java_tools_version}/java_tools-v${java_tools_version}-rc${rc}.zip" |
| 99 | rc_sources_url="release_candidates/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}-rc${rc}.zip" |
| 100 | |
| 101 | if [[ $release == "true" ]]; then |
| 102 | release_artifact="releases/java/v${java_tools_version}/java_tools-v${java_tools_version}.zip" |
| 103 | release_sources_artifact="releases/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}.zip" |
| 104 | # Make release candidate the release artifact for the current platform. |
| 105 | # Don't overwrite existing file. |
| 106 | gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}" |
| 107 | |
| 108 | # Copy the associated zip file that contains the sources of the release zip. |
| 109 | # Don't overwrite existing file. |
| 110 | gsutil -q cp -n "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}" |
| 111 | else |
| 112 | tmp_url=$(gsutil ls -lh ${gcs_bucket}/tmp/build/${commit_hash}/java/java_tools-* | sort -k 2 | grep gs -m 1 | awk '{print $4}') |
| 113 | |
| 114 | gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}" |
| 115 | release_artifact="${rc_url}" |
| 116 | |
| 117 | # Copy the associated zip file that contains the sources of the release zip. |
| 118 | # Don't overwrite existing file. |
| 119 | tmp_sources_url=$(gsutil ls -lh ${gcs_bucket}/tmp/sources/${commit_hash}/java/java_tools-* | sort -k 2 | grep gs -m 1 | awk '{print $4}') |
| 120 | gsutil -q cp -n ${tmp_sources_url} ${gcs_bucket}/${rc_sources_url} |
| 121 | fi |
| 122 | |
| 123 | # Download the file locally to compute its sha256sum (needed to update the |
| 124 | # java_tools in Bazel). |
| 125 | # Don't overwrite existing file. |
| 126 | local_zip="$tmp_dir/java_tools.zip" |
| 127 | gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip} |
| 128 | file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1) |
| 129 | echo "${release_artifact} ${file_hash}" |
| 130 | |