-
Notifications
You must be signed in to change notification settings - Fork 603
[ENG-603] Fix caching in care backend build actions #3696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tellmeY18
wants to merge
5
commits into
ohcnetwork:develop
Choose a base branch
from
tellmeY18:fix/workflow-cache
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d9a3ea
ci: switch Docker cache to GHCR registry with weekly rotation + plugi…
tellmeY18 9a4b733
Update .github/scripts/resolve_plugins.py
tellmeY18 76ddd40
Set default value for PLUGIN_RESOLVED_HASH in Dockerfile
vigneshhari ba2e22f
Set default value for PLUGIN_RESOLVED_HASH argument
vigneshhari 7faf1f7
Address review comments on plugin cache busting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python3 | ||
| import hashlib | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
| plugs_raw = os.environ.get("ADDITIONAL_PLUGS", "[]") | ||
| try: | ||
| plugs = json.loads(plugs_raw) | ||
| except json.JSONDecodeError: | ||
| sys.stdout.write("no-plugins") | ||
| sys.exit(0) | ||
|
|
||
| if not plugs: | ||
| sys.stdout.write("no-plugins") | ||
| sys.exit(0) | ||
|
|
||
| resolved = [] | ||
| for p in plugs: | ||
| ver = p.get("version", "@main") | ||
| pkg = p.get("package_name") | ||
| if not pkg: | ||
| sys.stderr.write(f"plugin entry {p!r} is missing 'package_name'\n") | ||
| sys.exit(1) | ||
| if ver.startswith("@"): | ||
| ref = ver[1:] | ||
| git_url = pkg.removeprefix("git+") | ||
| try: | ||
| out = subprocess.run( # noqa: S603 | ||
| ["git", "ls-remote", git_url, ref], # noqa: S607 | ||
| check=False, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=15, | ||
| ) | ||
| sha = out.stdout.split()[0] if out.stdout else ref | ||
| except Exception as exc: | ||
| sys.stderr.write(f"warning: git ls-remote failed for {git_url!r} ({exc}); using ref name as cache key\n") | ||
| sha = ref | ||
| resolved.append(f"{pkg}@{sha}") | ||
| else: | ||
| resolved.append(f"{pkg}{ver}") | ||
|
|
||
| h = hashlib.sha256(json.dumps(sorted(resolved)).encode()).hexdigest()[:16] | ||
| print(h, end="") # noqa: T201 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1395
🏁 Script executed:
Repository: ohcnetwork/care
Length of output: 1395
Avoid falling back to the raw ref here. When
git ls-remotefails or returns nothing,shabecomesref, so@mainhashes likepkg@mainand stops busting the cache when the branch moves. Surface the failure instead of quietly pretending it resolved.Also,
p.get("version", "@main")does not cover"version": null; that still reachesver.startswith("@")and crashes. Usep.get("version") or "@main"ifnullshould mean default.🧰 Tools
🪛 ast-grep (0.44.0)
[error] 29-35: Command coming from incoming request
Context: subprocess.run( # noqa: S603
["git", "ls-remote", git_url, ref], # noqa: S607
check=False,
capture_output=True,
text=True,
timeout=15,
)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(subprocess-from-request)
🪛 Ruff (0.15.18)
[warning] 38-38: Do not catch blind exception:
Exception(BLE001)
🤖 Prompt for AI Agents
Source: Linters/SAST tools