blob: eb160866c4d979aab8734f686e3fa39b95b90311 [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.
Googlerb0172be2020-06-09 05:05:08 -070070tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXXX')
iirina24ce2d92019-05-15 05:38:07 -070071trap "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.
Irina Iancu82ca3462019-10-15 04:23:53 -070083 # Don't overwrite existing file.
84 gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
iirina894c2482019-05-16 05:41:12 -070085
86 # Copy the associated zip file that contains the sources of the release zip.
Irina Iancu82ca3462019-10-15 04:23:53 -070087 # Don't overwrite existing file.
88 gsutil -q cp -n "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}"
iirina87ea1202019-05-15 03:00:08 -070089 else
iirina0c8260b2019-07-24 08:35:56 -070090 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 -m 1 | awk '{print $4}')
91
92
iirina87ea1202019-05-15 03:00:08 -070093 # Make the generated artifact a release candidate for the current platform.
Irina Iancu82ca3462019-10-15 04:23:53 -070094 # Don't overwrite existing file.
95 gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}"
iirina24ce2d92019-05-15 05:38:07 -070096 release_artifact="${rc_url}"
iirina894c2482019-05-16 05:41:12 -070097
98 # Copy the associated zip file that contains the sources of the release zip.
Irina Iancu82ca3462019-10-15 04:23:53 -070099 # Don't overwrite existing file.
iirina0c8260b2019-07-24 08:35:56 -0700100 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 -m 1 | awk '{print $4}')
Irina Iancu82ca3462019-10-15 04:23:53 -0700101 gsutil -q cp -n ${tmp_sources_url} ${gcs_bucket}/${rc_sources_url}
iirina87ea1202019-05-15 03:00:08 -0700102 fi
iirina24ce2d92019-05-15 05:38:07 -0700103
104 # Download the file locally to compute its sha256sum (needed to update the
105 # java_tools in Bazel).
Irina Iancu82ca3462019-10-15 04:23:53 -0700106 # Don't overwrite existing file.
iirina24ce2d92019-05-15 05:38:07 -0700107 local_zip="$tmp_dir/java_tools_$platform.zip"
Irina Iancu82ca3462019-10-15 04:23:53 -0700108 gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
iirina24ce2d92019-05-15 05:38:07 -0700109 file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
110 echo "${release_artifact} ${file_hash}"
iirina87ea1202019-05-15 03:00:08 -0700111done