blob: 4156998380275b289bf7748061acfe591a68703d [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:
25# --java_version The JDK version included in the java_tools to be
iirina24ce2d92019-05-15 05:38:07 -070026# released.
iirina87ea1202019-05-15 03:00:08 -070027# --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
52set -euo pipefail
53
54# Parsing the flags.
55while [[ -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
66done
67
iirina24ce2d92019-05-15 05:38:07 -070068# Create a tmp directory to download the artifacts from GCS and compute their
69# sha256sum.
70tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXX')
71trap "rm -fr $tmp_dir" EXIT
72
73gcs_bucket="gs://bazel-mirror/bazel_java_tools"
74
iirina87ea1202019-05-15 03:00:08 -070075for platform in linux windows darwin; do
iirina24ce2d92019-05-15 05:38:07 -070076 rc_url="release_candidates/javac${java_version}/v${java_tools_version}/java_tools_javac${java_version}_${platform}-v${java_tools_version}-rc${rc}.zip"
iirina894c2482019-05-16 05:41:12 -070077 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"
iirina24ce2d92019-05-15 05:38:07 -070078
iirina87ea1202019-05-15 03:00:08 -070079 if [[ $release == "true" ]]; then
iirina24ce2d92019-05-15 05:38:07 -070080 release_artifact="releases/javac${java_version}/v${java_tools_version}/java_tools_javac${java_version}_${platform}-v${java_tools_version}.zip"
iirina894c2482019-05-16 05:41:12 -070081 release_sources_artifact="releases/javac${java_version}/v${java_tools_version}/sources/java_tools_javac${java_version}_${platform}-v${java_tools_version}.zip"
iirina87ea1202019-05-15 03:00:08 -070082 # Make release candidate the release artifact for the current platform.
iirina24ce2d92019-05-15 05:38:07 -070083 gsutil -q cp "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
iirina894c2482019-05-16 05:41:12 -070084
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}"
iirina87ea1202019-05-15 03:00:08 -070087 else
iirina24ce2d92019-05-15 05:38:07 -070088 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)
iirina87ea1202019-05-15 03:00:08 -070089 # Make the generated artifact a release candidate for the current platform.
iirina24ce2d92019-05-15 05:38:07 -070090 gsutil -q cp ${tmp_url} "${gcs_bucket}/${rc_url}"
91 release_artifact="${rc_url}"
iirina894c2482019-05-16 05:41:12 -070092
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}
iirina87ea1202019-05-15 03:00:08 -070096 fi
iirina24ce2d92019-05-15 05:38:07 -070097
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}"
iirina87ea1202019-05-15 03:00:08 -0700104done