Working with RubyGems

CodeScoring.Save supports Bundler and the gem CLI through the RubyGems compact index:

  • Proxy — installs gems from rubygems.org or another compact-index source and caches .gem files on first download.
  • Hosted — stores your own gems and updates the index when you publish or yank a version.

Creating a Repository

Open a project, click Create repository, and select Format: RubyGems and Type: Proxy or Hosted. For a proxy, set Proxy URL to the upstream root (for example, https://rubygems.org) and Cache TTL, seconds for index metadata. A hosted repository needs no upstream.

Example: create a proxy through the API with an admin token:

curl -X POST https://save.example.com/api/v1/repos \
  -H "Authorization: Bearer $ADMIN_JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "project": "infra",
    "name": "rubygems-proxy",
    "format": "rubygems",
    "repository_type": "proxy",
    "remote_url": "https://rubygems.org",
    "enabled": true
  }'

Client Configuration

Copy the repository URL from Useful snippets. In your Gemfile, use it as the source:

source "https://save.example.com/cs-save/rubygems/infra/rubygems-proxy/"
gem "rack"

For a private repository, configure Basic authentication for that source. Here SAVE_API_KEY is the API key of a robot account with artifacts.download permission:

GEM_SOURCE=https://save.example.com/cs-save/rubygems/infra/rubygems-proxy
SAVE_USER='sa$ci'
bundle config set --global "$GEM_SOURCE/" "$SAVE_USER:$SAVE_API_KEY"
bundle install

To install without Bundler, pass credentials in the source URL. --clear-sources makes gem use only the specified repository for this install:

gem install rack --clear-sources \
  --source "https://${SAVE_USER}:${SAVE_API_KEY}@save.example.com/cs-save/rubygems/infra/rubygems-proxy/"

For internal gems, use the hosted repository URL instead.

Publishing to a Hosted Repository

Build the package from its .gemspec, then push it with artifacts.upload permission. Include Bearer in GEM_HOST_API_KEY: gem push and gem yank send its value unchanged as the Authorization header.

GEM_HOST=https://save.example.com/cs-save/rubygems/infra/rubygems-hosted
export GEM_HOST_API_KEY="Bearer $SAVE_API_KEY"
gem build my_gem.gemspec
gem push my_gem-1.0.0.gem --host "$GEM_HOST"

To withdraw a version, use gem yank with artifacts.delete permission:

gem yank my_gem -v 1.0.0 --host "$GEM_HOST"

Without --platform, yank selects the ruby build. For a native build, add its platform, e.g. --platform x86_64-linux. Only the selected build disappears from the index and downloads. A published name/version/platform cannot be pushed again, even after a yank or deletion (409); publish a new version instead.

Troubleshooting

Check the versions and dependencies known to Save for a specific gem:

curl -fsS -u "$SAVE_USER:$SAVE_API_KEY" "$GEM_SOURCE/info/rack"
  • Install works, but push is rejected. Use the hosted URL for --host. Bundler's read credentials do not configure gem push; check GEM_HOST_API_KEY and upload permission.
  • The client requests specs.4.8.gz. Use a compact-index client. Save does not serve the legacy full index or remote search.
  • The hosted index is out of sync. With repo.update permission, run curl -fsS -X POST -H "Authorization: Bearer $SAVE_API_KEY" "$GEM_HOST/rebuild-index". Normal pushes and yanks update the index automatically.
Was this page helpful?