Skip to content

ci: optimize release version checks and version caching - #14229

Open
lqiu96 wants to merge 1 commit into
mainfrom
perf-release-automation
Open

ci: optimize release version checks and version caching#14229
lqiu96 wants to merge 1 commit into
mainfrom
perf-release-automation

Conversation

@lqiu96

@lqiu96 lqiu96 commented Sep 1, 2026

Copy link
Copy Markdown
Member

Problem

In release generation scripts and nightly protobuf compatibility jobs:

  • In generation/check_existing_release_versions.sh, xmllint was invoked 3 separate times per POM across all 1,600+ POMs to extract coordinates, introducing a brittle external dependency on xmllint / libxml2-utils.
  • In sdk-platform-java/.kokoro/nightly/downstream-protobuf-binary-compatibility.sh, cat, grep, and cut were repeatedly executed against versions.txt inside a loop for each artifact (~120 subprocesses), and full repository history was cloned for cloud-opensource-java.

Changes

  • Release Version Checker Optimization (generation/check_existing_release_versions.sh):
    • Replaced external xmllint invocations with a local extract_xml_tag helper (ignoring <parent> blocks), removing the external xmllint / libxml2-utils dependency completely.
    • Replaced memory-buffered $(find ... | sort) with streaming process substitution.
    • Replaced complex chained exclusion if conditions with clean case pattern matching.
  • Associative Array Pre-caching & Shallow Clone (sdk-platform-java/.kokoro/nightly/downstream-protobuf-binary-compatibility.sh):
    • Pre-cached versions.txt into an associative array (declare -A versions_map), eliminating ~120 cat/grep/cut subprocesses and 40 redundant file reads.
    • Added --depth 1 shallow clone for cloud-opensource-java, saving ~98% of git objects and ~10MB.
    • Replaced space-substitution word-splitting with idiomatic IFS=, read -ra array operations.
    • Added explanatory comments for bash parameter expansion syntax.

@lqiu96
lqiu96 requested review from a team as code owners September 1, 2026 14:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes several shell scripts by replacing slow operations (such as mvn help:evaluate and full git clone commands) with faster alternatives like local XML parsing, git ls-remote, and associative array caching. However, the introduction of a sed-based XML parser in check_status.sh is fragile and can incorrectly extract parent POM versions instead of the project's own version. It is recommended to use xmllint with a robust XPath query to safely parse the POM files.

Comment thread java-cloud-bom/tests/release-repository-readiness/check_status.sh Outdated
@lqiu96
lqiu96 force-pushed the perf-release-automation branch from ff9e1c8 to 65b2bf0 Compare September 1, 2026 15:09
@lqiu96 lqiu96 changed the title perf(ci): optimize release readiness, commit queries, and version caching ci: optimize release readiness, commit queries, and version caching Sep 1, 2026
@lqiu96
lqiu96 force-pushed the perf-release-automation branch 8 times, most recently from d975f64 to b0c5b5f Compare September 1, 2026 22:43
Comment thread .kokoro/common.sh Outdated
local tag=$1
local file=$2
[[ ! -f "${file}" ]] && return 0
sed -n "/<parent>/,/<\/parent>/d; \|<${tag}[ >]|{s|.*<${tag}[^>]*>[[:space:]]*\([^<[:space:]]*\).*|\1|p; q;}" "${file}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML format is pretty flexible and I feel this may miss some cases. For example, group_id might be inherited from parent and not exist in the pom. I think we should use other xml tools (e.g. built-in Python XML parser) instead of using sed.

@lqiu96 lqiu96 Sep 3, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, group_id might be inherited from parent and not exist in the pom. I think we should use other xml tools (e.g. built-in Python XML parser) instead of using sed.

I believe Python's default XML parser uses XPath (same as Xmllint). XPath runs into the issue where parses the structure of a single XML file and has no knowledge of Maven pom.xml hierarchy (parent -> child inheritance)

A more robust structure for parsing may be needed in the future (ideally fast enough without having to invoke mvn help:effective-pom as that's a relatively costly call). I think the current bash call should be roughly 1:1 with existing functionality for the script. I'll move it away from common.sh and into the specific calling script so other scripts don't build reliance on this non-perfect solution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes in this file. Can we repurpose this PR to only include versions_map changes and remove the xml parsing part?

@lqiu96
lqiu96 force-pushed the perf-release-automation branch from b0c5b5f to 5726a4a Compare September 3, 2026 16:42
In release generation scripts and nightly protobuf compatibility jobs:
- In check_existing_release_versions.sh (generation/check_existing_release_versions.sh):
  * Replaced external xmllint calls with local extract_xml_tag helper, eliminating
    the xmllint / libxml2-utils dependency completely while avoiding parent-tag collisions.
  * Replaced memory-buffered $(find ... | sort) with streaming process substitution.
  * Replaced complex chained if condition with clean case pattern matching.
- In downstream-protobuf-binary-compatibility.sh (sdk-platform-java/.kokoro/nightly/downstream-protobuf-binary-compatibility.sh):
  * Pre-cached versions.txt into associative array declare -A versions_map, eliminating ~120
    cat/grep/cut subprocesses and 40 redundant file reads.
  * Added --depth 1 shallow clone for cloud-opensource-java, saving 98.5% of git objects and ~10MB.
  * Replaced space-substitution word-splitting with idiomatic IFS=, read -ra array operations.
  * Added explanatory comments for bash parameter expansion artifactId extraction.
@lqiu96
lqiu96 force-pushed the perf-release-automation branch from 5726a4a to 075de09 Compare September 3, 2026 16:43
@lqiu96 lqiu96 changed the title ci: optimize release readiness, commit queries, and version caching ci: optimize release version checks and version caching Sep 3, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants