From aa0f39cabd59c2fea9f3c6b2fbe6ab18466062c3 Mon Sep 17 00:00:00 2001 From: Christopher Petito Date: Fri, 23 Jan 2026 14:34:47 +0100 Subject: [PATCH] Optmize CI by caching better This is likely a temporary optimization before we move the project to build cloud Signed-off-by: Christopher Petito --- .github/workflows/ci.yml | 54 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b83bdfe28..75fbbf249 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,9 @@ on: pull_request: branches: [main] +env: + GO_VERSION: "1.25.5" + jobs: lint: runs-on: ubuntu-latest @@ -23,10 +26,15 @@ jobs: uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Go + id: setup-go uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: - go-version: "1.25.5" + go-version: ${{ env.GO_VERSION }} cache: true + cache-dependency-path: go.sum + + - name: Go cache status + run: echo "cache-hit=${{ steps.setup-go.outputs.cache-hit }}" - name: Lint uses: golangci/golangci-lint-action@e7fa5ac41e1cf5b7d48e45e42232ce7ada589601 # v9.1.0 @@ -40,10 +48,15 @@ jobs: uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Go + id: setup-go uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: - go-version: "1.25.5" + go-version: ${{ env.GO_VERSION }} cache: true + cache-dependency-path: go.sum + + - name: Go cache status + run: echo "cache-hit=${{ steps.setup-go.outputs.cache-hit }}" - name: Install Task uses: go-task/setup-task@0ab1b2a65bc55236a3bc64cde78f80e20e8885c2 # v1.0.0 @@ -60,10 +73,15 @@ jobs: uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Go + id: setup-go uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: - go-version: "1.25.5" + go-version: ${{ env.GO_VERSION }} cache: true + cache-dependency-path: go.sum + + - name: Go cache status + run: echo "cache-hit=${{ steps.setup-go.outputs.cache-hit }}" - name: Install go-licences run: go install github.com/google/go-licenses@latest @@ -79,10 +97,15 @@ jobs: uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Set up Go + id: setup-go uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: - go-version: "1.25.5" + go-version: ${{ env.GO_VERSION }} cache: true + cache-dependency-path: go.sum + + - name: Go cache status + run: echo "cache-hit=${{ steps.setup-go.outputs.cache-hit }}" - name: Install Task uses: go-task/setup-task@0ab1b2a65bc55236a3bc64cde78f80e20e8885c2 # v1.0.0 @@ -110,6 +133,7 @@ jobs: password: ${{ secrets.DOCKERPUBLICBOT_WRITE_PAT }} - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 - name: Docker metadata @@ -122,6 +146,26 @@ jobs: type=edge type=ref,event=pr + - name: Cache Go build mounts + id: cache + uses: actions/cache@v4 + with: + path: .buildkit-cache + key: buildkit-${{ runner.os }}-${{ hashFiles('Dockerfile', 'go.sum') }} + restore-keys: | + buildkit-${{ runner.os }}- + + - name: Inject Go caches into builder + uses: reproducible-containers/buildkit-cache-dance@v3 + with: + builder: ${{ steps.buildx.outputs.name }} + cache-map: | + { + ".buildkit-cache/go-mod": "/go/pkg/mod", + ".buildkit-cache/go-build": "/root/.cache/go-build" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and push image uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 with: @@ -135,3 +179,5 @@ jobs: build-args: | GIT_TAG=${{ github.ref_name }} GIT_COMMIT=${{ github.sha }} + cache-from: type=gha,scope=cagent-image + cache-to: type=gha,mode=max,scope=cagent-image