Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

ci(platform): let single-container PR builds read the GHCR layer cache (#15013)

Bentlyc23b67a64368
diff --git a/.github/scripts/single_container_cache.py b/.github/scripts/single_container_cache.py
index f51aaa9004..16bc6ea602 100644
--- a/.github/scripts/single_container_cache.py
+++ b/.github/scripts/single_container_cache.py
@@ -7,8 +7,6 @@ import os
def cache_settings(event: str, ref: str, image: str, arch: str) -> list[str]:
if arch not in {"amd64", "arm64"}:
raise ValueError(f"Unsupported cache architecture: {arch}")
- if event == "pull_request":
- return []
shared = f"{image}:v4-{arch}"
imports = [shared]
export = None
diff --git a/.github/workflows/platform-single-container-docker.yml b/.github/workflows/platform-single-container-docker.yml
index 1702e577c5..b00374468a 100644
--- a/.github/workflows/platform-single-container-docker.yml
+++ b/.github/workflows/platform-single-container-docker.yml
@@ -102,7 +102,7 @@ jobs:
image=docker.io/moby/buildkit:v0.32.0@sha256:1f8167fcb0eca5b7126353d35299386945cbb8949cc516c592a49f80cfce4fa2
- name: Authenticate to GHCR build cache
- if: ${{ github.event_name != 'pull_request' }}
+ continue-on-error: ${{ github.event_name == 'pull_request' }}
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
diff --git a/autogpt_platform/single-container/tests/test_ci_registry_cache.py b/autogpt_platform/single-container/tests/test_ci_registry_cache.py
index 3f16733342..7167dc8004 100644
--- a/autogpt_platform/single-container/tests/test_ci_registry_cache.py
+++ b/autogpt_platform/single-container/tests/test_ci_registry_cache.py
@@ -17,8 +17,33 @@ class RegistryCacheTests(unittest.TestCase):
def settings(self, event, ref="refs/heads/dev", arch="amd64"):
return cache.cache_settings(event, ref, IMAGE, arch)
- def test_pull_requests_never_read_or_write_registry_cache(self):
- self.assertEqual(self.settings("pull_request"), [])
+ def test_pull_requests_read_but_never_write_registry_cache(self):
+ self.assertEqual(
+ self.settings("pull_request", "refs/pull/1/merge"),
+ [
+ f"{target}.cache-from=type=registry,ref={IMAGE}:v4-amd64"
+ for target in (
+ "backend-server-base",
+ "backend-server",
+ "single-container",
+ )
+ ],
+ )
+ self.assertFalse(
+ any("cache-to" in s for s in self.settings("pull_request", arch="arm64"))
+ )
+
+ def test_only_pull_requests_tolerate_a_failed_cache_login(self):
+ workflow = (
+ SCRIPT.parents[1] / "workflows/platform-single-container-docker.yml"
+ ).read_text(encoding="utf-8")
+ login = workflow.split(" - name: Authenticate to GHCR build cache\n", 1)[
+ 1
+ ].split(" - name:", 1)[0]
+ self.assertIn(
+ "continue-on-error: ${{ github.event_name == 'pull_request' }}", login
+ )
+ self.assertNotIn("if:", login)
def test_only_dev_push_writes_the_shared_validation_cache(self):
settings = self.settings("push")
diff --git a/docs/platform/contributing/tests.md b/docs/platform/contributing/tests.md
index b1243ce846..02b1988fed 100644
--- a/docs/platform/contributing/tests.md
+++ b/docs/platform/contributing/tests.md
@@ -88,8 +88,9 @@ Dependency and browser caches are keyed to their lockfiles. Browser caches can
fall back to a previous cache for the same runner OS, then install missing versions.
Docker builds reuse unchanged layers. Full-stack cache export is limited to trusted `dev` pushes or an
explicit cache-publishing dispatch. Single-container builds use GHCR caches per
-architecture instead of the repository Actions cache, except on pull requests,
-which do not read or write registry caches. Manual dispatches read and update a
+architecture instead of the repository Actions cache. Pull requests read the shared
+`dev` validation cache but never write one; on a pull request a failed GHCR login
+or an unreadable cache gives a cold build, not a failed job. Manual dispatches read and update a
branch-specific cache, with the shared `dev` validation cache as a read-only fallback.
The helper writes that shared tag only on a push to `dev`, but repository workflows
with package-write permission can overwrite it. Release publication therefore