Skip to content

ci: cache ingestion Python venv in setup-openmetadata-test-environment - #30350

Merged
chirag-madlani merged 3 commits into
mainfrom
ci/cache-python-venv-in-setup-action
Jul 27, 2026
Merged

chirag-madlani merged 3 commits into
mainfrom
ci/cache-python-venv-in-setup-action

Conversation

@chirag-madlani

@chirag-madlani chirag-madlani commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Every job using the shared composite action .github/actions/setup-openmetadata-test-environment builds a fresh Python venv and runs uv pip install ingestion[dev] (plus, for py-tests workflows, [all]/[test] and extras). That's ~2–4 min per shard, every run.
  • Cache the env/ venv with actions/cache@v4, keyed on runner OS + python-version + hashFiles of ingestion/setup.py, ingestion/pyproject.toml, and the action file itself.

How it works

  • Cache is scoped to a manifest hash — any change to ingestion package deps or to the install-script code in the action invalidates it cleanly.
  • Generate Models now only runs python3 -m venv env if env/ isn't already restored.
  • The install steps are intentionally left in place. uv pip install skips already-satisfied packages on cache hit, so they become fast no-ops. This keeps the change self-contained and safe for every consumer of this action regardless of which install steps they hit.

Files changed

  • .github/actions/setup-openmetadata-test-environment/action.yml
  • No workflow file changes required.

Impact estimate

On postgresql-e2e run 29907894464, the Generate Models + Install Python Dependencies steps combined for ~5–8 min per shard. Cache hit reduces both to ~10–30 s. That's ~2–4 min saved per shard × 7 shards = ~15–25 runner-minutes per run. All Playwright / py-tests / py-cli-e2e workflows using this action benefit.

Test plan

  • First run of any workflow on this branch: cache miss (normal install path runs), "Cache ingestion Python venv" step reports cache-hit=false and saves at end of job.
  • Subsequent run without dep-manifest changes: cache hit, Generate Models's uv pip install becomes near-instant.
  • py-tests-postgres on this PR still passes (venv fully populated on cache hit; installs remain functional on cache miss).

Follow-ups (out of scope for this PR)

🤖 Generated with Claude Code

Greptile Summary

This PR caches the ingestion Python environment used by the shared test setup action. The main changes are:

  • Cache env/ using the runner OS, resolved Python version, and dependency manifests.
  • Avoid fallback restoration of obsolete environments.
  • Rebuild a restored environment when its Python interpreter cannot run.
  • Keep dependency installation active after cache restoration.

Confidence Score: 4/5

The cache should be partitioned by dependency mode before merging.

  • The resolved Python version prevents restoration across interpreter patch changes.
  • Removing fallback keys prevents restoration after dependency manifests change.
  • Jobs that install different dependency sets can still restore the same immutable cache, making results depend on which job populated it first.

Files Needing Attention: .github/actions/setup-openmetadata-test-environment/action.yml

Important Files Changed

Filename Overview
.github/actions/setup-openmetadata-test-environment/action.yml Adds resolved-version venv caching and interpreter recovery, but different dependency-install modes still share one cache key.

Reviews (6): Last reviewed commit: "Merge branch 'main' into ci/cache-python..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Copilot AI review requested due to automatic review settings July 22, 2026 12:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs UI UI specific issues labels Jul 22, 2026
chirag-madlani added a commit that referenced this pull request Jul 22, 2026
Two P1 comments on #30350:

1. "Resolved Interpreter Missing From Key" — setup-python can resolve
   "3.10" to a different patch install after a runner-image update. The
   old venv's shebangs point at a tool-cache path that no longer exists,
   and the existing "did activate exist?" check silently reuses it.

   Fix: capture the resolved patch version via `id: setup-python` and use
   `steps.setup-python.outputs.python-version` in the cache key. Also
   validate `env/bin/python --version` in Generate Models and rebuild the
   venv from scratch if it can't run, so a stale restore fails loud rather
   than as an opaque shebang error deeper in the step.

2. "Fallback Restores Obsolete Dependencies" — the `restore-keys` prefix
   fallback would restore an older venv when the exact key misses, and
   `uv pip install` only adds packages, never removes ones dropped from
   the manifest. Tests could then silently import a package the manifest
   no longer declares.

   Fix: drop the restore-keys line entirely. Cache miss now guarantees a
   fresh install, so the venv can never drift from the current manifest.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 14:30

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chirag-madlani

Copy link
Copy Markdown
Collaborator Author

@greptile-apps thanks — both P1s addressed in 629495f:

  1. Resolved interpreter — added id: setup-python and switched the cache key to steps.setup-python.outputs.python-version (resolved patch). Also added a validation guard in Generate Models that rebuilds the venv if env/bin/python --version can't run, so a broken restore fails loud instead of dying on an opaque shebang error later.
  2. restore-keys fallback — dropped entirely. Cache miss now guarantees a fresh install; no risk of importing a package the current manifest doesn't declare.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Both fixes look correct. The implementation is clean:

  1. Resolved interpreter — id: setup-python + steps.setup-python.outputs.python-version in the key pins the exact patch (e.g. 3.10.14 instead of 3.10), so a runner-image bump that changes the tool-cache path invalidates the cache automatically. The ! env/bin/python --version guard in Generate Models catches any remaining edge case (e.g. a corrupted restore) and rebuilds loudly rather than failing silently later.

  2. restore-keys — dropped entirely. The inline comment explaining why there's no fallback is a nice touch for future readers.

Both P1s fully addressed. LGTM.

Copilot AI review requested due to automatic review settings July 23, 2026 09:58

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

ulixius9
ulixius9 previously approved these changes Jul 23, 2026
@chirag-madlani
chirag-madlani requested a review from a team as a code owner July 27, 2026 11:28
Copilot AI review requested due to automatic review settings July 27, 2026 11:28

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

uses: actions/cache@v4
with:
path: env
key: ${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-om-venv-${{ hashFiles('ingestion/setup.py', 'ingestion/pyproject.toml', '.github/actions/setup-openmetadata-test-environment/action.yml') }}

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.

P1 Separate dependency-mode caches The same key is used when install-test-dependencies is either true or false, although those paths install different package sets. If a full-dependency job creates the immutable cache first, a lighter job restores packages it intentionally skipped. That job can then pass only with a warm cache while failing in a clean environment. Include the dependency-install mode in the key so each configuration restores only its own environment.

Suggested change
key: ${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-om-venv-${{ hashFiles('ingestion/setup.py', 'ingestion/pyproject.toml', '.github/actions/setup-openmetadata-test-environment/action.yml') }}
key: ${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-testdeps-${{ inputs.install-test-dependencies }}-om-venv-${{ hashFiles('ingestion/setup.py', 'ingestion/pyproject.toml', '.github/actions/setup-openmetadata-test-environment/action.yml') }}

@chirag-madlani
chirag-madlani merged commit 46802be into main Jul 27, 2026
78 of 80 checks passed
@chirag-madlani
chirag-madlani deleted the ci/cache-python-venv-in-setup-action branch July 27, 2026 12:35
@gitar-bot

gitar-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Caches the ingestion Python virtual environment in the shared test setup action with a pinned resolved version and exact keys. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants