Week 4 - CircuitVerse@GSOC'23

Week 4 - CircuitVerse@GSOC'23

This week was interesting and frustrating at the same time. The maximum time went to explore solutions and resolving the issues with specific library packages. This time everything does not go as planned.

The scheduled task for this week was

  • Write RBS Annotations for the codebase

RBS

What is RBS?

RBS is a type annotation system introduced in the Ruby programming language. Its purpose is to bring static typing capabilities to Ruby code. We can verify the type signature by using various tools like [steep, rbs, etc.]

RBS is released officially by Ruby.

Interesting Features

  • Type Safety: RBS helps catch type-related errors early, improving code reliability.

  • Tooling Support: Static type information enables advanced code editors to offer autocompletion and accurate error detection, enhancing developer productivity.

  • Documentation and Readability: RBS annotations serve as documentation, making code easier to understand and maintain.

Setup

  • Install rbs_rails gem

      gem install rbs_rails
    
  • Generate tasks

      bin/rails g rbs_rails:install
    
  • Run this to generate the rbs collection configuration file

      bundle exec rbs collection init
    
  • Now simply run this to download the required gem's rbs file

      bundle exec rbs collection install
    
  • We are going to use steep gem to type checking

  • So, install steep gem

      bundle install steep
    
  • Create Steepfile with this configuration

      target :app do
        signature "sig"
      end
    
  • As per the configuration, it will check sig folder for our writer rbs annotation files for our codebase

Issues

But one problem with RBS is -> As it's fairly new to the market, there is not much support for RBS in all the libraries. So we face various issues regarding that.

In our case, while using rbs validate it was throwing RBS::DuplicatedMethodDefinitionError due to conflicting rbs code of meta-tags and activesupport gem.

After searching for various solutions and taking suggestions from the maintainer, the final solution to fix the issue was -

  • Add meta-tags gem to ignore the list of rbs collection configurations like

      gems:
        # Skip loading rbs gem's RBS.
        # It's unnecessary if you don't use rbs as a library.
        - name: rbs
          ignore: true
        - name: steep
          ignore: true
    
  • Copy the rbs file of meta-tags gem

  • Modify them to remove duplicate definition issue

  • And then copy-paste those files in sig/vendor/meta-tags folder

References -

Discussion Thread for the issue - https://github.com/ruby/rbs/issues/1359

PR - https://github.com/CircuitVerse/CircuitVerse/pull/3807/

Undercover CI

Undercover is a great tool to analyze untested code of a commit and do PR reviews.

SimpleCov is mainly used to generate the test details and undercover analyze the generated Lcov file.

Setup SimpleCov to generate the Lcov file

  • Install simplecov and simplecov-lcov gem to :test group

  • In the config/environments/test.rb file, paste this configuration file at the top

      require "simplecov"
      require "simplecov-lcov"
      SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
      SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
      SimpleCov.start do
        add_filter(/^\/spec\//) # For RSpec, use `test` for MiniTest
        enable_coverage(:branch)
      end
    
  • Now we need to load all the code beforehand for this analysis

  • So, mark config.eager_load = true in configuration of test environment

  • Now when we run our test suite, it will generate lcov file under coverage/lcov/<project_name>.lcov file.

Now, We need to setup undercover CI for PR review

The first and easier option is to use https://undercover-ci.com/ which has simple steps for installation. But the issue here is , it's paid for organization

So,we keep searching and found a opensource project undercover-checkstyle which can review the PR by using undercover CLI tool and use reviewdog to do the PR Review

For this, add undercover-checkstyle gem under :test group in Gemfile

In the CI workflow add this configuration

- uses: aki77/delete-pr-comments-action@v1
  with:
   token: ${{ secrets.GITHUB_TOKEN }}
   bodyContains: "[undercover]"
   noReply: "true"
- name: Run reviewdog
  env:
    REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.github_token }}
  run: |
    git fetch --no-tags
    reviewdog -reporter=github-pr-review -runners=undercover --fail-on-error

After the setup, it will provide a review of any PR.

Just for example, the github-actions bot will give a review like this. This will also delete previous comments to make the PR Review clean.

PR - CircuitVerse/CircuitVerse#3812 CircuitVerse/CircuitVerse#3818


That's all for this week. Subscribe to the newsletter for more updates.