Skip to content

ROX-33792: optimize git checkout with shallow clones#19615

Open
janisz wants to merge 2 commits intomasterfrom
optimize-shallow-clones-master
Open

ROX-33792: optimize git checkout with shallow clones#19615
janisz wants to merge 2 commits intomasterfrom
optimize-shallow-clones-master

Conversation

@janisz
Copy link
Contributor

@janisz janisz commented Mar 25, 2026

Description

Pre-compute build tag and short commit in define-job-matrix (with full history), then pass to downstream jobs via BUILD_TAG and SHORTCOMMIT environment variables. This allows downstream jobs to use shallow clones while maintaining correct version information.

Benefits:

  • Only define-job-matrix needs full history (1× fetch)
  • All other jobs use shallow clones (default fetch-depth: 1)
  • Estimated savings: ~12s × 4-8 jobs = 48-96s per workflow run

Technical details:

  • Makefiles respect BUILD_TAG and SHORTCOMMIT env vars (see make/env.mk)
  • status.sh now gets version info from environment instead of git
  • Prerelease/rcd jobs still override BUILD_TAG as needed
  • Backwards compatible: local builds still work (fallback to git)

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

CI

Pre-compute build tag and short commit in define-job-matrix (with full
history), then pass to downstream jobs via BUILD_TAG and SHORTCOMMIT
environment variables. This allows downstream jobs to use shallow clones
while maintaining correct version information.

Changes:
- define-job-matrix: Add fetch-depth: 0, compute build-tag and
  short-commit outputs
- Updated jobs to use BUILD_TAG and SHORTCOMMIT env vars:
  - pre-build-go-binaries
  - build-and-push-main
  - push-main-manifests
  - build-and-push-operator
  - push-operator-manifests
  - scan-images-with-roxctl
- Removed fetch-depth: 0 from all downstream jobs (now use default
  shallow clone)

Benefits:
- Only define-job-matrix needs full history (1× fetch)
- All other jobs use shallow clones (default fetch-depth: 1)
- Estimated savings: ~12s × 4-8 jobs = 48-96s per workflow run

Technical details:
- Makefiles respect BUILD_TAG and SHORTCOMMIT env vars (see make/env.mk)
- status.sh now gets version info from environment instead of git
- Prerelease/rcd jobs still override BUILD_TAG as needed
- Backwards compatible: local builds still work (fallback to git)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@janisz janisz requested a review from a team as a code owner March 25, 2026 16:59
@janisz janisz changed the title perf(ci): optimize git checkout with shallow clones ROX-33792: optimize git checkout with shallow clones Mar 25, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Since BUILD_TAG and SHORTCOMMIT are now computed once and exported via job outputs, consider centralizing their propagation (e.g., via a reusable job or a shared env at the workflow level where possible) to avoid repetitive per-job env blocks and reduce the risk of inconsistencies in future edits.
  • In the vulnerability scan step you set BUILD_TAG/SHORTCOMMIT from the matrix outputs but still recompute release_tag via make tag; if the intent is to rely on the precomputed value, you could use $BUILD_TAG directly and avoid an extra make/git call there.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since BUILD_TAG and SHORTCOMMIT are now computed once and exported via job outputs, consider centralizing their propagation (e.g., via a reusable job or a shared `env` at the workflow level where possible) to avoid repetitive per-job `env` blocks and reduce the risk of inconsistencies in future edits.
- In the vulnerability scan step you set BUILD_TAG/SHORTCOMMIT from the matrix outputs but still recompute `release_tag` via `make tag`; if the intent is to rely on the precomputed value, you could use `$BUILD_TAG` directly and avoid an extra `make`/git call there.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@janisz janisz requested review from davdhacs and removed request for a team March 25, 2026 17:01
@rhacs-bot
Copy link
Contributor

rhacs-bot commented Mar 25, 2026

Images are ready for the commit at 46cb0e3.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-447-g46cb0e36d1.

@janisz janisz requested a review from porridge March 25, 2026 17:32
@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.28%. Comparing base (72d7354) to head (46cb0e3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19615      +/-   ##
==========================================
- Coverage   49.28%   49.28%   -0.01%     
==========================================
  Files        2735     2735              
  Lines      206215   206215              
==========================================
- Hits       101632   101625       -7     
- Misses      97041    97047       +6     
- Partials     7542     7543       +1     
Flag Coverage Δ
go-unit-tests 49.28% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@janisz janisz added the auto-retest PRs with this label will be automatically retested if prow checks fails label Mar 25, 2026
Fixes test failures where development builds were incorrectly compiled
as release builds.

Root cause:
- make/env.mk checks if BUILD_TAG is set in CI to determine release builds
- Our shallow clone optimization now sets BUILD_TAG for ALL builds
- This caused ALL builds to be compiled with GOTAGS=release

Solution:
- Check if BUILD_TAG contains '.x' (development tag marker)
- Only set GOTAGS=release for clean version tags without '.x'

Examples:
- 4.7.x-36-gc2253ef650 → development build (GOTAGS empty)
- 4.6.0 → release build (GOTAGS=release)
- 4.11.x-nightly-20260325 → development build (GOTAGS empty)

This fixes E2E test failures:
- TestMetadataIsSetCorrectly expecting buildFlavor=development
- TestFeatureFlagSettings expecting development defaults

AI-assisted debugging and fix.
@rhacs-bot
Copy link
Contributor

/retest

Copy link
Contributor

@davdhacs davdhacs left a comment

Choose a reason for hiding this comment

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

+1 with or without SHORTCOMMIT :)

- name: Compute short commit
id: short-commit
run: |
SHORTCOMMIT=$(make --quiet --no-print-directory shortcommit)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like SHORTCOMMIT is only used by main-build-dockerized. Can it be removed from this workflow?

# Use a release go -tag when CI is targeting a release tag (not development tags with .x)
ifdef CI
ifneq ($(BUILD_TAG),)
ifeq ($(findstring .x,$(BUILD_TAG)),)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there another way to avoid having this in the release execution path? It looks good, but it feels like there may be a way to separate it fully like if there is another variable in addition to BUILD_TAG that can signify a non-release CI build (or we could add one?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried the following, but I think your ".x" check reads better:

Suggested change
ifeq ($(findstring .x,$(BUILD_TAG)),)
# Preserve existing GOTAGS and append release tags
GOTAGS := $(if $(GOTAGS),$(GOTAGS)$(comma))$(RELEASE_GOTAGS)
else ifneq ($(DEV_BUILD_TAG),)
BUILD_TAG := $(DEV_BUILD_TAG)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So there is TAG in line 47 but it's clear on purpose to prevent injection from env.

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

Labels

ai-review area/ci auto-retest PRs with this label will be automatically retested if prow checks fails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants