Skip to content

chore: add a script to do a sparse checkout of the mono repo to make it manageable#13408

Merged
igorbernstein2 merged 2 commits into
googleapis:mainfrom
igorbernstein2:monorepo-script
Jun 9, 2026
Merged

chore: add a script to do a sparse checkout of the mono repo to make it manageable#13408
igorbernstein2 merged 2 commits into
googleapis:mainfrom
igorbernstein2:monorepo-script

Conversation

@igorbernstein2

@igorbernstein2 igorbernstein2 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This repo is 5GB, breaks a lot of tooling. To make it manageable this script will do a sparse clone of it, then walk the dependency tree and do a cone checkout of just the relevant modules. The script should work with any module, but currently lives under bigtable until there is interest to move it to the monorepo root

Example usage:

# download the git repo, but don't populate the worktree
git clone --sparse git@github.com:googleapis/google-cloud-java.git

# now populate the worktree with your team's module
cd google-cloud-java
git sparse-checkout set java-bigtable

# then use the script to add all of the relevant modules to the worktree and install them in the local maven repo
java-bigtable/scripts/sparse-bootstrap.py java-bigtable

# now you can work in you module dir
cd java-bigtable
mvn install

# after a release, git pull & re-run the script to install updated dependencies into your local maven repo
git pull
java-bigtable/scripts/sparse-bootstrap.py java-bigtable

@igorbernstein2 igorbernstein2 requested review from a team as code owners June 9, 2026 22:14

@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 introduces a new script, sparse-bootstrap.py, designed to automate sparse checkout and dependency installation for Maven modules. The code review identified several key improvements: resolving issues in parent POM resolution (handling directory-based relative paths and coordinate fallbacks), adding the -N flag to prevent recursive Maven builds when no submodules are targeted, ensuring compatibility with Python versions older than 3.9 by replacing Path.is_relative_to, and filtering out root-level files from the sparse-checkout directory list to prevent Git warnings.

Comment thread java-bigtable/scripts/sparse-bootstrap.py Outdated
Comment thread java-bigtable/scripts/sparse-bootstrap.py
Comment thread java-bigtable/scripts/sparse-bootstrap.py
needed_poms, dep_edges = find_needed_modules(seed_dir, pom_contents, coord_to_pom)
sorted_poms = topo_sort(needed_poms, dep_edges)

top_dirs = sorted({p.parts[0] for p in needed_poms})

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.

medium

If needed_poms contains a root-level pom.xml (e.g., pom.xml), p.parts[0] will be 'pom.xml'. In Git's sparse-checkout cone mode, adding a file instead of a directory can cause warnings or errors. Since root-level files are always checked out by default in cone mode, we should filter out any root-level paths (where len(p.parts) <= 1) from top_dirs.

Suggested change
top_dirs = sorted({p.parts[0] for p in needed_poms})
top_dirs = sorted({p.parts[0] for p in needed_poms if len(p.parts) > 1})

@nimf nimf 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.

This helps a lot!

Comment thread java-bigtable/scripts/sparse-bootstrap.py Outdated
@igorbernstein2 igorbernstein2 enabled auto-merge (squash) June 9, 2026 22:44
@igorbernstein2 igorbernstein2 merged commit bc90e19 into googleapis:main Jun 9, 2026
180 of 183 checks passed
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