Skip to content

feat(lint): Cache necessary files for lint:check-cpp-static-full to skip unnecessary re-runs.#815

Merged
kirkrodrigues merged 3 commits into
y-scope:mainfrom
kirkrodrigues:cache-clang-tidy
Apr 11, 2025
Merged

feat(lint): Cache necessary files for lint:check-cpp-static-full to skip unnecessary re-runs.#815
kirkrodrigues merged 3 commits into
y-scope:mainfrom
kirkrodrigues:cache-clang-tidy

Conversation

@kirkrodrigues

@kirkrodrigues kirkrodrigues commented Apr 11, 2025

Copy link
Copy Markdown
Member

Description

The lint:check-cpp-static-full task in the clp-core-build and clp-core-build-macos workflows currently takes ~10m to run. As we fix clang-tidy violations in more files, this time will likely increase steadily. However, since a pull request might only change a few C++ source files, the time spent re-checking the other source files is wasted.

This PR uses the actions/cache action to cache the lint:check-cpp-static-full task from the main branch, so that when run in a pull request, it will skip re-running clang-tidy on the files which haven't changed. This could miss issues in files that haven't changed but that depend on the files which have changed, but those will still be caught by the nightly scheduled run which doesn't use the cache.

Note that we cache both:

  • the source file checksums that task uses to determine whether a source file has changed; and
  • the files generated by the task, which in this case are the logs of clang-tidy's output and a failure/success message.

The cache is only updated when it's run successfully on main, so the generated files should all contain a success message.

Overall, this reduces the time for the lint:check-cpp-static-full task in the workflows to less than a minute when the C++ files haven't been changed or only small changes have been made.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Committed this change to the main branch of my fork.
  • Waited for the cache to be successfully built.
  • Created a branch from the main branch of my fork.
  • Added a clang-tidy violation to that branch.
  • Validated that it was detected (quickly) by the workflow that runs lint:check-cpp-static-full.
  • Reverted the clang-tidy violation.
  • Validated that the workflow succeeded (quickly).

Summary by CodeRabbit

Summary by CodeRabbit

  • Chores
    • Enhanced the build process by optimising the caching mechanism for linting operations across multiple operating systems.
    • Implemented conditional steps to update caching only when necessary, contributing to more efficient build times and resource usage.

@kirkrodrigues kirkrodrigues requested a review from a team as a code owner April 11, 2025 01:28
@coderabbitai

coderabbitai Bot commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update two GitHub Actions workflow files to introduce caching for the lint:check-cpp-static-full task. In both the macOS and Ubuntu lint jobs, two conditional steps have been added: one to restore an existing cache and another to update it. The restore step is executed for non-scheduled events, while the update step runs only on the main branch for non-pull request events. The caching mechanism uses unique keys based on the operating system and branch to ensure proper cache segregation.

Changes

File(s) Change Summary
.github/workflows/clp-core-build-...-macos.yaml
.github/workflows/clp-core-build.yaml
Added two caching steps in each workflow for the lint:check-cpp-static-full task:
- Restore Cache Step: Executes on non-scheduled events to restore cached files.
- Update Cache Step: Executes on the main branch (non-pull request events) to save updated cache using key derived from the restore step output.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Action Runner
    participant Restore as Restore Cache Step
    participant Update as Update Cache Step

    Runner->>Restore: Check if event is not scheduled
    Restore-->>Runner: Return restored cache (OS-specific key)
    Runner->>Update: Check if branch is 'main' and not a pull request
    Update-->>Runner: Save updated cache using key from restore step
Loading

Possibly related PRs

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ad3edb and 96e384a.

📒 Files selected for processing (2)
  • .github/workflows/clp-core-build-macos.yaml (1 hunks)
  • .github/workflows/clp-core-build.yaml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/clp-core-build-macos.yaml
  • .github/workflows/clp-core-build.yaml

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/clp-core-build-macos.yaml (1)

92-105: Efficient Cache Restoration for clang-tidy Results
The added step to restore the lint cache is implemented correctly. The conditional check ('schedule' != github.event_name) ensures that on scheduled events the cache restoration is skipped—this is in line with the intent to update cache only on specific events. Additionally, using a per-OS cache key (main-branch-${{matrix.os}}-lint:check-cpp-tidy-static-full) is a smart approach to separate caches for different operating systems.

Suggestion: Consider adding an inline comment explaining why scheduled events are excluded from the cache restore to help future maintainers understand this decision.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e647d4 and 160b9b9.

📒 Files selected for processing (2)
  • .github/workflows/clp-core-build-macos.yaml (1 hunks)
  • .github/workflows/clp-core-build.yaml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: ubuntu-jammy-deps-image
  • GitHub Check: centos-stream-9-deps-image
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: build-macos (macos-13, false)
  • GitHub Check: build-macos (macos-13, true)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (3)
.github/workflows/clp-core-build-macos.yaml (1)

112-123: Robust Cache Update Implementation
The update step correctly uses a conditional ('pull_request' != github.event_name && 'refs/heads/main' == github.ref) to ensure that the cache is only updated after successful runs on the main branch. This assures that only valid and current outputs (logs and checksums) are saved, reducing redundant lint re-runs. The use of the output from the previous restoration step (${{steps.cache-restore-lint-check-cpp-static-full.outputs.cache-primary-key}}) maintains consistency in cache key usage.

Make sure that the logged outputs in the specified paths (checksums and build/lint-clang-tidy) are always generated by the lint task to avoid stale cache issues.

.github/workflows/clp-core-build.yaml (2)

330-343: Proper Cache Restoration for Ubuntu Lint Job
The restoration step for the ubuntu-jammy-lint job mirrors the macOS implementation well. Using the condition ('schedule' != github.event_name) and a unique per-OS cache key (main-branch-ubuntu-jammy-lint:check-cpp-tidy-static-full) ensures that different OS environments maintain independent caches. This strategy will help skip unnecessary clang-tidy checks when no relevant changes have occurred.

Ensure that excluding scheduled events from this step aligns with your broader testing strategy, as scheduled runs might require a full lint pass.


358-369: Consistent Cache Update Mechanism
The update step is set up to save the computed lint results only on the main branch and not during pull requests, which is critical for maintaining cache integrity. Using the cache key output from the restore step (${{steps.cache-restore-lint-check-cpp-static-full.outputs.cache-primary-key}}) is an effective way to tie both steps together.

No further changes are needed here; this implementation should effectively reduce redundant lint executions and improve workflow speed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

.github/workflows/clp-core-build.yaml:344

  • [nitpick] Consider renaming the cache key to reflect 'static' as used in other parts of the task (e.g., 'lint:check-cpp-static-full') to ensure consistency across the configuration.
key: "main-branch-ubuntu-jammy-lint:check-cpp-tidy-static-full"

.github/workflows/clp-core-build-macos.yaml:106

  • [nitpick] Consider aligning the cache key naming with the rest of the workflow by using 'lint:check-cpp-static-full' instead of 'lint:check-cpp-tidy-static-full' to avoid potential confusion.
key: "main-branch-${{matrix.os}}-lint:check-cpp-tidy-static-full"

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