blob: 92dca4e3337e199f978b165fb658672f63f0f62d [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"
71
Ivo Listd10013d2020-11-25 14:41:16 -080072for 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"
iirina24ce2d92019-05-15 05:38:07 -070074
iirina87ea1202019-05-15 03:00:08 -070075 if [[ $release == "true" ]]; then
Ivo Listd10013d2020-11-25 14:41:16 -080076 release_artifact="releases/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip"
iirina87ea1202019-05-15 03:00:08 -070077 # Make release candidate the release artifact for the current platform.
Irina Iancu82ca3462019-10-15 04:23:53 -070078 # Don't overwrite existing file.
79 gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
iirina87ea1202019-05-15 03:00:08 -070080 else
Ivo Listd10013d2020-11-25 14:41:16 -080081 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 -070082
iirina87ea1202019-05-15 03:00:08 -070083 # Make the generated artifact a release candidate for the current platform.
Irina Iancu82ca3462019-10-15 04:23:53 -070084 # Don't overwrite existing file.
85 gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}"
iirina24ce2d92019-05-15 05:38:07 -070086 release_artifact="${rc_url}"
iirina87ea1202019-05-15 03:00:08 -070087 fi
iirina24ce2d92019-05-15 05:38:07 -070088
89 # Download the file locally to compute its sha256sum (needed to update the
90 # java_tools in Bazel).
Irina Iancu82ca3462019-10-15 04:23:53 -070091 # Don't overwrite existing file.
Ivo List62022712020-11-27 07:24:36 -080092 local_zip="$tmp_dir/java_tools$platform.zip"
Irina Iancu82ca3462019-10-15 04:23:53 -070093 gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
iirina24ce2d92019-05-15 05:38:07 -070094 file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
95 echo "${release_artifact} ${file_hash}"
iirina87ea1202019-05-15 03:00:08 -070096done
Ivo Listd10013d2020-11-25 14:41:16 -080097
98rc_url="release_candidates/java/v${java_tools_version}/java_tools-v${java_tools_version}-rc${rc}.zip"
99rc_sources_url="release_candidates/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}-rc${rc}.zip"
100
101if [[ $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}"
111else
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}
121fi
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.
126local_zip="$tmp_dir/java_tools.zip"
127gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
128file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
129echo "${release_artifact} ${file_hash}"
130