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: |
| 25 | # --java_version The JDK version included in the java_tools to be |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 26 | # released. |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 27 | # --java_tools_version The version number of the java_tools to be released. |
| 28 | # --rc The release candidate number of current release. |
| 29 | # If --release true then --rc is the number of the rc to |
| 30 | # be released. |
| 31 | # If --release false then --rc is the number of the rc to |
| 32 | # be created. |
| 33 | # --release "true" if the script has to create the release artifact |
| 34 | # or "false" if the script has to create a release |
| 35 | # candidate. |
| 36 | # --commit_hash The commit hash where the java_tools binaries pipeline |
| 37 | # was run. Mandatory only if --release false. |
| 38 | # |
| 39 | # Usage examples: |
| 40 | # |
| 41 | # To create the first release candidate for a new java_tools version 2.1 and |
| 42 | # JDK11, that was built at commit_hash 123456: |
| 43 | # |
| 44 | # src/create_java_tools_release.sh --commit_hash 123456 \ |
| 45 | # --java_tools_version 2.1 --java_version 11 --rc 1 --release false |
| 46 | # |
| 47 | # To release the release candidate created above: |
| 48 | # |
| 49 | # src/create_java_tools_release.sh \ |
| 50 | # --java_tools_version 2.1 --java_version 11 --rc 1 --release true |
| 51 | |
| 52 | set -euo pipefail |
| 53 | |
| 54 | # Parsing the flags. |
| 55 | while [[ -n "$@" ]]; do |
| 56 | arg="$1"; shift |
| 57 | val="$1"; shift |
| 58 | case "$arg" in |
| 59 | "--java_version") java_version="$val" ;; |
| 60 | "--java_tools_version") java_tools_version="$val" ;; |
| 61 | "--commit_hash") commit_hash="$val" ;; |
| 62 | "--rc") rc="$val" ;; |
| 63 | "--release") release="$val" ;; |
| 64 | *) echo "Flag $arg is not recognized." && exit 1 ;; |
| 65 | esac |
| 66 | done |
| 67 | |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 68 | # Create a tmp directory to download the artifacts from GCS and compute their |
| 69 | # sha256sum. |
| 70 | tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXX') |
| 71 | trap "rm -fr $tmp_dir" EXIT |
| 72 | |
| 73 | gcs_bucket="gs://bazel-mirror/bazel_java_tools" |
| 74 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 75 | for platform in linux windows darwin; do |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 76 | rc_url="release_candidates/javac${java_version}/v${java_tools_version}/java_tools_javac${java_version}_${platform}-v${java_tools_version}-rc${rc}.zip" |
iirina | 894c248 | 2019-05-16 05:41:12 -0700 | [diff] [blame] | 77 | rc_sources_url="release_candidates/javac${java_version}/v${java_tools_version}/sources/java_tools_javac${java_version}_${platform}-v${java_tools_version}-rc${rc}.zip" |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 78 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 79 | if [[ $release == "true" ]]; then |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 80 | release_artifact="releases/javac${java_version}/v${java_tools_version}/java_tools_javac${java_version}_${platform}-v${java_tools_version}.zip" |
iirina | 894c248 | 2019-05-16 05:41:12 -0700 | [diff] [blame] | 81 | release_sources_artifact="releases/javac${java_version}/v${java_tools_version}/sources/java_tools_javac${java_version}_${platform}-v${java_tools_version}.zip" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 82 | # Make release candidate the release artifact for the current platform. |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 83 | gsutil -q cp "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}" |
iirina | 894c248 | 2019-05-16 05:41:12 -0700 | [diff] [blame] | 84 | |
| 85 | # Copy the associated zip file that contains the sources of the release zip. |
| 86 | gsutil -q cp "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 87 | else |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 88 | tmp_url=$(gsutil ls -lh ${gcs_bucket}/tmp/build/${commit_hash}/java${java_version}/java_tools_javac${java_version}_${platform}* | sort -k 2 | grep "gs" | cut -d " " -f 7) |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 89 | # Make the generated artifact a release candidate for the current platform. |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 90 | gsutil -q cp ${tmp_url} "${gcs_bucket}/${rc_url}" |
| 91 | release_artifact="${rc_url}" |
iirina | 894c248 | 2019-05-16 05:41:12 -0700 | [diff] [blame] | 92 | |
| 93 | # Copy the associated zip file that contains the sources of the release zip. |
| 94 | tmp_sources_url=$(gsutil ls -lh ${gcs_bucket}/tmp/sources/${commit_hash}/java${java_version}/java_tools_javac${java_version}_${platform}* | sort -k 2 | grep "gs" | cut -d " " -f 7) |
| 95 | gsutil -q cp ${tmp_sources_url} ${gcs_bucket}/${rc_sources_url} |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 96 | fi |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 97 | |
| 98 | # Download the file locally to compute its sha256sum (needed to update the |
| 99 | # java_tools in Bazel). |
| 100 | local_zip="$tmp_dir/java_tools_$platform.zip" |
| 101 | gsutil -q cp ${gcs_bucket}/${rc_url} ${local_zip} |
| 102 | file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1) |
| 103 | echo "${release_artifact} ${file_hash}" |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 104 | done |