Skip to content

ci: optimize trailing whitespace check - #1617

Open
hariharimc1962-ui wants to merge 1 commit into
openconfig:masterfrom
hariharimc1962-ui:perf/single-pass-whitespace-check
Open

hariharimc1962-ui wants to merge 1 commit into
openconfig:masterfrom
hariharimc1962-ui:perf/single-pass-whitespace-check

Conversation

@hariharimc1962-ui

Copy link
Copy Markdown

Summary

  • Replace the trailing-whitespace CI loop with one git grep scan across tracked YANG models.
  • Remove 233+ repeated egrep subprocesses and shell variable accumulation per pull request.

10 performance improvements identified

  1. Implemented: Use one repository-level git grep scan for whitespace checks.
  2. Cache downloaded Go modules and the openconfig-ci binary in the breaking-change workflow.
  3. Replace the concatenated-spec shell glob/cat pipeline with a single sorted pipeline.
  4. Use shallow clones for third-party CI dependencies where full history is unnecessary.
  5. Skip unchanged validator jobs using path-based workflow filters.
  6. Cache downloaded libyang and model-CI container layers across builds.
  7. Run independent validator groups concurrently when Cloud Build resource limits allow it.
  8. Replace repeated git checkout operations in diff validation with worktrees or direct file extraction.
  9. Add caching for installed Go tools in cloudbuild.yaml.
  10. Add focused benchmark/regression tests for large-model whitespace and spec-concatenation scripts.

Validation

  • git diff --check
  • git grep -n -I -E '[[:blank:]]+$' -- 'release/models/*.yang' (no matches in the current tree)

Replace the per-file subprocess loop with a single git grep across tracked YANG models. This avoids spawning 233+ egrep processes on every pull request.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@google-cla

google-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request optimizes the continuous integration process by streamlining the trailing whitespace validation for YANG models. By replacing a per-file loop with a single repository-level grep scan, the change reduces overhead and improves the overall efficiency of the CI pipeline.

Highlights

  • CI Optimization: Replaced the inefficient loop-based trailing whitespace check with a single, high-performance 'git grep' command.
  • Performance Gains: Eliminated over 233 redundant 'egrep' subprocesses and shell variable accumulations, significantly reducing CI execution time.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@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 the trailing whitespace check in scripts/find_trailing_whitespace.sh by replacing a file-by-file loop with a single git grep command. The review feedback suggests a more idiomatic and readable way to handle the exit status of git grep under set -e instead of using an empty then block with a dummy command.

Comment on lines +28 to +36
tw_lines=""
if tw_lines=$(git grep -n -I -E '[[:blank:]]+$' -- 'release/models/*.yang'); then
:
else
grep_status=$?
if [ "$grep_status" -ne 1 ]; then
exit "$grep_status"
fi
done
fi

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

Using an if statement with a dummy : command to capture the exit status of a command substitution under set -e is non-idiomatic and less readable.

By using the || operator, we can safely capture the exit status of git grep without triggering set -e and without needing an empty then block. This makes the script cleaner and more maintainable.

Suggested change
tw_lines=""
if tw_lines=$(git grep -n -I -E '[[:blank:]]+$' -- 'release/models/*.yang'); then
:
else
grep_status=$?
if [ "$grep_status" -ne 1 ]; then
exit "$grep_status"
fi
done
fi
grep_status=0
tw_lines=$(git grep -n -I -E '[[:blank:]]+$' -- 'release/models/*.yang') || grep_status=$?
if [ "$grep_status" -ne 0 ] && [ "$grep_status" -ne 1 ]; then
exit "$grep_status"
fi

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant