Skip to content

Commit

Permalink
Fail in create_java_tools_release.sh instead of silently ignoring e…
Browse files Browse the repository at this point in the history
…xisting RCs

Context: #25048 (comment)
PiperOrigin-RevId: 722604130
Change-Id: I6766895e455916440d6fe28ad40299129f4bc31c
  • Loading branch information
hvadehra authored and copybara-github committed Feb 3, 2025
1 parent f812289 commit e2ecfc0
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/create_java_tools_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@

set -euo pipefail

function fail() {
echo $@ > /dev/stderr
exit 1
}

# Parsing the flags.
while [[ -n "$@" ]]; do
arg="$1"; shift
Expand All @@ -58,7 +63,7 @@ while [[ -n "$@" ]]; do
"--commit_hash") commit_hash="$val" ;;
"--rc") rc="$val" ;;
"--release") release="$val" ;;
*) echo "Flag $arg is not recognized." && exit 1 ;;
*) fail "Flag $arg is not recognized." ;;
esac
done

Expand All @@ -71,14 +76,25 @@ gcs_bucket="gs://bazel-mirror/bazel_java_tools"
mirror_prefix="https://mirror.bazel.build/bazel_java_tools"
github_prefix="https://github.com/bazelbuild/java_tools/releases/download"

function copy_or_fail_if_target_exists() {
src_path=$1
target_path=$2
already_exists=$(gsutil -q stat ${target_path} || echo "no")
if [[ "${already_exists}" != "no" ]]; then
fail "${target_path} already exists, did you mean to create a fresh RC / release?"
else
gsutil -q cp -n ${src_path} ${target_path}
fi
}

for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do
rc_url="release_candidates/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}-rc${rc}.zip"

if [[ $release == "true" ]]; then
release_artifact="releases/java/v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip"
# Make release candidate the release artifact for the current platform.
# Don't overwrite existing file.
gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
copy_or_fail_if_target_exists "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"

github_url="${github_prefix}/java_v${java_tools_version}/java_tools_${platform}-v${java_tools_version}.zip"
mirror_url=${mirror_prefix}/${release_artifact}
Expand All @@ -88,7 +104,7 @@ for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do

# Make the generated artifact a release candidate for the current platform.
# Don't overwrite existing file.
gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}"
copy_or_fail_if_target_exists "${tmp_url}" "${gcs_bucket}/${rc_url}"

mirror_url=${mirror_prefix}/${rc_url}
urls='"mirror_url" : "'${mirror_url}'"'
Expand All @@ -112,24 +128,24 @@ if [[ $release == "true" ]]; then
release_sources_artifact="releases/java/v${java_tools_version}/sources/java_tools-v${java_tools_version}.zip"
# Make release candidate the release artifact for the current platform.
# Don't overwrite existing file.
gsutil -q cp -n "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"
copy_or_fail_if_target_exists "${gcs_bucket}/${rc_url}" "${gcs_bucket}/${release_artifact}"

# Copy the associated zip file that contains the sources of the release zip.
# Don't overwrite existing file.
gsutil -q cp -n "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}"
copy_or_fail_if_target_exists "${gcs_bucket}/${rc_sources_url}" "${gcs_bucket}/${release_sources_artifact}"

github_url="${github_prefix}/java_v${java_tools_version}/java_tools-v${java_tools_version}.zip"
mirror_url=${mirror_prefix}/${release_artifact}
urls='"mirror_url" : "'${mirror_url}'", "github_url" : "'${github_url}'"'
else
tmp_url=$(gsutil ls -lh ${gcs_bucket}/tmp/build/${commit_hash}/java/java_tools-* | sort -k 2 | grep gs -m 1 | awk '{print $4}')

gsutil -q cp -n ${tmp_url} "${gcs_bucket}/${rc_url}"
copy_or_fail_if_target_exists "${tmp_url}" "${gcs_bucket}/${rc_url}"

# Copy the associated zip file that contains the sources of the release zip.
# Don't overwrite existing file.
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}')
gsutil -q cp -n ${tmp_sources_url} ${gcs_bucket}/${rc_sources_url}
copy_or_fail_if_target_exists "${tmp_sources_url}" "${gcs_bucket}/${rc_sources_url}"

mirror_url=${mirror_prefix}/${rc_url}
urls='"mirror_url" : "'${mirror_url}'"'
Expand Down

0 comments on commit e2ecfc0

Please sign in to comment.