Skip to content

Guardrails / ruby

Ruby version is declared ​

ruby/version-declared@v1

The project declares the Ruby version it is built and run against, and that version is no older than the configured floor.

Idruby/version-declared
Versionv1
Categoryruby
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsruby

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
rubyThe Bundler project in the project directory: the Ruby version it asks for, the gem sources it resolves from, the gems each manifest declares with their groups and origins, and the lock file beside them. The Gemfile is Ruby rather than a declaration, so what it declares conditionally is not seen and scanned says so.projectDir

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "ruby/version-declared@v1",
              "severity": "warning",
              "with": {
                  "projectDir": ".",
                  "minVersion": "3.0"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR
minVersionOldest Ruby version accepted. A declared version below this is a violation.3.0GUARDRAIL_INPUT_MINVERSION

How to fix ​

Declare the interpreter where developers' shells and deploy tooling already look: a .ruby-version file naming the exact release, or the Gemfile next to your gems:

ruby
ruby "3.3.1"

Without one, the interpreter is whichever Ruby the runner and the deploy image happen to have, so a syntax or standard library difference is discovered in production instead of on the laptop where it was introduced.

More in ruby ​

  • ruby/lockfile-committed. The project commits Gemfile.lock, so an install of the same commit resolves the same gem versions.
  • ruby/no-git-dependencies. No gem the manifests declare is fetched from a git repository instead of a gem source. The Gemfile is Ruby code, not a declaration, so it is read by pattern. A git gem that is found is a real finding, but finding none doesn't prove there are none: a gem added inside a condition, a loop or an eval isn't detected.
  • ruby/single-gem-source. The Gemfile resolves gems from at most one source, and that source is one the repository trusts. The Gemfile is Ruby code, not a declaration, so it is read by pattern. A second source that is found is a real finding, but finding only one doesn't prove there is only one: a source named inside a condition, a loop or an eval isn't detected.

All 4 ruby guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412