xref: /aosp_15_r20/external/google-cloud-java/generation/check_existing_release_versions.sh (revision 55e87721aa1bc457b326496a7ca40f3ea1a63287)
1#!/bin/bash
2
3# Using Google Mirror to avoid unnecessary load to https://repo1.maven.org/maven2
4MAVEN_SITE=https://maven-central.storage-download.googleapis.com/maven2
5
6set -e
7
8function find_existing_version_pom() {
9  local pom_file=$1
10  if [ -z "${pom_file}" ]; then
11    echo "Empty pom file name"
12    exit 1
13  fi
14  local group_id=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="groupId"]/text()' \
15      "${pom_file}")
16  local artifact_id=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="artifactId"]/text()' \
17      "${pom_file}")
18  local version=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' \
19      "${pom_file}")
20  echo -n "Checking ${group_id}:${artifact_id}:${version}:"
21  if [ -z "${group_id}" ] || [ -z "${artifact_id}" ] || [ -z "${version}" ]; then
22    echo "Couldn't parse the pom file: $pom_file"
23    exit 1
24  fi
25  if [[ "${version}" == *SNAPSHOT* ]] && [ "${artifact_id}" != "google-cloud-java" ]; then
26    echo " Release Please pull request contains SNAPSHOT version. Please investigate."
27    return_code=1
28  fi
29  local group_id_dir="${group_id//\.//}"
30  local URL="${MAVEN_SITE}/${group_id_dir}/${artifact_id}/${version}/${artifact_id}-${version}.pom"
31  local status_code=$(curl --silent --head -o /dev/null -w "%{http_code}" $URL)
32  if [ "${status_code}" == "404" ]; then
33    echo " The version does not exists. Good"
34  else
35    echo " The version already exists at ${URL}. Please investigate."
36    return_code=1
37  fi
38
39}
40
41return_code=0
42
43for pom_file in $(find . -maxdepth 3 -name pom.xml|sort --dictionary-order); do
44  find_existing_version_pom "${pom_file}"
45done
46
47exit ${return_code}
48