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" |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 71 | mirror_prefix="https://mirror.bazel.build/bazel_java_tools" |
| 72 | github_prefix="https://github.com/bazelbuild/java_tools/releases/download" |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 73 | |
hvd | 3b475b3 | 2023-03-16 07:28:55 -0700 | [diff] [blame] | 74 | for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 75 | 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] | 76 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 77 | if [[ $release == "true" ]]; then |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 78 | 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] | 79 | # Make release candidate the release artifact for the current platform. |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 80 | # Don't overwrite existing file. |
| 81 | gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}" |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 82 | |
| 83 | github_url="${github_prefix}/java_v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip" |
| 84 | mirror_url=${mirror_prefix}/${release_artifact} |
| 85 | urls='"mirror_url" : "'${mirror_url}'", "github_url" : "'${github_url}'"' |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 86 | else |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 87 | 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] | 88 | |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 89 | # Make the generated artifact a release candidate for the current platform. |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 90 | # Don't overwrite existing file. |
| 91 | gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}" |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 92 | |
| 93 | mirror_url=${mirror_prefix}/${rc_url} |
| 94 | urls='"mirror_url" : "'${mirror_url}'"' |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 95 | fi |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 96 | |
| 97 | # Download the file locally to compute its sha256sum (needed to update the |
| 98 | # java_tools in Bazel). |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 99 | # Don't overwrite existing file. |
Ivo List | 6202271 | 2020-11-27 07:24:36 -0800 | [diff] [blame] | 100 | local_zip="$tmp_dir/java_tools$platform.zip" |
Irina Iancu | 82ca346 | 2019-10-15 04:23:53 -0700 | [diff] [blame] | 101 | gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip} |
iirina | 24ce2d9 | 2019-05-15 05:38:07 -0700 | [diff] [blame] | 102 | file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1) |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 103 | |
| 104 | platform_output+='"java_tools_'${platform}'" : {'${urls}', "sha": "'${file_hash}'"},' |
iirina | 87ea120 | 2019-05-15 03:00:08 -0700 | [diff] [blame] | 105 | done |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 106 | |
| 107 | rc_url="release_candidates/java/v${java_tools_version}/java_tools-v${java_tools_version}-rc${rc}.zip" |
| 108 | rc_sources_url="release_candidates/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}-rc${rc}.zip" |
| 109 | |
| 110 | if [[ $release == "true" ]]; then |
| 111 | release_artifact="releases/java/v${java_tools_version}/java_tools-v${java_tools_version}.zip" |
| 112 | release_sources_artifact="releases/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}.zip" |
| 113 | # Make release candidate the release artifact for the current platform. |
| 114 | # Don't overwrite existing file. |
| 115 | gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}" |
| 116 | |
| 117 | # Copy the associated zip file that contains the sources of the release zip. |
| 118 | # Don't overwrite existing file. |
| 119 | gsutil -q cp -n "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}" |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 120 | |
| 121 | github_url="${github_prefix}/java_v${java_tools_version}/java_tools-v${java_tools_version}.zip" |
| 122 | mirror_url=${mirror_prefix}/${release_artifact} |
| 123 | urls='"mirror_url" : "'${mirror_url}'", "github_url" : "'${github_url}'"' |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 124 | else |
| 125 | tmp_url=$(gsutil ls -lh ${gcs_bucket}/tmp/build/${commit_hash}/java/java_tools-* | sort -k 2 | grep gs -m 1 | awk '{print $4}') |
| 126 | |
| 127 | gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}" |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 128 | |
| 129 | # Copy the associated zip file that contains the sources of the release zip. |
| 130 | # Don't overwrite existing file. |
| 131 | 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}') |
| 132 | gsutil -q cp -n ${tmp_sources_url} ${gcs_bucket}/${rc_sources_url} |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 133 | |
| 134 | mirror_url=${mirror_prefix}/${rc_url} |
| 135 | urls='"mirror_url" : "'${mirror_url}'"' |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 136 | fi |
| 137 | |
| 138 | # Download the file locally to compute its sha256sum (needed to update the |
| 139 | # java_tools in Bazel). |
| 140 | # Don't overwrite existing file. |
| 141 | local_zip="$tmp_dir/java_tools.zip" |
| 142 | gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip} |
| 143 | file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1) |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 144 | |
Googler | c1627af | 2023-10-02 03:56:54 -0700 | [diff] [blame] | 145 | java_tools_output='"java_tools" : {'${urls}', "sha" : "'${file_hash}'"}' |
| 146 | artifacts='"artifacts" : {'${platform_output}' '${java_tools_output}'}' |
| 147 | version='"version" : "v'${java_tools_version}'"' |
| 148 | release='"release" : "'${release}'"' |
| 149 | echo "{${version}, ${release}, ${artifacts}}" | jq |