Skip to content

Update logic to handle Cargo caching in GitHub Actions#659

Merged
forstmeier merged 1 commit intomasterfrom
update-cargo-caching
Jan 5, 2026
Merged

Update logic to handle Cargo caching in GitHub Actions#659
forstmeier merged 1 commit intomasterfrom
update-cargo-caching

Conversation

@forstmeier
Copy link
Copy Markdown
Collaborator

@forstmeier forstmeier commented Jan 5, 2026

Overview

Changes

  • add conditional check to "build" command based on environment

Comments

This should help with Rust-based build times in GitHub Actions.

Summary by CodeRabbit

  • Chores
    • Upgraded Docker caching infrastructure for Cargo builds with intelligent environment detection and dynamic strategy selection. The build system now automatically chooses the most efficient caching approach based on execution context, substantially improving overall build performance across various scenarios while maintaining full backward compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 5, 2026

Walkthrough

This pull request modifies the build script to implement environment-aware Docker caching for Cargo builds. It detects whether the build is running in GitHub Actions via the GITHUB_ACTIONS environment variable and conditionally configures Docker buildx cache arguments accordingly. When in GitHub Actions, both GHA and registry caches are utilized with corresponding --cache-from and --cache-to parameters. In other environments, caching falls back to registry-only configuration. The script also outputs environment-specific messages to indicate which caching strategy is active.

Possibly related PRs

Suggested labels

rust

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Update logic to handle Cargo caching in GitHub Actions' clearly and specifically describes the main change: implementing environment-aware caching logic for Cargo builds in GitHub Actions CI/CD.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes Docker build caching for Rust-based builds by adding GitHub Actions-specific cache handling. When running in GitHub Actions, the build process now uses both GitHub Actions cache (gha) and registry cache in a hybrid configuration, while local builds continue using only registry cache.

Key Changes:

  • Added conditional logic to detect GitHub Actions environment
  • Implemented hybrid caching strategy (gha + registry) for CI builds
  • Maintained backward compatibility with local development builds

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

@coderabbitai coderabbitai Bot added the rust label Jan 5, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 (2)
maskfile.md (2)

74-83: Improve error visibility and cache fallback safety.

If the GHA cache backend is unavailable or fails, the build continues without explicit warning. Consider adding error handling or validation to ensure the intended caching strategy is actually in effect, especially given that GHA caching can significantly impact build performance.

🔎 Suggested improvements for error handling and validation
# Validate that docker buildx cache parameters are correctly applied
# Add after docker buildx command or with --verbose flag to confirm cache hits/misses

# Example: Log cache backend info before build
if [ -n "${GITHUB_ACTIONS:-}" ]; then
    echo "Verifying GHA cache backend availability..."
    docker buildx bake --print > /dev/null || echo "WARNING: GHA cache backend may not be available"
fi

# Or add explicit validation in docker buildx build output
docker buildx build \
    --platform linux/amd64 \
    --target ${stage_name} \
    --file applications/${application_name}/Dockerfile \
    --tag ${image_reference}:latest \
    ${cache_from_arguments} \
    ${cache_to_arguments} \
    --load \
    --progress=plain \  # Shows detailed cache output
    .

74-83: GHA cache backend requires GitHub Actions environment variables — verify runner setup if using custom/non-standard environments.

The type=gha cache backend relies on GitHub Actions–provided environment variables (ACTIONS_CACHE_URL, ACTIONS_RESULTS_URL, ACTIONS_RUNTIME_TOKEN), not just the presence of GITHUB_ACTIONS. In standard GitHub-hosted runners, these are automatically set and the code will work as written. However, if using custom runners or self-hosted environments, ensure these variables are available—otherwise GHA caching will fail silently. If possible, validate these environment variables in addition to checking GITHUB_ACTIONS, or document this dependency clearly.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec207fb and 1e42cb4.

📒 Files selected for processing (1)
  • maskfile.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run Rust code checks
🔇 Additional comments (1)
maskfile.md (1)

94-102: LGTM on cache argument application.

The conditional cache arguments are correctly applied to the docker buildx command. Variable expansion without quotes is safe here since the arguments are intended to be split on whitespace. The --load flag combined with mode=max registry cache writes should work correctly.

@forstmeier forstmeier merged commit f189ad4 into master Jan 5, 2026
6 checks passed
@forstmeier forstmeier deleted the update-cargo-caching branch January 5, 2026 20:16
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.

2 participants