Skip to content

Fix yarn/bundle install in CI #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

alexeyr-ci2
Copy link
Collaborator

@alexeyr-ci2 alexeyr-ci2 commented Apr 18, 2025

Summary

  • Cache actions for node_modules and vendor/bundle should use lockfile hash in their key, not the main package.json/Gemfile
  • Run yarn install and bundle install in frozen lockfile mode to be sure the lockfiles are updated.

Pull Request checklist

  • [ ] Add/update test to cover these changes
  • [ ] Update documentation
  • [ ] Update CHANGELOG file

This change is Reviewable

Summary by CodeRabbit

  • Chores
    • Improved workflow dependency caching by switching cache keys to use lockfiles for both Node and Ruby dependencies, enhancing cache accuracy.
    • Updated environment variables and install commands to enforce stricter or conditional dependency installation based on the matrix version, increasing consistency and reliability in CI runs.
    • Adjusted Yarn and bundle install steps to use the --frozen-lockfile flag and BUNDLE_FROZEN variable where appropriate.

Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

The updates modify several GitHub Actions workflow YAML files to improve dependency management and caching strategies. Environment variables such as BUNDLE_FROZEN are now set dynamically based on matrix versions, and the --frozen-lockfile flag for Yarn installs is conditionally applied, typically enforced only on the newest Node versions. Cache keys for Ruby gems and Node modules now use lockfiles (Gemfile.lock and yarn.lock) instead of package manifests or gemspecs, ensuring more accurate cache invalidation. These changes collectively enhance the consistency and reliability of dependency installations during CI runs.

Changes

File(s) Change Summary
.github/workflows/examples.yml
.github/workflows/main.yml
Yarn install commands now conditionally use --frozen-lockfile only for 'newest' matrix versions. Environment variable BUNDLE_FROZEN is set dynamically in examples.yml. Cache keys for Ruby gems and Node modules now use Gemfile.lock and yarn.lock respectively, replacing previous references to gemspecs, development dependencies, or package.json.
.github/workflows/lint-js-and-ruby.yml Sets BUNDLE_FROZEN=true globally. Updates Ruby gem cache keys to use Gemfile.lock for both main and dummy apps. Yarn install steps for renderer and dummy app now use --frozen-lockfile. Dummy app's node modules cache key now uses spec/dummy/yarn.lock. The second Yarn install step for the dummy app removes --ignore-scripts and adds --frozen-lockfile.
.github/workflows/package-js-tests.yml Yarn install command for JS unit tests now conditionally adds --frozen-lockfile for 'newest' matrix version only; 'oldest' runs without this flag.
.github/workflows/rspec-package-specs.yml Sets BUNDLE_FROZEN dynamically based on matrix version (false for 'oldest', true otherwise). Changes Ruby gems cache key to use Gemfile.lock instead of react_on_rails.gemspec, combined with matrix version.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Matrix Job
    participant Yarn
    participant Bundler

    GitHub Actions->>Matrix Job: Start job with matrix version
    Matrix Job->>Matrix Job: Set env BUNDLE_FROZEN (dynamic)
    Matrix Job->>Matrix Job: Set Yarn install command (conditional --frozen-lockfile)
    Matrix Job->>Bundler: Install Ruby gems (cache keyed by Gemfile.lock)
    Matrix Job->>Yarn: Install Node modules (cache keyed by yarn.lock)
    Yarn-->>Matrix Job: Node modules installed
    Bundler-->>Matrix Job: Ruby gems installed
    Matrix Job-->>GitHub Actions: Job complete
Loading

Suggested reviewers

  • Judahmeek
  • alexeyr-ci2

Poem

In the warren where workflows hop and run,
We lock our gems and yarn for fun.
With frozen flags and caches neat,
Our CI builds are hard to beat!
No more stale or drifting code,
Just bouncy bunnies on the road.
🐇✨

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 b2163b8 and 43f5fa6.

📒 Files selected for processing (5)
  • .github/workflows/examples.yml (3 hunks)
  • .github/workflows/lint-js-and-ruby.yml (3 hunks)
  • .github/workflows/main.yml (5 hunks)
  • .github/workflows/package-js-tests.yml (1 hunks)
  • .github/workflows/rspec-package-specs.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • .github/workflows/rspec-package-specs.yml
  • .github/workflows/package-js-tests.yml
  • .github/workflows/examples.yml
  • .github/workflows/main.yml
  • .github/workflows/lint-js-and-ruby.yml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: rspec-package-tests (oldest)
  • GitHub Check: build
  • GitHub Check: rspec-package-tests (newest)

🪧 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 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.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-actions-cache branch 4 times, most recently from 4c8a153 to 8877840 Compare April 18, 2025 10:53
@alexeyr-ci2 alexeyr-ci2 marked this pull request as ready for review April 18, 2025 13:15
@alexeyr-ci2 alexeyr-ci2 requested a review from Judahmeek April 18, 2025 13:15
Copy link
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: 6

🧹 Nitpick comments (1)
.github/workflows/lint-js-and-ruby.yml (1)

45-45: Review static -oldest cache key suffix
Both Ruby gem cache keys are suffixed with -oldest, but this job has no matrix.versions. Confirm if the suffix is intentional or should be removed/standardized.

Also applies to: 71-71

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d09352e and 8877840.

📒 Files selected for processing (5)
  • .github/workflows/examples.yml (2 hunks)
  • .github/workflows/lint-js-and-ruby.yml (2 hunks)
  • .github/workflows/main.yml (3 hunks)
  • .github/workflows/package-js-tests.yml (1 hunks)
  • .github/workflows/rspec-package-specs.yml (2 hunks)
🔇 Additional comments (11)
.github/workflows/rspec-package-specs.yml (2)

15-16: Dynamically configuring BUNDLE_FROZEN environment variable
Correctly sets BUNDLE_FROZEN to 'false' for the oldest variant and 'true' otherwise, enforcing frozen bundle installs only when intended.


43-43: Switch cache key to Gemfile.lock
Using hashFiles('Gemfile.lock') combined with ${{ matrix.versions }} ensures accurate cache invalidation based on the actual locked dependencies and the matrix variant.

.github/workflows/main.yml (4)

59-59: Use spec/dummy/yarn.lock for dummy-app node modules cache
Switching the cache key to hashFiles('spec/dummy/yarn.lock') plus ${{ matrix.versions }} ensures precise invalidation based on the dummy app’s actual dependencies.


129-129: Use Gemfile.lock for root Ruby gems cache
Changing the cache key to hashFiles('Gemfile.lock') plus ${{ matrix.versions }} standardizes the strategy and improves cache accuracy.


134-134: Use spec/dummy/Gemfile.lock for dummy-app gems cache
Aligns the dummy app cache key with its lockfile to ensure proper cache invalidation.


139-139: Cache dummy-app node modules by lockfile
Using hashFiles('spec/dummy/yarn.lock') with ${{ matrix.versions }} ensures the cache reflects the correct dependencies.

.github/workflows/examples.yml (2)

15-17: Standardize SKIP_YARN_COREPACK_CHECK and BUNDLE_FROZEN in job env
Moving SKIP_YARN_COREPACK_CHECK inside env and adding BUNDLE_FROZEN per matrix version aligns this workflow with others, enforcing frozen installs consistently.


70-70: Switch main Ruby gems cache to Gemfile.lock
Using hashFiles('Gemfile.lock') combined with ${{ matrix.versions }} improves cache precision based on actual dependencies.

.github/workflows/lint-js-and-ruby.yml (3)

11-12: Enforce frozen bundle installs unconditionally
Setting BUNDLE_FROZEN: true ensures all bundle installs respect the lockfile.


48-48: Use frozen lockfile for Yarn installs
Including --frozen-lockfile guarantees Yarn adheres strictly to yarn.lock.


56-56: Use frozen lockfile for dummy-app Yarn installs
Consistent use of --frozen-lockfile for the dummy app aligns with the dependency strategy.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-actions-cache branch from b2163b8 to 43f5fa6 Compare April 18, 2025 13:40
Comment on lines +49 to +50
cache: yarn
cache-dependency-path: '**/yarn.lock'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data and https://github.com/actions/cache/blob/main/examples.md#node---npm for why this is preferred over caching node_modules. In our case it also avoids duplication between node_modules and spec/dummy/node_modules.

- name: Save root ruby gems to cache
uses: actions/cache@v4
with:
path: vendor/bundle
key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-${{ matrix.versions }}
key: package-app-gem-cache-${{ hashFiles('Gemfile.lock') }}-${{ matrix.versions }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

setup-ruby documentation says action/cache isn't enough and action/cache docs link to it.

But I am awaiting their reply for what to do for multiple Gemfile.locks in a single repo.

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