Skip to content

Commit

Permalink
Update java_tools release script to output json
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 570015163
Change-Id: I5cbf45fcdc87f716aae49990e3feca1fd63b8e49
  • Loading branch information
keertk authored and copybara-github committed Oct 2, 2023
1 parent 3453d03 commit c1627af
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/create_java_tools_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXXX')
trap "rm -fr $tmp_dir" EXIT

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"

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"
Expand All @@ -77,13 +79,19 @@ for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do
# 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}"

github_url="${github_prefix}/java_v${java_tools_version}/java_tools_${platform}-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_${platform}* | sort -k 2 | grep gs -m 1 | awk '{print $4}')

# 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}"
release_artifact="${rc_url}"

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

# Download the file locally to compute its sha256sum (needed to update the
Expand All @@ -92,7 +100,8 @@ for platform in "linux" "windows" "darwin_x86_64" "darwin_arm64"; do
local_zip="$tmp_dir/java_tools$platform.zip"
gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
echo "${release_artifact} ${file_hash}"

platform_output+='"java_tools_'${platform}'" : {'${urls}', "sha": "'${file_hash}'"},'
done

rc_url="release_candidates/java/v${java_tools_version}/java_tools-v${java_tools_version}-rc${rc}.zip"
Expand All @@ -108,16 +117,22 @@ if [[ $release == "true" ]]; then
# 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}"

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}"
release_artifact="${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}

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

# Download the file locally to compute its sha256sum (needed to update the
Expand All @@ -126,5 +141,9 @@ fi
local_zip="$tmp_dir/java_tools.zip"
gsutil -q cp -n ${gcs_bucket}/${rc_url} ${local_zip}
file_hash=$(sha256sum ${local_zip} | cut -d' ' -f1)
echo "${release_artifact} ${file_hash}"

java_tools_output='"java_tools" : {'${urls}', "sha" : "'${file_hash}'"}'
artifacts='"artifacts" : {'${platform_output}' '${java_tools_output}'}'
version='"version" : "v'${java_tools_version}'"'
release='"release" : "'${release}'"'
echo "{${version}, ${release}, ${artifacts}}" | jq

0 comments on commit c1627af

Please sign in to comment.