blob: fd3f7702d2a97c2c47ae7b18b36ec48c66e1a6f7 [file] [log] [blame]
iirina87ea1202019-05-15 03:00:08 -07001#!/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:
iirina87ea1202019-05-15 03:00:08 -070025# --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 Listd10013d2020-11-25 14:41:16 -080043# --java_tools_version 2.1 --rc 1 --release false
iirina87ea1202019-05-15 03:00:08 -070044#
45# To release the release candidate created above:
46#
47# src/create_java_tools_release.sh \
Ivo Listd10013d2020-11-25 14:41:16 -080048# --java_tools_version 2.1 --rc 1 --release true
iirina87ea1202019-05-15 03:00:08 -070049
50set -euo pipefail
51
52# Parsing the flags.
53while [[ -n "$@" ]]; do
54 arg="$1"; shift
55 val="$1"; shift
56 case "$arg" in
iirina87ea1202019-05-15 03:00:08 -070057 "--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
63done
64
iirina24ce2d92019-05-15 05:38:07 -070065# Create a tmp directory to download the artifacts from GCS and compute their
66# sha256sum.
Googlerb0172be2020-06-09 05:05:08 -070067tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXXX')
iirina24ce2d92019-05-15 05:38:07 -070068trap "rm -fr $tmp_dir" EXIT
69
70gcs_bucket="gs://bazel-mirror/bazel_java_tools"
Googlerc1627af2023-10-02 03:56:54 -070071mirror_prefix="https://mirror.bazel.build/bazel_java_tools"
72github_prefix="https://github.com/bazelbuild/java_tools/releases/download"
iirina24ce2d92019-05-15 05:38:07 -070073
hvd3b475b32023-03-16 07:28:55 -070074for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do
Ivo Listd10013d2020-11-25 14:41:16 -080075 rc_url="release_candidates/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}-rc${rc}.zip"
iirina24ce2d92019-05-15 05:38:07 -070076
iirina87ea1202019-05-15 03:00:08 -070077 if [[ $release == "true" ]]; then
Ivo Listd10013d2020-11-25 14:41:16 -080078 release_artifact="releases/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip"
iirina87ea1202019-05-15 03:00:08 -070079 # Make release candidate the release artifact for the current platform.
Irina Iancu82ca3462019-10-15 04:23:53 -070080 # Don't overwrite existing file.
81 gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
Googlerc1627af2023-10-02 03:56:54 -070082
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}'"'
iirina87ea1202019-05-15 03:00:08 -070086 else
Ivo Listd10013d2020-11-25 14:41:16 -080087 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}')
iirina0c8260b2019-07-24 08:35:56 -070088
iirina87ea1202019-05-15 03:00:08 -070089 # Make the generated artifact a release candidate for the current platform.
Irina Iancu82ca3462019-10-15 04:23:53 -070090 # Don't overwrite existing file.
91 gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}"
Googlerc1627af2023-10-02 03:56:54 -070092
93 mirror_url=${mirror_prefix}/${rc_url}
94 urls='"mirror_url" : "'${mirror_url}'"'
iirina87ea1202019-05-15 03:00:08 -070095 fi
iirina24ce2d92019-05-15 05:38:07 -070096
97 # Download the file locally to compute its sha256sum (needed to update the
98 # java_tools in Bazel).
Irina Iancu82ca3462019-10-15 04:23:53 -070099 # Don't overwrite existing file.
Ivo List62022712020-11-27 07:24:36 -0800100 local_zip="$tmp_dir/java_tools$platform.zip"
Irina Iancu82ca3462019-10-15 04:23:53 -0700101 gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
iirina24ce2d92019-05-15 05:38:07 -0700102 file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
Googlerc1627af2023-10-02 03:56:54 -0700103
104 platform_output+='"java_tools_'${platform}'" : {'${urls}', "sha": "'${file_hash}'"},'
iirina87ea1202019-05-15 03:00:08 -0700105done
Ivo Listd10013d2020-11-25 14:41:16 -0800106
107rc_url="release_candidates/java/v${java_tools_version}/java_tools-v${java_tools_version}-rc${rc}.zip"
108rc_sources_url="release_candidates/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}-rc${rc}.zip"
109
110if [[ $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}"
Googlerc1627af2023-10-02 03:56:54 -0700120
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 Listd10013d2020-11-25 14:41:16 -0800124else
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 Listd10013d2020-11-25 14:41:16 -0800128
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}
Googlerc1627af2023-10-02 03:56:54 -0700133
134 mirror_url=${mirror_prefix}/${rc_url}
135 urls='"mirror_url" : "'${mirror_url}'"'
Ivo Listd10013d2020-11-25 14:41:16 -0800136fi
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.
141local_zip="$tmp_dir/java_tools.zip"
142gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
143file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
Ivo Listd10013d2020-11-25 14:41:16 -0800144
Googlerc1627af2023-10-02 03:56:54 -0700145java_tools_output='"java_tools" : {'${urls}', "sha" : "'${file_hash}'"}'
146artifacts='"artifacts" : {'${platform_output}' '${java_tools_output}'}'
147version='"version" : "v'${java_tools_version}'"'
148release='"release" : "'${release}'"'
149echo "{${version}, ${release}, ${artifacts}}" | jq