diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 559904d..9a4dda8 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,4 @@ -name: Check Branch +name: CI Workflow on: push: @@ -7,7 +7,7 @@ on: branches: [main] jobs: - Check-Branch: + Test-Ruby: runs-on: ubuntu-latest strategy: @@ -18,18 +18,23 @@ jobs: - '3.2' - '3.3' + name: Ruby ${{ matrix.ruby }} + steps: - name: Check out repository code uses: actions/checkout@v4 - - name: Install dependencies + - name: Install Ruby uses: ruby/setup-ruby@v1 with: bundler-cache: true + bundler-with: development ruby-version: ${{ matrix.ruby }} - - name: Run unit tests - run: bundle exec rake + - name: Debug Environment + run: | + echo "Ruby version: $(ruby -v)" + echo "Bundler version: $(bundle -v)" - - name: Run Rubocop - run: bundle exec rubocop + - name: Run CI pipeline for the gem + run: bin/check diff --git a/.rubocop.yml b/.rubocop.yml index e03d38e..ba2a80d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,6 +5,7 @@ require: AllCops: NewCops: enable SuggestExtensions: false + TargetRubyVersion: 3.0 Metrics/MethodLength: Exclude: diff --git a/Gemfile b/Gemfile index 0bf5bac..88232e4 100644 --- a/Gemfile +++ b/Gemfile @@ -3,12 +3,14 @@ source 'https://rubygems.org' # Specify your gem's dependencies in scalar_ruby.gemspec -# gemspec gem 'minitest' gem 'rake' -gem 'rubocop', '~> 1.68' -gem 'rubocop-minitest', '~> 0.36.0' -gem 'rubocop-performance', '~> 1.23' +group :development do + gem 'bundler-audit', require: false + gem 'rubocop' + gem 'rubocop-minitest' + gem 'rubocop-performance' +end diff --git a/Gemfile.lock b/Gemfile.lock index deec0c8..7db7539 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,48 +7,55 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - json (2.8.2) - language_server-protocol (3.17.0.3) - minitest (5.25.1) + bundler-audit (0.9.2) + bundler (>= 1.2.0, < 3) + thor (~> 1.0) + json (2.9.1) + language_server-protocol (3.17.0.4) + minitest (5.25.4) parallel (1.26.3) - parser (3.3.6.0) + parser (3.3.7.1) ast (~> 2.4.1) racc racc (1.8.1) rainbow (3.1.1) rake (13.2.1) - regexp_parser (2.9.2) - rubocop (1.68.0) + regexp_parser (2.10.0) + rubocop (1.71.2) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.38.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.36.1) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.38.0) parser (>= 3.3.1.0) rubocop-minitest (0.36.0) rubocop (>= 1.61, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-performance (1.23.0) + rubocop-performance (1.23.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) - unicode-display_width (2.6.0) + thor (1.3.2) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) PLATFORMS arm64-darwin-23 ruby DEPENDENCIES + bundler-audit minitest rake - rubocop (~> 1.68) - rubocop-minitest (~> 0.36.0) - rubocop-performance (~> 1.23) + rubocop + rubocop-minitest + rubocop-performance scalar_ruby! BUNDLED WITH diff --git a/README.md b/README.md index 9f218e8..b7f1dcc 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,14 @@ This gem simplifies the integration of [Scalar](https://scalar.com), a modern open-source developer experience platform for your APIs into Ruby applications. +## Requirements + +This gem is tested and supported on the following Ruby versions: + +- Ruby 3.0, 3.1, 3.2, 3.3 + +Other Ruby versions might work but are not officially supported. + ## Installation Add the gem to your application's Gemfile by executing in the terminal: @@ -15,6 +23,11 @@ bundle add scalar_ruby ## Getting Started +#### Integrations +You can use in-build generator to setup gem into [Ruby in Rails](https://rubyonrails.org) framework followed by instructions: + +Setup gem with [Ruby on Rails](lib/scalar/installers/rails/README.md) + Statistically, you will likely use the gem for the Ruby on Rails application, so here are instructions on how to set up the Scalar for this framework. In the future, we'll add examples for other popular Ruby frameworks. Once you have installed the gem, go to `config/routes.rb` and mount the `Scalar::UI` to your application. diff --git a/bin/check b/bin/check new file mode 100755 index 0000000..08ed6cb --- /dev/null +++ b/bin/check @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e # Exit immediately if a command exits with a non-zero status +set -o pipefail # Fail if any part of a pipeline fails + +# Run bundle audit (checks for vulnerabilities in gem dependencies) +echo "๐Ÿ” [ bin/check ] Analyzing Ruby gems for security vulnerabilities..." +bundle exec bundle-audit check --update || { echo "โŒ [ bin/check ] Bundle audit failed"; exit 1; } + +# Run tests +echo "๐Ÿงช [ bin/check ] Running Minitest tests..." +bundle exec rake test || { echo "โŒ [ bin/check ] Tests failed"; exit 1; } + +# Run RuboCop (linter and style checker) +echo "๐Ÿค– [ bin/check ] Running Rubocop..." +bundle exec rubocop || { echo "โŒ [ bin/check ] Rubocop failed"; exit 1; } + +echo "โœ… [ bin/check ] Done." diff --git a/lib/generators/scalar/install/USAGE b/lib/generators/scalar/install/USAGE new file mode 100644 index 0000000..0df0a84 --- /dev/null +++ b/lib/generators/scalar/install/USAGE @@ -0,0 +1,11 @@ +Description: + Installs Scalar, modern open-source developer experience platform for your APIs + +Example: + bin/rails generate scalar:install + +This will update: + config/routes.rb + +This will create: + config/initializers/scalar.rb diff --git a/lib/generators/scalar/install/install_generator.rb b/lib/generators/scalar/install/install_generator.rb new file mode 100644 index 0000000..0db086d --- /dev/null +++ b/lib/generators/scalar/install/install_generator.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Scalar + module Generators + class InstallGenerator < ::Rails::Generators::Base + source_root File.expand_path('templates', __dir__) + + desc 'Installs Scalar into a Rails app' + + def introduction + say <<~INTRODUCTION + + ๐Ÿ‘‹ Let's install Scalar into your Rails app! + + INTRODUCTION + end + + def update_routes + insert_into_file Rails.root.join('config/routes.rb'), after: 'Rails.application.routes.draw do' do + "\n mount Scalar::UI, at: \"/docs\"" + end + end + + def create_initializer + template 'initializer.rb', 'config/initializers/scalar.rb' + end + + def farewell + say <<~FAREWELL + + We're done! Your can run "/docs" to observe a scalar API platform + + FAREWELL + end + end + end +end diff --git a/lib/generators/scalar/install/templates/initializer.rb b/lib/generators/scalar/install/templates/initializer.rb new file mode 100644 index 0000000..fcaff00 --- /dev/null +++ b/lib/generators/scalar/install/templates/initializer.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +Scalar.setup do |config| + # Specify the specific version of the Scalar. By default it uses the latest one + # + # config.library_url = "https://cdn.jsdelivr.net/npm/@scalar/api-reference" + + # Add custom page title displayed in the browser tab + # + # config.page_title = "API Reference" + + # Pass your API specification. It may be URL or file content in OpenAPI format + # + # config.specification = File.read(Rails.root.join("docs/openapi.yml")) + + # Additional Scalar configuration (e.g. theme) can be set here + # + # config.scalar_configuration = { + # theme: "purple" + # } +end diff --git a/scalar_ruby.gemspec b/scalar_ruby.gemspec index 70a671f..c20a9d3 100644 --- a/scalar_ruby.gemspec +++ b/scalar_ruby.gemspec @@ -19,5 +19,5 @@ Gem::Specification.new do |spec| spec.files = Dir['{lib}/**/*', 'Rakefile', 'README.md'] spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.5.5' + spec.required_ruby_version = '>= 3.0' end