Skip to content

feat(cgo): cache repository checkout to reduce GitHub API calls per run - #48699

Merged
pelikhan merged 3 commits into
mainfrom
copilot/update-cgo-yml-cache-jobs
Jul 28, 2026
Merged

feat(cgo): cache repository checkout to reduce GitHub API calls per run#48699
pelikhan merged 3 commits into
mainfrom
copilot/update-cgo-yml-cache-jobs

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Each of the ~17 jobs in cgo.yml was independently calling actions/checkout, making redundant authenticated git clone requests against GitHub on every run. This adds a single checkout-cache job that stores the checkout in actions/cache so all downstream jobs restore from cache instead.

What changed

  • New checkout-cache job: runs first, checks out with persist-credentials: false (no token in cache), saves working directory to actions/cache keyed by github.sha
  • 16 ubuntu-latest jobs replace actions/checkout with actions/cache/restore (fail-on-cache-miss: true) and gain needs: [checkout-cache]
  • 3 jobs keep direct actions/checkout:
    • impacted-go-tests, lint-go — require fetch-depth: 0 (full git history not cacheable this way)
    • cross-platform-build — runs on macOS/Windows; Linux cache is not safely reusable cross-platform
  • notify-failure gains checkout-cache in its needs so it surfaces cache job failures

Net effect: ~17 authenticated git clone calls per run → 4.

Copilot AI and others added 2 commits July 28, 2026 17:04
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Add a checkout-cache job that checks out with persist-credentials: false
and saves to actions/cache. All ubuntu-latest jobs restore from cache
instead of calling actions/checkout. Jobs needing fetch-depth: 0 or
running on non-Linux platforms keep direct checkout.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title feat: cache checkout in cgo.yml to reduce GitHub API calls feat(cgo): cache repository checkout to reduce GitHub API calls per run Jul 28, 2026
Copilot AI requested a review from pelikhan July 28, 2026 17:13
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for working on optimizing CI performance, @copilot-swe-agent! 🚀 This checkout caching strategy is smart — reducing ~17 redundant git clones per run to 4 is a meaningful savings.

A couple of things that would strengthen this PR:

  • Workflow validation — GitHub Actions workflows can benefit from validation or testing. Consider adding a step or test to verify the cache key strategy works as expected across job boundaries (e.g., ensure all ubuntu-latest jobs successfully restore from cache, and that jobs with fetch-depth: 0 or cross-platform runs still get fresh checkouts).
  • Draft status — This PR is currently in draft. When ready, mark it ready for review so maintainers can take a final look.

The logic looks sound — the checkout-cache job runs first with persist-credentials: false, and downstream jobs depend on it and restore from the keyed cache. Non-Linux or fetch-depth jobs keep direct checkout, which is the right exception.

If you would like to add validation, here is a prompt for your agent:

Add validation or test steps to .github/workflows/cgo.yml to verify the checkout cache strategy:
1. In the checkout-cache job, log the cache key being used.
2. In a restored job, verify the cache was hit (check GitHub Actions logs/output).
3. Document or validate that jobs with fetch-depth: 0 and cross-platform builds correctly skip the cache and use direct checkout.

Alternatively, create a simple integration test in tests/ that simulates the cache workflow pattern.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by ✅ Contribution Check · sonnet50 · 52.1 AIC · ⌖ 12.5 AIC · ⊞ 8.3K ·

@pelikhan
pelikhan marked this pull request as ready for review July 28, 2026 17:27
Copilot AI review requested due to automatic review settings July 28, 2026 17:27
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot lint go does not require fetch 0.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot you missing "build & test" jobs who still checkoutg.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #48699 does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot do the same optimzation for cjs.yml

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.

Pull request overview

Caches one Linux checkout for reuse across CGO jobs, reducing redundant authenticated clones.

Changes:

  • Adds a checkout-cache producer and restores it in 16 jobs.
  • Retains direct checkout where full history or cross-platform support is required.
  • Includes an unrelated generated workflow update.
Show a summary per file
File Description
.github/workflows/cgo.yml Adds shared checkout caching and job dependencies.
.github/workflows/daily-spending-forecast.lock.yml Updates generated sink-visibility handling.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Medium

Comment thread .github/workflows/cgo.yml
with:
persist-credentials: false
- name: Cache repository checkout
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
GH_AW_SAFE_OUTPUTS: ${{ steps.set-runtime-paths.outputs.GH_AW_SAFE_OUTPUTS }}
GH_AW_SAFE_OUTPUTS_CONFIG_PATH: ${{ steps.set-runtime-paths.outputs.GH_AW_SAFE_OUTPUTS_CONFIG_PATH }}
GH_AW_SAFE_OUTPUTS_TOOLS_PATH: ${{ steps.set-runtime-paths.outputs.GH_AW_SAFE_OUTPUTS_TOOLS_PATH }}
GH_AW_SINK_VISIBILITY: ${{ steps.determine-automatic-lockdown.outputs.visibility }}

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@pelikhan Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: cbfbff1b-d26a-4e8e-a422-7dce082fc752

Sorry for the inconvenience!

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /codebase-design — requesting changes on resilience and cache efficiency.

📋 Key Themes & Highlights

Issues to Address

  1. Cache eviction causes total failure (line 73): fail-on-cache-miss: true with no fallback means a stale/evicted cache (7-day TTL or 10 GB quota pressure) instantly fails all 16 downstream jobs with no recovery path. A checkout fallback step is needed.

  2. .git directory bloats the cache (line 55): path: . includes the full .git directory. Since none of the cache-consuming jobs use git commands, excluding .git reduces cache size and I/O.

  3. Missing concurrency group on checkout-cache (line 42): Every other job in this workflow has a concurrency block. Without one, concurrent pushes can race to write duplicate cache entries.

Positive Highlights

  • ✅ Clean use of persist-credentials: false — no token stored in the shared cache
  • ✅ Correct preservation of direct checkout for impacted-go-tests, lint-go (need fetch-depth: 0) and cross-platform-build (cross-OS)
  • fail-on-cache-miss: true is good intent — the fix is adding a fallback, not removing the signal

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 42.8 AIC · ⌖ 7.78 AIC · ⊞ 6.7K
Comment /matt to run again

Comment thread .github/workflows/cgo.yml
with:
path: .
key: checkout-${{ github.sha }}
fail-on-cache-miss: true

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.

[/codebase-design] fail-on-cache-miss: true with no fallback means all 16 downstream jobs fail hard if the cache is evicted (GitHub evicts after 7 days or at 10 GB). Authors see a cryptic "Cache not found" error with no self-healing path.

💡 Suggested fix

Add a checkout fallback step after the restore in each consumer job:

- name: Restore checkout
  id: restore-checkout
  uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9   # v6.1.0
  with:
    path: .
    key: checkout-${{ github.sha }}
- name: Checkout (cache-miss fallback)
  if: steps.restore-checkout.outputs.cache-hit != 'true'
  uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd   # v6.0.2
  with:
    persist-credentials: false

This preserves the optimisation on warm cache while making the workflow resilient to cold starts.

@copilot please address this.

Comment thread .github/workflows/cgo.yml
- name: Cache repository checkout
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .

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.

[/codebase-design] Caching path: . includes the .git directory, which can be hundreds of MB for a repository with history. Since no downstream job that uses this cache needs git history or git commands, excluding .git would make the cache leaner and faster to save/restore.

💡 Suggested fix
- name: Cache repository checkout
  uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9   # v6.1.0
  with:
    path: |
      .
      !.git
    key: checkout-${{ github.sha }}

Apply the same exclusion to all cache/restore steps. This can meaningfully reduce cache I/O for large repositories.

@copilot please address this.

Comment thread .github/workflows/cgo.yml
- 'install-gh-aw.sh'
workflow_dispatch:
jobs:
checkout-cache:

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.

[/codebase-design] The checkout-cache job has no concurrency group, while all other jobs in this workflow do. If multiple commits are pushed in quick succession, multiple checkout-cache jobs will run in parallel and write duplicate cache entries for the same SHA — wasting compute and cache storage quota.

💡 Suggested fix
checkout-cache:
  runs-on: ubuntu-latest
  concurrency:
    group: ci-${{ github.ref }}-checkout-cache
    cancel-in-progress: true
  timeout-minutes: 5

@copilot please address this.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Comment thread .github/workflows/cgo.yml
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .
key: checkout-${{ github.sha }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot default retention 1 day

@github-actions github-actions Bot 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.

Review: feat(cgo): cache repository checkout

Summary: Well-structured optimization — replacing ~16 independent actions/checkout calls with a shared actions/cache keyed on github.sha. The approach is sound: persist-credentials: false ensures no tokens are stored in the cache, jobs requiring fetch-depth: 0 correctly keep their own checkout, and cross-platform jobs are excluded. The daily-spending-forecast.lock.yml diff is an unrelated compiled change.

One non-blocking suggestion (inline comment): path: . includes the .git directory in the cache bundle. Since all jobs that restore the cache only build/test source files and don't use git history, caching .git adds size without benefit. Excluding it via ! prefix pattern would reduce cache size and upload/restore time.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 76.1 AIC · ⌖ 4.66 AIC · ⊞ 5K

Comment thread .github/workflows/cgo.yml
- name: Cache repository checkout
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .

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.

Potential issue: path: . caches the .git directory

Caching path: . includes the .git directory. For repos with non-trivial history, this can make the cache artifact unexpectedly large and slow to upload/restore, potentially negating the I/O savings from skipping actions/checkout.

Consider excluding .git:

path: |
  .
  !.git

actions/cache supports exclude patterns with ! prefixes. Since none of the downstream restore jobs rely on git history (they already skip jobs that need fetch-depth: 0), the .git directory in the cache is unused weight.

@copilot please address this.

@github-actions github-actions Bot 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.

🔎 Code quality review by PR Code Quality Reviewer · sonnet50 · 127 AIC · ⌖ 6.95 AIC · ⊞ 7.4K
Comment /review to run again

Comment thread .github/workflows/cgo.yml
- name: Cache repository checkout
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .

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.

Caching path: . stores the entire working tree (including .git history) instead of just checked-out source, needlessly inflating usage of the shared 10GB per-repo actions/cache quota.

💡 Details

A plain actions/checkout (with default shallow clone) is typically much smaller than the full working directory tree cached here. With ~16 jobs restoring this cache every run, and other jobs also depending on Go module/npm caches sharing the same repo-wide quota, this checkout cache risks evicting more valuable dependency caches as the repo grows.

Consider excluding .git from the cached path (e.g. git archive the tracked files instead) and monitor cache eviction/usage after rollout.

Comment thread .github/workflows/cgo.yml
timeout-minutes: 15
needs:
- checkout-cache
- test

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.

canary-go gates on needs.test.result == 'success' but not on checkout-cache's result, so if the cache save failed upstream the job still runs and hard-fails at fail-on-cache-miss: true instead of skipping cleanly.

💡 Details

This pattern repeats for every job using if: always()/conditional needs.*.result checks combined with needs: [checkout-cache, ...] (e.g. notify-failure at the bottom of the file). Since checkout-cache's own result isn't checked in the if: condition, a checkout-cache failure surfaces as an opaque "cache miss" error in every downstream job rather than a clear "upstream checkout-cache failed" signal, making CI failures harder to triage.

Consider adding && needs.checkout-cache.result == 'success' to these conditional jobs, or fail-on-cache-miss: false plus an explicit early exit step when the cache is missing.

@pelikhan
pelikhan merged commit 2402adb into main Jul 28, 2026
5 checks passed
@pelikhan
pelikhan deleted the copilot/update-cgo-yml-cache-jobs branch July 28, 2026 17:48
Copilot stopped work on behalf of pelikhan due to an error July 28, 2026 17:49
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.5

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants