Skip to content
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

Unable to pick 3.2.2 version when only git diff files are in the scope #580

Closed
2 tasks done
mpurusottamc opened this issue Mar 26, 2024 · 5 comments
Closed
2 tasks done

Comments

@mpurusottamc
Copy link

Ensure the following before filing this issue

  • I verified it reproduces with the latest version with - uses: ruby/setup-ruby@v1 (see Versioning policy)

  • I tried to reproduce the issue locally by following the workflow steps (including all commands done by ruby/setup-ruby, except for Downloading Ruby & Extracting Ruby),
    and it did not reproduce locally (if it does reproduce locally, it's not a ruby/setup-ruby issue)

Are you running on a GitHub-hosted runner or a self-hosted runner?

GitHub-hosted runner

Link to the failed workflow job (must be a public workflow job, so the necessary information is available)

NA

Any other notes?

I am trying to run rubocop only on the changed files. For that, i am checking out the PR branch. But, when i try to install ruby 3.2.2, it throws an error.

Here's the error (with debug logs enabled):

##[debug]Evaluating condition for step: 'Install Dependencies'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Install Dependencies
##[debug]Loading inputs
##[debug]Loading env
Run bundle install --jobs 4 --retry 3
##[debug]/usr/bin/bash -e /home/runner/work/_temp/383fcb74-9a47-4dc0-88a6-5c[2](https://github.com/<org>/<repo_name>/actions/runs/8440722176/job/23118618377?pr=1463#step:4:2)9a5b1c67e.sh
Your Ruby version is [3](https://github.com/<org>/<repo_name>/actions/runs/8440722176/job/23118618377?pr=1463#step:4:3).2.2, but your Gemfile specified 
Error: Process completed with exit code 1[8](https://github.com/<org>/<repo_name>/actions/runs/8440722176/job/23118618377?pr=1463#step:4:8).
##[debug]Finishing: Install Dependencies

Screenshot:
Screenshot 2024-03-26 at 11 10 47 AM

Here's my entire yml file:

name: CI

on: [ pull_request_target ]

jobs:
  rubocop:
    name: RuboCop Auto-fix
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.2.2'

      - name: Install Dependencies
        run: bundle install --jobs 4 --retry 3

      - name: Run RuboCop Auto-correct
        run: |
          # Run RuboCop auto-correct on the changed files
          bundle exec rubocop --auto-correct $(git diff --name-only ${{ github.event.before }}...${{ github.event.after }} | grep '\.rb$')

      - name: Commit Changes
        run: |
          git config --global user.name "GitHub Actions"
          git config --global user.email "actions@users.noreply.github.com"
          git add .
          if git diff --quiet; then
            echo "No changes to commit"
          else
            git commit -m "Auto-fix RuboCop offenses"
            git push
          fi

Any help is much appreciated.

@eregon
Copy link
Member

eregon commented Mar 26, 2024

That should repro locally by checking out that branch + running bundle install on Ruby 3.2.2.
It seems a mistmatch between the version specified in the Gemfile and the version passed to setup-ruby.
In any case, it seems pretty clear this is not a setup-ruby issue.

@mpurusottamc
Copy link
Author

@eregon on the local machine, I am able to checkout and run bundle install with 3.2.2.

In this case though, since the CI job is checking out only the files in the PR, it does not have access to Gemfile or .ruby-version file. Is there a way to skip the check for Gemfile or .ruby-version and install the version specific in the ruby-version parameter?

@eregon
Copy link
Member

eregon commented Mar 27, 2024

setup-ruby respects the version you gave it, so it does install Ruby 3.2.2.

The issue if you don't checkout the Gemfile is there is no way to bundle install, so that's a bug of your workflow.

@eregon eregon closed this as completed Mar 27, 2024
@eregon
Copy link
Member

eregon commented Mar 27, 2024

According to the workflow you posted it checks out all files, no?

      - name: Checkout Code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

But anyway, the command that fails is run: bundle install --jobs 4 --retry 3, this has nothing to do with setup-ruby as far as I can see, it fails after it.

@mpurusottamc
Copy link
Author

Thanks for your prompt response @eregon. Yes, I misunderstood :(. checkout step checks out all files.

Adding ruby version to Gemfile to resolve dependency installation issue.

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

No branches or pull requests

2 participants