Closed
[WIP] Optimize CI workflow for concurrency and permissions#416
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Original prompt
This section details on the original issue you should resolve
<issue_title>[ci-coach] ci: optimize CI workflow — concurrency, least-privilege permissions, Go cache</issue_title>
<issue_description>### Summary
Three targeted optimizations to the
CI Buildworkflow that reduce wasted runner minutes, tighten security permissions, and improve dependency cache reliability. No test logic is changed.Optimizations
1. Add
concurrencygroup withcancel-in-progress: trueType: Conditional Execution
Impact: Eliminates duplicate runs — saves the full workflow runtime (~2–5 min) for every superseded commit
Risk: Low
Changes:
concurrencyblock at the workflow level keyed ongithub.workflow+github.refRationale: Without this, pushing 3 quick commits to a PR fires 3 full CI runs simultaneously. Only the last one matters. This is the single highest-ROI CI optimization for active PR branches.
Detailed Analysis
Before: Each push to a PR branch queues an independent run. If a developer pushes a fix-up commit 30 seconds later, both runs consume full runner minutes even though only the latest result is relevant.
After: GitHub automatically cancels the older in-progress run, freeing up concurrency and reducing billed minutes proportional to how often this happens (common on active PRs with dependabot or rapid iteration).
2. Remove
pull-requests: writefrombuild-dotnetType: Security / Least Privilege
Impact: Reduces blast radius if the workflow is compromised
Risk: None — no step in the job writes to pull requests
Changes:
pull-requests: writefrombuild-dotnetpermissions blockcontents: read, consistent with all other jobsRationale: The only steps are checkout, NuGet cache, setup-dotnet,
dotnet build, anddotnet format. None require PR write access. The commented-outdotnet teststep doesn't either. Principle of least privilege.3. Add explicit
cache-dependency-pathto Go setupType: Cache Optimization
Impact: Ensures Go module cache is keyed on
go.sum(more precise, fewer unnecessary cache misses)Risk: None
Changes:
cache-dependency-path: src/Garage.FeatureFlags/go.sumtoactions/setup-goRationale:
actions/setup-gov6 auto-caches Go modules but uses a heuristic to locatego.sumrelative to the repo root. Providing the path explicitly avoids any ambiguity and guarantees correct cache keying — matching the pattern already used byactions/setup-node(which hascache-dependency-path: src/Garage.Web/package-lock.json).Expected Impact
contents: read+pull-requests: writecontents: readonlygo.sumpathTesting Recommendations
To create a pull request with the changes: