xref: /aosp_15_r20/external/google-cloud-java/generation/apply_current_versions.sh (revision 55e87721aa1bc457b326496a7ca40f3ea1a63287)
1#!/bin/bash
2
3# This script sets the "current-version" written in versions.txt applied to all
4# pom.xml files in this monorepo.
5# This script plays supplemental role just in case Release Please pull request
6# fails to update all files.
7
8# Usage:
9# # Run this script at the root of the monorepo
10# bash generation/apply_current_versions.sh
11
12set -e
13
14SED_OPTIONS=""
15for versions_file in $(find . -mindepth 0 -maxdepth 2 -name versions.txt \
16    |sort --dictionary-order); do
17  for KV in $(cut -f1,3 -d: $versions_file |grep -v "#"); do
18    K=${KV%:*}; V=${KV#*:}
19    echo Key:$K, Value:$V;
20    SED_OPTIONS="$SED_OPTIONS -e /x-version-update:$K:current/{s|<version>.*<\/version>|<version>$V<\/version>|;}"
21  done
22done
23
24echo "Running sed command. It may take few minutes."
25find . -maxdepth 3 -name pom.xml |sort --dictionary-order |xargs sed -i.bak $SED_OPTIONS
26find . -maxdepth 3 -name pom.xml.bak |xargs rm
27