|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Sets the version of a module (the top-level directory in google-cloud-java, such as |
| 4 | +# java-accessapproval) in the google-cloud-java repository to 1.0.0. |
| 5 | +# You need to call this script from the root directory on the Release Please pull request branch; |
| 6 | +# otherwise the changes to the versions are overridden by the Release Please. |
| 7 | + |
| 8 | +set -eo pipefail |
| 9 | + |
| 10 | +# Pattern to match the lines in versions.txt. Usually it's the library_name for a module, |
| 11 | +# as in the generation_config.yaml. |
| 12 | +# For example "securityposture" for the "java-securityposture" module. |
| 13 | +library_name=$1 |
| 14 | + |
| 15 | +if [ -z "${library_name}" ]; then |
| 16 | + echo "Please specify library_name that matches the pattern in versions.txt." |
| 17 | + echo "Example: 'securityposture'" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | +versions_file=versions.txt |
| 21 | + |
| 22 | +sed -i -E "s/^(.*${library_name}(-v.+)?):0.+:.+/\1:1.0.0:1.0.0/g" "${versions_file}" |
| 23 | + |
| 24 | +# Guardrail for bad pattern |
| 25 | +set +e |
| 26 | +diff_lines_count=$(git diff --unified=0 versions.txt |grep -c "^[+-]\w") |
| 27 | + |
| 28 | +if ! grep --quiet -E "${library_name}-v[1-9]:" versions.txt; then |
| 29 | + echo "The module does not seem to have a GA server API version (>= v1)." |
| 30 | + echo "A library should not become 1.0.0 before the server API releases v1 (go/client-quality)" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +set -e |
| 35 | +if [[ "${diff_lines_count}" -eq 0 ]]; then |
| 36 | + echo "There's no matching lines in versions.txt for ${library_name}." |
| 37 | + echo "Check the hyphenation in the versions.txt." |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | +if [[ "${diff_lines_count}" -gt 10 ]]; then |
| 41 | + echo "There are more than 5 lines changed. The pattern (${library_name}) is too generic. Failing this script for safe side." |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +SED_OPTIONS="" |
| 46 | +for KV in $(cut -f1,3 -d: "${versions_file}" |grep -v "#" | grep "${library_name}"); do |
| 47 | + K=${KV%:*}; V=${KV#*:} |
| 48 | + echo Key:$K, Value:$V; |
| 49 | + SED_OPTIONS="$SED_OPTIONS -e /x-version-update:$K:current/{s|<version>.*<\/version>|<version>$V<\/version>|;}" |
| 50 | +done |
| 51 | + |
| 52 | +find . -maxdepth 3 -name pom.xml |sort --dictionary-order |xargs sed -i.bak $SED_OPTIONS |
| 53 | +# Clean up unnecessary backup files |
| 54 | +find . -maxdepth 3 -name pom.xml.bak |xargs rm |
0 commit comments