New gem generator

Generate a new gem scaffold with some goodies
Icons/chart bar
Used 23 times
Created by
V Vladimir Dementyev

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/Vqqs8d"
Template Source

Review the code before running this template on your machine.

require "date"

say "👋 Let's scaffold your new gem!\n"

name = nil

loop do
  name = ask("What's gonna be the name of your gem?") || ""
  if name.empty?
    say "Hm, empty name doesn't work. Let's try again"
  else
    break
  end
end

root_dir = ask("Where do you want to store the code? (Default: #{File.join(Dir.pwd, name)})")

if root_dir.nil? || root_dir.empty?
  root_dir = File.join(Dir.pwd, name)
end

gem_path = name_path = name.gsub("-", "/")
human_name = name.split(/[-_]/).map(&:capitalize).join(" ")
module_name = name.split("-").map do |mod|
  mod.split("_").map(&:capitalize).join
end.join("::")

author = nil

loop do
  author = ask("What's your name? (For gemspec, license, etc.)") || ""
  if author.empty?
    say "Hm, empty name doesn't work. Let's try again"
  else
    break
  end
end

email = ask("What's your email? (for gemspec)")
use_rails = yes? "Does this library meant to be used with Rails? (So we can add Rails-related dev and test stuff)"
use_ruby_next = yes? "Would you like to use Ruby Next (so you can use modern syntax/APIs while supporting older Ruby versions)?"
use_github = yes? "Do you plan to host your code on GitHub?"

if use_github
  repo_name = ask("What's the GitHub repo for the project? (\"<org>/<name>\")")
  github_user = ask("What's your GitHub username? (for issue templates)")
end
use_ga = yes? "Would you like to configure GitHub Actions?"

if use_ga
  use_jruby = yes? "Do you want to run tests against JRuby? (Recommended)"
end

lint_docs = yes? "Would you like to install documentation linting tools (mdlint, rubocop markdown, forspell)?"
use_rspec = false

loop do
  testing_library = ask("Which library do you want to use for testing? RSpec (1), Minitest (2)") || ""

  testing_library = testing_library.chomp

  if %w[1 2].include?(testing_library)
    use_rspec = testing_library == "1"
    break
  else
    say "Please, choose 1 or 2"
  end
end

# Move to the destination folder
inside(root_dir) do

  # Base files
  file ".gitignore", ERB.new(
    *[
  <<~'TCODE'
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache
*.iml
.idea/

# Sublime
*.sublime-project
*.sublime-workspace

# OS or Editor folders
.DS_Store
.cache
.project
.settings
.tmproj
Thumbs.db

.bundle/
log/*.log
pkg/
spec/dummy/db/*.sqlite3
spec/dummy/db/*.sqlite3-journal
spec/dummy/tmp/

Gemfile.lock
Gemfile.local
.rspec-local
.ruby-version
*.gem

tmp/
.rbnext/

gemfiles/*.lock

  TCODE
  ], trim_mode: "<>").result(binding)
  file ".gem_release.yml", ERB.new(
    *[
  <<~'TCODE'
bump:
  file: lib/<%= gem_path %>/version.rb
  skip_ci: true

  TCODE
  ], trim_mode: "<>").result(binding)
  file "CHANGELOG.md", ERB.new(
    *[
  <<~'TCODE'
# Change log

## master
  TCODE
  ], trim_mode: "<>").result(binding)
  file "Gemfile", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

source "https://rubygems.org"

gem "debug", platform: :mri

gemspec

eval_gemfile "gemfiles/rubocop.gemfile"

local_gemfile = "#{File.dirname(__FILE__)}/Gemfile.local"

if File.exist?(local_gemfile)
  eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
<% if use_rails %>
else
  gem "rails", "~> 7.0"
<% end %>
end

  TCODE
  ], trim_mode: "<>").result(binding)
  file "#{name}.gemspec", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

require_relative "lib/<%= name_path %>/version"

Gem::Specification.new do |s|
  s.name = "<%= name %>"
  s.version = <%= module_name %>::VERSION
  s.authors = ["<%= author %>"]
  s.email = ["<%= author %>"]
  s.homepage = "https://github.com/<%= repo_name %>"
  s.summary = "Example description"
  s.description = "Example description"

  s.metadata = {
    "bug_tracker_uri" => "https://github.com/<%= repo_name %>/issues",
    "changelog_uri" => "https://github.com/<%= repo_name %>/blob/master/CHANGELOG.md",
    "documentation_uri" => "https://github.com/<%= repo_name %>",
    "homepage_uri" => "https://github.com/<%= repo_name %>",
    "source_code_uri" => "https://github.com/<%= repo_name %>"
  }

  s.license = "MIT"

<% if use_ruby_next %>
  s.files = Dir.glob("lib/**/*") + Dir.glob("lib/.rbnext/**/*") + Dir.glob("bin/**/*") + %w[README.md LICENSE.txt CHANGELOG.md]
<% else %>
  s.files = Dir.glob("lib/**/*") + Dir.glob("bin/**/*") + %w[README.md LICENSE.txt CHANGELOG.md]
<% end %>
  s.require_paths = ["lib"]
  s.required_ruby_version = ">= 2.7"

  s.add_development_dependency "bundler", ">= 1.15"
<% if use_rails %>
  s.add_development_dependency "combustion", ">= 1.1"
<% end %>
  s.add_development_dependency "rake", ">= 13.0"
<% if use_rspec %>
  s.add_development_dependency "rspec", ">= 3.9"
<% else %>
  s.add_development_dependency "minitest", "~> 5.0"
<% end %>

<% if use_ruby_next %>
  # When gem is installed from source, we add `ruby-next` as a dependency
  # to auto-transpile source files during the first load
  if ENV["RELEASING_GEM"].nil? && File.directory?(File.join(__dir__, ".git"))
    s.add_runtime_dependency "ruby-next", ">= 0.15.0"
  else
    s.add_dependency "ruby-next-core", ">= 0.15.0"
  end
<% end %>
end
  TCODE
  ], trim_mode: "<>").result(binding)
  file "LICENSE.txt", ERB.new(
    *[
  <<~'TCODE'
Copyright (c) <%= Date.today.year %> <%= author %>

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  TCODE
  ], trim_mode: "<>").result(binding)
  file "README.md", ERB.new(
    *[
  <<~'TCODE'
[![Gem Version](https://badge.fury.io/rb/<%= name %>.svg)](https://rubygems.org/gems/<%= name %>)
<% if use_ga %>
[![Build](https://github.com/<%= repo_name %>/workflows/Build/badge.svg)](https://github.com/palkan/<%= name %>/actions)
<% if use_jruby %>
[![JRuby Build](https://github.com/<%= repo_name %>/workflows/JRuby%20Build/badge.svg)](https://github.com/<%= repo_name %>/actions)
<% end %>
<% end %>

# <%= human_name %>

TBD

## Installation

Adding to a gem:

```ruby
# my-cool-gem.gemspec
Gem::Specification.new do |spec|
  # ...
  spec.add_dependency "<%= name %>"
  # ...
end
```

Or adding to your project:

```ruby
# Gemfile
gem "<%= name %>"
```

### Supported Ruby versions

- Ruby (MRI) >= 2.7.0
<% if use_jruby %>
- JRuby >= 9.3.0
<% end %>

## Usage

TBD

## Contributing

Bug reports and pull requests are welcome on GitHub at [https://github.com/<%= repo_name %>](https://github.com/<%= repo_name %>).

## Credits

This gem is generated via [`newgem` template](https://github.com/palkan/newgem) by [@palkan](https://github.com/palkan).

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
  TCODE
  ], trim_mode: "<>").result(binding)
  file "RELEASING.md", ERB.new(
    *[
  <<~'TCODE'
# How to release a gem

This document describes a process of releasing a new version of a gem.

1. Bump version.

```sh
git commit -m "Bump 1.<x>.<y>"
```

We're (kinda) using semantic versioning:

- Bugfixes should be released as fast as possible as patch versions.
- New features could be combined and released as minor or patch version upgrades (depending on the _size of the feature_—it's up to maintainers to decide).
- Breaking API changes should be avoided in minor and patch releases.
- Breaking dependencies changes (e.g., dropping older Ruby support) could be released in minor versions.

How to bump a version:

- Change the version number in `lib/<%= name_path %>/version.rb` file.
- Update the changelog (add new heading with the version name and date).
- Update the installation documentation if necessary (e.g., during minor and major updates).

2. Push code to GitHub and make sure CI passes.

```sh
git push
```

3. Release a gem.
<% if use_ruby_next %>

```sh
make release
```

Under the hood we generated pre-transpiled files with Ruby Next and use [gem-release](https://github.com/svenfuchs/gem-release) to publish a gem. Then, a Git tag is created and pushed to the remote repo.
<% else %>

```sh
gem release -t
git push --tags
```

We use [gem-release](https://github.com/svenfuchs/gem-release) for publishing gems with a single command:

```sh
gem release -t
```

Don't forget to push tags and write release notes on GitHub (if necessary).
<% end %>
  TCODE
  ], trim_mode: "<>").result(binding)
  file "Rakefile", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

require "bundler/gem_tasks"
<% if use_rspec %>
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

<% else %>
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
  t.libs << "test"
  t.libs << "lib"
  t.test_files = FileList["test/**/*_test.rb"]
  t.warning = false
end

<% end %>
begin
  require "rubocop/rake_task"
  RuboCop::RakeTask.new

  RuboCop::RakeTask.new("rubocop:md") do |task|
    task.options << %w[-c .rubocop-md.yml]
  end
rescue LoadError
  task(:rubocop) {}
  task("rubocop:md") {}
end

<% if use_rspec %>
<% if lint_docs %>
task default: %w[rubocop rubocop:md spec]
<% else %>
task default: %w[rubocop spec]
<% end %>
<% else %>
<% if lint_docs %>
task default: %w[rubocop rubocop:md test]
<% else %>
task default: %w[rubocop test]
<% end %>
<% end %>
  TCODE
  ], trim_mode: "<>").result(binding)
  file ".rubocop.yml", ERB.new(
    *[
  <<~'TCODE'
require:
  - standard

inherit_gem:
  standard: config/base.yml

<% if use_rspec %>
inherit_from:
  - .rubocop/rspec.yml
<% end %>

AllCops:
  Exclude:
    - 'bin/*'
    - 'tmp/**/*'
    - 'Gemfile'
    - 'vendor/**/*'
    - 'gemfiles/**/*'
    - 'lib/.rbnext/**/*'
    - 'lib/generators/**/templates/*.rb'
    - '.github/**/*'
  DisplayCopNames: true
  SuggestExtensions: false
  NewCops: disable
  TargetRubyVersion: 2.7

Standard/BlockSingleLineBraces:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: true

  TCODE
  ], trim_mode: "<>").result(binding)
  file "gemfiles/rubocop.gemfile", ERB.new(
    *[
  <<~'TCODE'
source "https://rubygems.org" do
  <% if lint_docs %>
  gem "rubocop-md", "~> 1.0"
  <% end %>
  <% if use_rspec %>
  gem "rubocop-rspec"
  <% end %>
  gem "standard", "~> 1.0"
end

  TCODE
  ], trim_mode: "<>").result(binding)

  file "lib/#{name}.rb", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true
<% if use_ruby_next %>

require "ruby-next"

require "ruby-next/language/setup"
RubyNext::Language.setup_gem_load_path(transpile: true)
<% end %>

require "<%= name_path %>/version"
<% if use_rails %>
require "<%= name_path %>/railtie" if defined?(Rails::Railtie)
<% end %>
  TCODE
  ], trim_mode: "<>").result(binding)
  file "lib/#{name_path}/version.rb", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

module <%= module_name %> # :nodoc:
  VERSION = "0.0.1"
end
  TCODE
  ], trim_mode: "<>").result(binding)

  if use_rails
    file "lib/#{name_path}/railtie.rb", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

module <%= module_name %> # :nodoc:
  class Railtie < ::Rails::Railtie # :nodoc:
  end
end
  TCODE
  ], trim_mode: "<>").result(binding)
  end

  if lint_docs
    file ".rubocop-md.yml", ERB.new(
    *[
  <<~'TCODE'
inherit_from: ".rubocop.yml"

require:
  - rubocop-md

AllCops:
  Include:
    - '**/*.md'

  TCODE
  ], trim_mode: "<>").result(binding)
    file ".mdlrc", ERB.new(
    *[
  <<~'TCODE'
rules "~MD013", "~MD033", "~MD029", "~MD034"

  TCODE
  ], trim_mode: "<>").result(binding)
    file "forspell.dict", ERB.new(
    *[
  <<~'TCODE'
# Format: one word per line. Empty lines and #-comments are supported too.
# If you want to add word with its forms, you can write 'word: example' (without quotes) on the line,
# where 'example' is existing word with the same possible forms (endings) as your word.
# Example: deduplicate: duplicate

  TCODE
  ], trim_mode: "<>").result(binding)
  end

  if use_github
    file ".github/PULL_REQUEST_TEMPLATE.md", ERB.new(
    *[
  <<~'TCODE'
<!--
  First of all, thanks for contributing!

  If it's a typo fix or minor documentation update feel free to skip the rest of this template!
-->

## What is the purpose of this pull request?

<!--
  If it's a bug fix, then link it to the issue, for example:

  Fixes #xxx
-->

## What changes did you make? (overview)

## Is there anything you'd like reviewers to focus on?

## Checklist

- [ ] I've added tests for this change
- [ ] I've added a Changelog entry
- [ ] I've updated a documentation

  TCODE
  ], trim_mode: "<>").result(binding)
    file ".github/ISSUE_TEMPLATE/bug_report.md", ERB.new(
    *[
  <<~'TCODE'
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: <%= github_user %>

---

## What did you do?

## What did you expect to happen?

## What actually happened?

## Additional context

## Environment

**Ruby Version:**

**Framework Version (Rails, whatever):**

**<%= human_name %> Version:**

  TCODE
  ], trim_mode: "<>").result(binding)
    file ".github/ISSUE_TEMPLATE/feature_request.md", ERB.new(
    *[
  <<~'TCODE'
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: <%= github_user %>

---

## Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

## Describe the solution you'd like

A clear and concise description of what you want to happen.

## Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

## Additional context

Add any other context or screenshots about the feature request here.

  TCODE
  ], trim_mode: "<>").result(binding)
  end

  if use_ruby_next
    file ".rbnextrc", ERB.new(
    *[
  <<~'TCODE'
nextify: |
  ./lib
  --min-version=2.6
  --edge

  TCODE
  ], trim_mode: "<>").result(binding)
    file "Makefile", ERB.new(
    *[
  <<~'TCODE'
default: test

nextify:
	bundle exec rake nextify

test: nextify
	bundle exec rake
	CI=true bundle exec rake

lint:
	bundle exec rubocop

release: test lint
	git status
	RELEASING_GEM=true gem release -t
	git push
	git push --tags

  TCODE
  ], trim_mode: "<>").result(binding)
  end

  if use_rspec
    file ".rspec", ERB.new(
    *[
  <<~'TCODE'
--require spec_helper

  TCODE
  ], trim_mode: "<>").result(binding)
    file "spec/spec_helper.rb", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

begin
  require "debug" unless ENV["CI"]
rescue LoadError
end
<% if use_ruby_next %>

require "ruby-next/language/runtime"

if ENV["CI"] == "true"
  # Only transpile specs, source code MUST be loaded from pre-transpiled files
  RubyNext::Language.watch_dirs.clear
  RubyNext::Language.watch_dirs << __dir__
end

<% end %>
<% if use_rails %>
ENV["RAILS_ENV"] = "test"

require "combustion"
require "<%= name %>"

begin
  # See https://github.com/pat/combustion
  Combustion.initialize! do
    config.logger = Logger.new(nil)
    config.log_level = :fatal
  end
rescue => e
  # Fail fast if application couldn't be loaded
  $stdout.puts "Failed to load the app: #{e.message}\n#{e.backtrace.take(5).join("\n")}"
  exit(1)
end
<% else %>
require "<%= name %>"
<% end %>

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }

RSpec.configure do |config|
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  config.order = :random
  Kernel.srand config.seed
end
  TCODE
  ], trim_mode: "<>").result(binding)

    file ".rubocop/rspec.yml", ERB.new(
    *[
  <<~'TCODE'
require:
  - rubocop-rspec

RSpec:
  Enabled: false

RSpec/Focus:
  Enabled: true

RSpec/EmptyExampleGroup:
  Enabled: true

RSpec/EmptyLineAfterExampleGroup:
  Enabled: true

RSpec/EmptyLineAfterFinalLet:
  Enabled: true

RSpec/EmptyLineAfterHook:
  Enabled: true

RSpec/EmptyLineAfterSubject:
  Enabled: true

RSpec/HookArgument:
  Enabled: true

RSpec/HooksBeforeExamples:
  Enabled: true

RSpec/ImplicitExpect:
  Enabled: true

RSpec/IteratedExpectation:
  Enabled: true

RSpec/LetBeforeExamples:
  Enabled: true

RSpec/MissingExampleGroupArgument:
  Enabled: true

RSpec/ReceiveCounts:
  Enabled: true

  TCODE
  ], trim_mode: "<>").result(binding)
  else
    file "test/test_helper.rb", ERB.new(
    *[
  <<~'TCODE'
# frozen_string_literal: true

begin
  require "debug" unless ENV["CI"]
rescue LoadError
end

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
<% if use_ruby_next %>

require "ruby-next/language/runtime"

if ENV["CI"] == "true"
  # Only transpile specs, source code MUST be loaded from pre-transpiled files
  RubyNext::Language.watch_dirs.clear
  RubyNext::Language.watch_dirs << __dir__
end

<% end %>
<% if use_rails %>
ENV["RAILS_ENV"] = "test"

require "combustion"
require "<%= name %>"

begin
  # See https://github.com/pat/combustion
  Combustion.initialize! do
    config.logger = Logger.new(nil)
    config.log_level = :fatal
  end
rescue => e
  # Fail fast if application couldn't be loaded
  $stdout.puts "Failed to load the app: #{e.message}\n#{e.backtrace.take(5).join("\n")}"
  exit(1)
end
<% else %>
require "<%= name %>"
<% end %>

Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }

require "minitest/autorun"

  TCODE
  ], trim_mode: "<>").result(binding)
  end

  if use_ga
    file ".github/workflows/test.yml", ERB.new(
    *[
  <<~'TCODE'
name: Build

on:
  push:
    branches:
    - master
  pull_request:

jobs:
  rspec:
    runs-on: ubuntu-latest
    env:
      BUNDLE_JOBS: 4
      BUNDLE_RETRY: 3
      <% if use_rails %>
      BUNDLE_GEMFILE: ${{ matrix.gemfile }}
      <% end %>
      CI: true
    strategy:
      fail-fast: false
      matrix:
        <% if use_rails %>
        ruby: ["2.7"]
        gemfile: ["gemfiles/rails6.gemfile"]
        include:
        - ruby: "2.7"
          gemfile: "gemfiles/rails6.gemfile"
        - ruby: "3.2"
          gemfile: "gemfiles/railsmain.gemfile"
        - ruby: "3.1"
          gemfile: "gemfiles/rails7.gemfile"
        <% else %>
        ruby: ["2.7", "3.0", "3.1", "3.2"]
        <% end %>
    steps:
    - uses: actions/checkout@v3
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby }}
        bundler-cache: true
    <% if use_ruby_next %>
    - name: Ruby Ruby Next
      run: |
        bundle exec ruby-next nextify -V
    <% end %>
    <% if use_rspec %>
    - name: Run RSpec
      run: |
        bundle exec rspec
    <% else %>
    - name: Run tests
      run: |
        bundle exec rake test
    <% end %>

  TCODE
  ], trim_mode: "<>").result(binding)
    file ".github/workflows/rubocop.yml", ERB.new(
    *[
  <<~'TCODE'
name: Lint Ruby

on:
  push:
    branches:
    - master
  pull_request:

jobs:
  rubocop:
    runs-on: ubuntu-latest
    env:
      BUNDLE_GEMFILE: gemfiles/rubocop.gemfile
    steps:
    - uses: actions/checkout@v3
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.1
        bundler-cache: true
    - name: Lint Ruby code with RuboCop
      run: |
        bundle exec rubocop

  TCODE
  ], trim_mode: "<>").result(binding)

    if lint_docs
      file ".github/workflows/docs-lint.yml", ERB.new(
    *[
  <<~'TCODE'
name: Lint Docs

on:
  push:
    branches:
    - master
    paths:
    - "*.md"
    - "**/*.md"
    - ".github/workflows/docs-lint.yml"
  pull_request:
    paths:
    - "*.md"
    - "**/*.md"
    - ".github/workflows/docs-lint.yml"

jobs:
  markdownlint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.1
    - name: Run Markdown linter
      run: |
        gem install mdl
        mdl *.md
  rubocop:
    runs-on: ubuntu-latest
    env:
      BUNDLE_GEMFILE: gemfiles/rubocop.gemfile
    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.1
        bundler-cache: true
    - name: Lint Markdown files with RuboCop
      run: |
        bundle exec rubocop -c .rubocop-md.yml

  forspell:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install Hunspell
      run: |
        sudo apt-get install hunspell
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.1
    - name: Cache installed gems
      uses: actions/cache@v1
      with:
        path: /home/runner/.rubies/ruby-3.1.0/lib/ruby/gems/3.1.0
        key: gems-cache-${{ runner.os }}
    - name: Install Forspell
      run: gem install forspell
    - name: Run Forspell
      run: forspell *.md .github/**/*.md

  lychee:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Link Checker
      id: lychee
      uses: lycheeverse/[email protected]
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      with:
        args: README.md CHANGELOG.md -v


  TCODE
  ], trim_mode: "<>").result(binding)
    end

    if use_jruby
      file ".github/workflows/test-jruby.yml", ERB.new(
    *[
  <<~'TCODE'
name: JRuby Build

on:
  push:
    branches:
    - master
  pull_request:

jobs:
  rspec:
    runs-on: ubuntu-latest
    env:
      BUNDLE_JOBS: 4
      BUNDLE_RETRY: 3
      BUNDLE_GEMFILE: gemfiles/jruby.gemfile
      CI: true
    steps:
    - uses: actions/checkout@v3
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: jruby
        bundler-cache: true
    <% if use_ruby_next %>
    - name: Ruby Ruby Next
      run: |
        bundle exec ruby-next nextify -V
    <% end %>
    <% if use_rspec %>
    - name: Run RSpec
      run: |
        bundle exec rspec
    <% else %>
    - name: Run tests
      run: |
        bundle exec rake test
    <% end %>

  TCODE
  ], trim_mode: "<>").result(binding)
    end

    if use_rails
      file "gemfiles/rails6.gemfile", ERB.new(
    *[
  <<~'TCODE'
source "https://rubygems.org"

gem "rails", "~> 6.0"

gemspec path: ".."

  TCODE
  ], trim_mode: "<>").result(binding)
      file "gemfiles/rails7.gemfile", ERB.new(
    *[
  <<~'TCODE'
source "https://rubygems.org"

gem "rails", "~> 7.0"

gemspec path: ".."

  TCODE
  ], trim_mode: "<>").result(binding)
      file "gemfiles/railsmain.gemfile", ERB.new(
    *[
  <<~'TCODE'
source "https://rubygems.org"

gem "rails", github: "rails/rails"

gemspec path: ".."

  TCODE
  ], trim_mode: "<>").result(binding)
    end

    if use_jruby
      file "gemfiles/jruby.gemfile", ERB.new(
    *[
  <<~'TCODE'
source "https://rubygems.org"

<% if use_rails %>
gem "rails", "~> 6.0"
<% end %>

gemspec path: ".."

  TCODE
  ], trim_mode: "<>").result(binding)
    end
  end

  git :init
end

say "Congrats! Your gem is ready. Try running `bundle install` and `bundle exec rake` to make sure we configured it correctly."
Comments

Sign up or Login to leave a comment.