From 5f0a6d1133c0cd5c0b2962ec7b7008f44e6261c5 Mon Sep 17 00:00:00 2001 From: Alex Koval Date: Sat, 8 Nov 2025 15:03:09 +0100 Subject: [PATCH] feat: new settings, release please and templates --- .claude/settings.local.json | 9 ++ .github/workflows/ci.yml | 19 ++++ .github/workflows/main.yml | 24 ------ .github/workflows/release.yml | 37 ++++++++ .release-please-manifest.json | 3 + .rubocop.yml | 24 ------ Gemfile | 7 -- Gemfile.lock | 62 +++++++++---- Makefile | 24 +++--- Rakefile | 8 +- bin/console | 1 - exe/gemfather | 1 - gemfather.gemspec | 16 ++-- lib/gemfather/cli.rb | 105 +++++++++++++++-------- lib/gemfather/cli/settings_builder.rb | 71 +++++++++++++++ lib/gemfather/cli/settings_reader.rb | 51 ----------- lib/gemfather/cli/version.rb | 2 - lib/gemfather_cli.rb | 2 - release-please-config.json | 16 ++++ spec/gemfather_spec.rb | 8 +- spec/spec_helper.rb | 2 - templates/.release-please-manifest.json | 3 + templates/CHANGELOG.md | 1 + templates/CODE_OF_CONDUCT.md.erb | 36 ++++++++ templates/Makefile | 16 ---- templates/Makefile.erb | 25 ++++++ templates/ci/github/ci.yml | 19 ++++ templates/ci/github/release.yml | 37 ++++++++ templates/licences/mit.txt.erb | 21 +++++ templates/release-please-config.json.erb | 16 ++++ 30 files changed, 451 insertions(+), 215 deletions(-) create mode 100644 .claude/settings.local.json create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/release.yml create mode 100644 .release-please-manifest.json delete mode 100644 .rubocop.yml create mode 100644 lib/gemfather/cli/settings_builder.rb delete mode 100644 lib/gemfather/cli/settings_reader.rb create mode 100644 release-please-config.json create mode 100644 templates/.release-please-manifest.json create mode 100644 templates/CHANGELOG.md create mode 100644 templates/CODE_OF_CONDUCT.md.erb delete mode 100644 templates/Makefile create mode 100644 templates/Makefile.erb create mode 100644 templates/ci/github/ci.yml create mode 100644 templates/ci/github/release.yml create mode 100644 templates/licences/mit.txt.erb create mode 100644 templates/release-please-config.json.erb diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..c562b5f --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,9 @@ +{ + "permissions": { + "allow": [ + "Bash(ruby:*)" + ], + "deny": [], + "ask": [] + } +} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..527699f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: CI +on: [push] +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['3.2', '3.3', '3.4'] + + steps: + - uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + + - name: Run tests & linters + run: bundle install && bundle exec rake diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f78f3c1..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Gemfather - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - ruby-version: ['3.1', '3.0', '2.7', '2.6'] - steps: - - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 - with: - ruby-version: ${{ matrix.ruby-version }} - - name: Install dependencies - run: make install - - name: Run tests - run: make test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e3d87d7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + branches: + - master + +permissions: + contents: write + id-token: write + pull-requests: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Release Please + uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{ secrets.GH_TOKEN }} + + - uses: actions/checkout@v4 + if: ${{ steps.release.outputs.release_created }} + with: + fetch-tags: true + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + if: ${{ steps.release.outputs.release_created }} + with: + bundler-cache: true + ruby-version: 3.4 + + - uses: rubygems/release-gem@v1 + if: ${{ steps.release.outputs.release_created }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..2be9c43 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.2.0" +} diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 2187967..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,24 +0,0 @@ -AllCops: - TargetRubyVersion: 2.6 - -Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes - -Style/StringLiteralsInInterpolation: - Enabled: true - EnforcedStyle: double_quotes - -Layout/LineLength: - Max: 120 - -Metrics/BlockLength: - CountComments: false - Max: 5 - IgnoredMethods: - - context - - describe - - it - - let - - shared_examples - - shared_examples_for diff --git a/Gemfile b/Gemfile index 92182d1..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,3 @@ -# frozen_string_literal: true - source "https://rubygems.org" -# Specify your gem's dependencies in gemfather.gemspec gemspec - -gem "rake", "~> 13.0" -gem "rspec", "~> 3.0" -gem "rubocop", "~> 1.21" diff --git a/Gemfile.lock b/Gemfile.lock index 0a9fb06..3ca4827 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,22 +3,27 @@ PATH specs: gemfather-cli (0.2.0) tty-prompt (~> 0.23) + zeitwerk (~> 2.6) GEM remote: https://rubygems.org/ specs: - ast (2.4.2) + ast (2.4.3) diff-lcs (1.5.0) - json (2.6.2) - parallel (1.22.1) - parser (3.1.2.1) + json (2.16.0) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + parallel (1.27.0) + parser (3.3.10.0) ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + prism (1.6.0) + racc (1.8.1) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.0) - rexml (3.2.5) + regexp_parser (2.11.3) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -32,19 +37,37 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) - rubocop (1.38.0) + rubocop (1.80.2) json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.23.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.23.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.47.1) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.25.0) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + ruby-progressbar (1.13.0) + standard (1.51.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.80.2) + standard-custom (~> 1.0.0) + standard-performance (~> 1.8) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.8.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.25.0) tty-color (0.6.0) tty-cursor (0.7.1) tty-prompt (0.23.1) @@ -55,17 +78,22 @@ GEM tty-screen (~> 0.8) wisper (~> 2.0) tty-screen (0.8.1) - unicode-display_width (2.3.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.1.0) wisper (2.0.1) + zeitwerk (2.7.3) PLATFORMS + arm64-darwin-24 x86_64-linux DEPENDENCIES + bundler (~> 2.0) gemfather-cli! rake (~> 13.0) rspec (~> 3.0) - rubocop (~> 1.21) + standard (= 1.51.0) BUNDLED WITH 2.3.3 diff --git a/Makefile b/Makefile index cad3818..c7ddae6 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,17 @@ -.PHONY: test +.PHONY: test install lint-fix install_gem remove_gem reinstall_gem start + +start: + exe/gemfather install: bundle install +lint-fix: + bundle exec standardrb --fix + +test: + @env $$(cat .env | xargs) bundle exec rspec $(filter-out $@,$(MAKECMDGOALS)) + install_gem: yes | rm -rf pkg/* bundle exec rake build @@ -12,16 +21,3 @@ remove_gem: yes | gem uninstall gemfather reinstall_gem: remove_gem install_gem - -publish: - bundle exec rake build - gem push pkg/*.gem - -start: - exe/gemfather - -test: - bundle exec rspec - -lint-fix: - bundle exec rubocop -A diff --git a/Rakefile b/Rakefile index cca7175..d854ce7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,8 @@ -# frozen_string_literal: true - require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -require "rubocop/rake_task" - -RuboCop::RakeTask.new +require "standard/rake" -task default: %i[spec rubocop] +task default: %i[spec standard] diff --git a/bin/console b/bin/console index 9ca7d9d..fd63b64 100755 --- a/bin/console +++ b/bin/console @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true require "bundler/setup" require "gemfather/cli" diff --git a/exe/gemfather b/exe/gemfather index 829414d..c64bb97 100755 --- a/exe/gemfather +++ b/exe/gemfather @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true require "bundler/setup" require "gemfather/cli" diff --git a/gemfather.gemspec b/gemfather.gemspec index ba4ddf5..33a7842 100644 --- a/gemfather.gemspec +++ b/gemfather.gemspec @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require_relative "lib/gemfather/cli/version" Gem::Specification.new do |spec| @@ -12,15 +10,21 @@ Gem::Specification.new do |spec| spec.description = "Ask some questions & create a new gem template" spec.homepage = "https://gitlab.com/k0va1/gemfather-cli" spec.license = "MIT" - spec.required_ruby_version = ">= 2.6.0" + spec.required_ruby_version = ">= 3.2.0" spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://gitlab.com/k0va1/gemfather-cli" - spec.metadata["changelog_uri"] = "https://gitlab.com/k0va1/gemfather-cli" + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md" - spec.files = Dir.glob("{lib,templates}/**/*", File::FNM_DOTMATCH) + spec.files = Dir.glob("{lib,templates}/**/*", File::FNM_DOTMATCH) + %w[LICENSE.txt README.md CHANGELOG.md] spec.bindir = "exe" spec.executables = ["gemfather"] + spec.add_dependency "zeitwerk", "~> 2.6" spec.add_runtime_dependency("tty-prompt", "~> 0.23") + + spec.add_development_dependency "bundler", "~> 2.0" + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "standard", "1.51.0" end diff --git a/lib/gemfather/cli.rb b/lib/gemfather/cli.rb index 699ccd1..b8318ca 100644 --- a/lib/gemfather/cli.rb +++ b/lib/gemfather/cli.rb @@ -1,22 +1,20 @@ -# frozen_string_literal: true - -require_relative "cli/settings_reader" +require_relative "cli/settings_builder" require "fileutils" +require "erb" module Gemfather module Cli class Error < StandardError; end - # Entrypoint of the gem class Runner - attr_accessor :settings + attr_accessor :settings_builder, :settings - def initialize(settings_reader = ::Gemfather::Cli::SettingsReader.new) - @settings_reader = settings_reader + def initialize(settings_builder: Gemfather::Cli::SettingsBuilder.new) + @settings_builder = settings_builder + @settings = @settings_builder.call end def call - populate_settings init_gem update_gem_info copy_templates @@ -24,29 +22,23 @@ def call private - def populate_settings - @settings = @settings_reader.call - end - def build_bundle_options linter_options = build_linter_options test_options = build_test_options - coc_options = build_coc_options ci_options = build_ci_options [ linter_options, test_options, - coc_options, ci_options ].join(" ") end def build_linter_options case settings[:linter] - when "Rubocop" + when "rubocop" "--linter=rubocop" - when "Standard" + when "standard" "--linter=standard" else "" @@ -55,25 +47,17 @@ def build_linter_options def build_test_options case settings[:test] - when "Minitest" + when "minitest" "--test=minitest" - when "RSpec" + when "rspec" "--test=rspec" - when "TestUnit" - "--test=test-unit" else "" end end - def build_coc_options - settings[:coc?] ? "--coc" : "--no-coc" - end - def build_ci_options - cis = { "Github" => "github", "Gitlab" => "gitlab", "Travis" => "travis", "Circle" => "circle" } - ci_name = cis[settings[:ci]] - ci_name ? "--ci=#{ci_name}" : "" + settings[:ci] ? "--ci=#{settings[:ci]}" : "" end def init_gem @@ -85,14 +69,11 @@ def update_gem_info gemspec_path = File.join(Dir.pwd, settings[:name], "#{settings[:name]}.gemspec") updated_gemspec_lines = update_gemspec_lines(gemspec_path) - File.open(gemspec_path, "w") do |f| - f.write(updated_gemspec_lines.join) - f.close - end + File.write(gemspec_path, updated_gemspec_lines.join) end - def update_gemspec_lines(gemspec_path) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize - IO.readlines(gemspec_path).map do |line| # rubocop:disable Metrics/BlockLength + def update_gemspec_lines(gemspec_path) + IO.readlines(gemspec_path).map do |line| case line when /spec\.summary =.*/ line.gsub(/=\s".*"/, "= \"#{settings[:summary]}\"") @@ -100,10 +81,16 @@ def update_gemspec_lines(gemspec_path) # rubocop:disable Metrics/MethodLength,Me line.gsub(/=\s".*"/, "= \"#{settings[:description]}\"") when /spec\.homepage =.*/ line.gsub(/=\s".*"/, "= \"#{settings[:homepage]}\"") + when /spec\.metadata\["homepage_uri"\] =.*/ + line.gsub(/=\s".*"/, "= spec.homepage") when /spec\.metadata\["source_code_uri"\] =.*/ - line.gsub(/=\s".*"/, "= \"#{settings[:homepage]}\"") + line.gsub(/=\s".*"/, "= spec.homepage") when /spec\.metadata\["changelog_uri"\] =.*/ - line.gsub(/=\s".*"/, "= \"#{settings[:homepage]}/CHANGELOG.md\"") if settings[:changelog?] + if settings[:changelog?] + line.gsub(/=\s".*"/, "= \"#{settings[:homepage]}/blob/master/CHANGELOG.md\"") + end + when /spec\.metadata\["allowed_push_host"\] =.*/ + next else line end @@ -113,19 +100,63 @@ def update_gemspec_lines(gemspec_path) # rubocop:disable Metrics/MethodLength,Me def copy_templates copy_makefile copy_changelog + copy_coc + copy_release_please + copy_ci_files end def copy_makefile - FileUtils.cp(File.join(File.dirname(__dir__), "../templates/Makefile"), new_gem_root) if settings[:makefile?] + return unless settings[:makefile?] + + rendered_string = render_erb("Makefile.erb", settings_builder.get_binding) + File.write(File.join(new_gem_root, "Makefile"), rendered_string) end def copy_changelog - FileUtils.touch("#{new_gem_root}/CHANGELOG.md") if settings[:changelog?] + return unless settings[:changelog?] + + FileUtils.cp(File.join(templates_root, "CHANGELOG.md"), new_gem_root) + end + + def copy_coc + return unless settings[:coc?] + + rendered_string = render_erb("CODE_OF_CONDUCT.md.erb", settings_builder.get_binding) + File.write(File.join(new_gem_root, "CODE_OF_CONDUCT.md"), rendered_string) + end + + def copy_release_please + return unless settings[:use_release_please] + + rendered_string = render_erb("release-please-config.json.erb", settings_builder.get_binding) + File.write(File.join(new_gem_root, "release-please-config.json"), rendered_string) + FileUtils.cp(File.join(templates_root, ".release-please-manifest.json"), new_gem_root) + + if settings[:ci] == "github" + FileUtils.cp(File.join(templates_root, "ci/github/release.yml"), File.join(new_gem_root, ".github/workflows/release.yml")) + end + end + + def copy_ci_files + if settings[:ci] == "github" + FileUtils.rm_rf(File.join(new_gem_root, ".github/workflows/main.yml")) + FileUtils.cp(File.join(templates_root, "ci/github/ci.yml"), File.join(new_gem_root, ".github/workflows/ci.yml")) + end end def new_gem_root @new_gem_root ||= File.join(Dir.pwd, settings[:name]) end + + def templates_root + @templates_root ||= File.join(File.dirname(__dir__), "../templates") + end + + def render_erb(file, binding) + template_path = File.join(templates_root, file) + template = ERB.new(File.read(template_path)) + template.result(binding) + end end end end diff --git a/lib/gemfather/cli/settings_builder.rb b/lib/gemfather/cli/settings_builder.rb new file mode 100644 index 0000000..c831d6d --- /dev/null +++ b/lib/gemfather/cli/settings_builder.rb @@ -0,0 +1,71 @@ +require "tty-prompt" + +module Gemfather + module Cli + class SettingsBuilder + DEFAULT_GEM_NAME = "awesome-new-gem" + DEFAULT_USER_EMAIL = "your-mail@example.com" + DEFAULT_USERNAME = `whoami`.chomp + + attr_accessor :settings + + def initialize + @settings = {} + end + + def call + prompt = TTY::Prompt.new(interrupt: :exit) + + user_email = `git config user.email`.chomp + settings[:email] = user_email.empty? ? DEFAULT_USER_EMAIL : user_email + + username = `git config user.name`.chomp + settings[:username] = username.empty? ? DEFAULT_USERNAME : username + + settings[:name] = prompt.ask("Gem name:", default: DEFAULT_GEM_NAME) + settings[:summary] = prompt.ask("Summary", default: DEFAULT_GEM_NAME) + settings[:description] = prompt.ask("Description", default: DEFAULT_GEM_NAME) + settings[:homepage] = prompt.ask("Home page(URL)", default: DEFAULT_GEM_NAME, value: "https://github.com/") + + settings[:licence] = prompt.select("Select Licence") do |menu| + menu.choice "MIT", "mit" + menu.choice "N/A", "n/a" + end + + settings[:linter] = prompt.select("Select linter") do |menu| + menu.choice "Standard", "standard" + menu.choice "Rubocop", "rubocop" + menu.choice "N/A", "n/a" + end + + settings[:test] = prompt.select("Select test tool") do |menu| + menu.choice "RSpec", "rspec" + menu.choice "Minitest", "minitest" + menu.choice "N/A", "n/a" + end + + settings[:ci] = prompt.select("Select CI") do |menu| + menu.choice "GitHub", "github" + menu.choice "Gitlab", "gitlab" + end + + settings[:use_release_please] = prompt.yes?("Do you want to use release-please for releases?") + + settings[:makefile?] = prompt.yes?("Do you need Makefile?") + settings[:coc?] = prompt.yes?("Do you need Code Of Conduct?") + settings[:changelog?] = prompt.yes?("Do you need CHANGELOG file?") + + settings[:debugger] = prompt.select("Select debugger tool:") do |menu| + menu.choice "IRB", "irb" + menu.choice "Pry", "pry" + end + + settings + end + + def get_binding + binding + end + end + end +end diff --git a/lib/gemfather/cli/settings_reader.rb b/lib/gemfather/cli/settings_reader.rb deleted file mode 100644 index 4b79138..0000000 --- a/lib/gemfather/cli/settings_reader.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -require "tty-prompt" - -module Gemfather - module Cli - # Class responsible to collect user input and build settings hash - class SettingsReader - def call # rubocop:disable Metrics/MethodLength, Metrics/AbcSize - settings = {} - prompt = TTY::Prompt.new(interrupt: :exit) - - settings[:name] = prompt.ask("Gem name:", default: "awesome-new-gem") - settings[:summary] = prompt.ask("Summary", default: "awesome-new-gem") - settings[:description] = prompt.ask("Description", default: "awesome-new-gem") - settings[:homepage] = prompt.ask("Home page(URL)", default: "awesome-new-gem") - - settings[:linter] = prompt.select("Select linter") do |menu| - menu.choice "Rubocop" - menu.choice "Standard" - menu.choice "N/A" - end - - settings[:test] = prompt.select("Select test tool:") do |menu| - menu.choice "RSpec" - menu.choice "Minitest" - menu.choice "TestUnit" - menu.choice "N/A" - end - - settings[:ci] = prompt.select("Select CI tool:") do |menu| - menu.choice "GitHub" - menu.choice "Gitlab" - menu.choice "Travis" - menu.choice "Circle" - end - - settings[:makefile?] = prompt.yes?("Do you need Makefile?") - settings[:coc?] = prompt.yes?("Do you need Code Of Conduct?") - settings[:changelog?] = prompt.yes?("Do you need CHANGELOG?") - - settings[:debugger] = prompt.select("Select debugger tool:") do |menu| - menu.choice "IRB" - menu.choice "Pry" - end - - settings - end - end - end -end diff --git a/lib/gemfather/cli/version.rb b/lib/gemfather/cli/version.rb index 8950a7d..6cf6872 100644 --- a/lib/gemfather/cli/version.rb +++ b/lib/gemfather/cli/version.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - module Gemfather module Cli VERSION = "0.2.0" diff --git a/lib/gemfather_cli.rb b/lib/gemfather_cli.rb index b46ebca..8db8da3 100644 --- a/lib/gemfather_cli.rb +++ b/lib/gemfather_cli.rb @@ -1,3 +1 @@ -# frozen_string_literal: true - require "gemfather/cli" diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..4ed9909 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,16 @@ +{ + "packages": { + ".": { + "package-name": "gemfather-cli", + "include-component-in-tag": false, + "changelog-path": "CHANGELOG.md", + "release-type": "ruby", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "draft": false, + "prerelease": false, + "version-file": "lib/gemfather/cli/version.rb" + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/spec/gemfather_spec.rb b/spec/gemfather_spec.rb index 0c4fff1..4ea60f4 100644 --- a/spec/gemfather_spec.rb +++ b/spec/gemfather_spec.rb @@ -1,12 +1,10 @@ -# frozen_string_literal: true - require "fileutils" RSpec.describe Gemfather::Cli::Runner do describe "run" do - subject { described_class.new(settings_reader).call } + subject { described_class.new(settings_builder: settings_builder).call } - let(:settings_reader) { instance_double("Gemfather::Cli::SettingsReader") } + let(:settings_builder) { instance_double("Gemfather::Cli::SettingsBuilder") } let(:settings_mock) do { name: "new_gem", @@ -22,7 +20,7 @@ } end before do - allow(settings_reader).to receive(:call).and_return(settings_mock) + allow(settings_builder).to receive(:call).and_return(settings_mock) end it "runs successfuly" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72c857c..3d0e2af 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require "gemfather/cli" RSpec.configure do |config| diff --git a/templates/.release-please-manifest.json b/templates/.release-please-manifest.json new file mode 100644 index 0000000..466df71 --- /dev/null +++ b/templates/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.1.0" +} diff --git a/templates/CHANGELOG.md b/templates/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/templates/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/templates/CODE_OF_CONDUCT.md.erb b/templates/CODE_OF_CONDUCT.md.erb new file mode 100644 index 0000000..c1433e5 --- /dev/null +++ b/templates/CODE_OF_CONDUCT.md.erb @@ -0,0 +1,36 @@ +# Code of Conduct + +## Our Pledge +We, the maintainers and contributors, pledge to make participation in this project a harassment-free experience for everyone. We are committed to creating a welcoming and inclusive community regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards +### Examples of behavior that contributes to a positive environment: +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Accepting constructive criticism gracefully +- Focusing on what is best for the community +- Showing empathy toward other community members + +### Examples of unacceptable behavior: +- Harassment or discriminatory jokes and language +- Personal or political attacks +- Publishing others’ private information without permission +- Unwanted sexual attention or advances +- Any conduct that would be considered inappropriate in a professional setting + +## Our Responsibilities +Project maintainers are responsible for clarifying standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable conduct. + +Maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, issues, and other contributions that do not align with this Code of Conduct. + +## Scope +This Code of Conduct applies within all project spaces and in public spaces when an individual is representing the project or its community. + +## Enforcement +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainers at **<%= settings[:email] %>**. +All complaints will be reviewed and investigated, and will result in a response that is deemed necessary and appropriate to the circumstances. + +Maintainers are obligated to respect the privacy and safety of reporters. + +## Attribution +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1. diff --git a/templates/Makefile b/templates/Makefile deleted file mode 100644 index 2a921c8..0000000 --- a/templates/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -.PHONY: test - -install: - bundle install - -cons: - bin/console - -test: - bundle exec rspec - -release: - bundle exec rake release - -lint: - bundle exec rubocop diff --git a/templates/Makefile.erb b/templates/Makefile.erb new file mode 100644 index 0000000..683dc84 --- /dev/null +++ b/templates/Makefile.erb @@ -0,0 +1,25 @@ +.PHONY: test lint-fix console install + +install: + bundle install + +console: + bin/console +<% if settings[:test] == "rspec" %> + +test: + bundle exec rspec +<% elsif settings[:test] == "minitest" %> + +test: + bundle exec rake test +<% end %> +<% if settings[:linter] == "rubocop" %> + +lint-fix: + bundle exec rubocop -A +<% elsif settings[:linter] == "standard" %> + +lint-fix: + bundle exec standardrb --fix +<% end %> diff --git a/templates/ci/github/ci.yml b/templates/ci/github/ci.yml new file mode 100644 index 0000000..527699f --- /dev/null +++ b/templates/ci/github/ci.yml @@ -0,0 +1,19 @@ +name: CI +on: [push] +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['3.2', '3.3', '3.4'] + + steps: + - uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + + - name: Run tests & linters + run: bundle install && bundle exec rake diff --git a/templates/ci/github/release.yml b/templates/ci/github/release.yml new file mode 100644 index 0000000..e3d87d7 --- /dev/null +++ b/templates/ci/github/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + push: + branches: + - master + +permissions: + contents: write + id-token: write + pull-requests: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Release Please + uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{ secrets.GH_TOKEN }} + + - uses: actions/checkout@v4 + if: ${{ steps.release.outputs.release_created }} + with: + fetch-tags: true + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + if: ${{ steps.release.outputs.release_created }} + with: + bundler-cache: true + ruby-version: 3.4 + + - uses: rubygems/release-gem@v1 + if: ${{ steps.release.outputs.release_created }} diff --git a/templates/licences/mit.txt.erb b/templates/licences/mit.txt.erb new file mode 100644 index 0000000..b4b40f8 --- /dev/null +++ b/templates/licences/mit.txt.erb @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) <%= Time.now.year %> <%= settings[:username] %> + +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. diff --git a/templates/release-please-config.json.erb b/templates/release-please-config.json.erb new file mode 100644 index 0000000..0b376f2 --- /dev/null +++ b/templates/release-please-config.json.erb @@ -0,0 +1,16 @@ +{ + "packages": { + ".": { + "package-name": "<%= settings[:name] %>", + "include-component-in-tag": false, + "changelog-path": "CHANGELOG.md", + "release-type": "ruby", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "draft": false, + "prerelease": false, + "version-file": "lib/<%= settings[:name] %>/version.rb" + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +}