From 46b85e562c849b2ed04bddf430dc5727c536b326 Mon Sep 17 00:00:00 2001 From: kg8m Date: Sat, 28 Dec 2024 22:27:44 +0900 Subject: [PATCH 1/2] Extract the logic to collect the package files into a separate module And add a test for it. --- spec/tools/collect_package_files_spec.rb | 136 +++++++++++++++++++++++ tanshuku.gemspec | 11 +- tools/collect_package_files.rb | 12 ++ 3 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 spec/tools/collect_package_files_spec.rb create mode 100644 tools/collect_package_files.rb diff --git a/spec/tools/collect_package_files_spec.rb b/spec/tools/collect_package_files_spec.rb new file mode 100644 index 0000000..b112a24 --- /dev/null +++ b/spec/tools/collect_package_files_spec.rb @@ -0,0 +1,136 @@ +# frozen_string_literal: true + +RSpec.describe CollectPackageFiles do + let(:expected_included_files) do + %w[ + LICENSE + README.md + app/controllers/tanshuku/urls_controller.rb + app/models/tanshuku/url.rb + config/locales/en.yml + config/locales/ja.yml + config/routes.rb + db/migrate/20230220123456_create_tanshuku_urls.rb + lib/generators/tanshuku/install_generator.rb + lib/generators/templates/initializer.rb + lib/tanshuku.rb + lib/tanshuku/configuration.rb + lib/tanshuku/engine.rb + lib/tanshuku/version.rb + lib/tasks/check_all.rb + sig/app/controllers/tanshuku/urls_controller.rbs + sig/app/models/tanshuku/url.rbs + sig/db/migrate/create_tanshuku_urls.rbs + sig/lib/generators/tanshuku/install_generator.rbs + sig/lib/tanshuku.rbs + sig/lib/tanshuku/configuration.rbs + sig/lib/tanshuku/engine.rbs + sig/lib/tanshuku/version.rbs + sig/lib/tasks/check_all.rbs + ] + end + let(:expected_excluded_files) do + %w[ + .gitattributes + .github/dependabot.yml + .github/release.yml + .github/workflows/bot-auto-merge.yml + .github/workflows/checks.yml + .github/workflows/create-release.yml + .github/workflows/dependabot-autolabeling.yml + .github/workflows/pages.yml + .github/workflows/update-rbs-collection.yml + .gitignore + .rspec + .rubocop.yml + Gemfile + Gemfile.ci + Gemfile.lock + Rakefile + Steepfile + bin/rails + rbs_collection.lock.yaml + rbs_collection.yaml + sig/patch/actionpack.rbs + sig/patch/activerecord.rbs + sig/patch/english.rbs + sig/patch/paint.rbs + sig/patch/pty.rbs + sig/patch/rack.rbs + sig/patch/rails.rbs + sig/patch/thor.rbs + spec/config/locales/en_spec.rb + spec/config/locales/ja_spec.rb + spec/dummy/Rakefile + spec/dummy/app/assets/config/manifest.js + spec/dummy/app/assets/images/.keep + spec/dummy/app/assets/stylesheets/application.css + spec/dummy/app/channels/application_cable/channel.rb + spec/dummy/app/channels/application_cable/connection.rb + spec/dummy/app/controllers/application_controller.rb + spec/dummy/app/controllers/concerns/.keep + spec/dummy/app/helpers/application_helper.rb + spec/dummy/app/jobs/application_job.rb + spec/dummy/app/mailers/application_mailer.rb + spec/dummy/app/models/application_record.rb + spec/dummy/app/models/concerns/.keep + spec/dummy/app/views/layouts/application.html.erb + spec/dummy/app/views/layouts/mailer.html.erb + spec/dummy/app/views/layouts/mailer.text.erb + spec/dummy/app/views/pwa/manifest.json.erb + spec/dummy/app/views/pwa/service-worker.js + spec/dummy/bin/dev + spec/dummy/bin/rails + spec/dummy/bin/rake + spec/dummy/bin/setup + spec/dummy/config.ru + spec/dummy/config/application.rb + spec/dummy/config/boot.rb + spec/dummy/config/cable.yml + spec/dummy/config/database.yml + spec/dummy/config/environment.rb + spec/dummy/config/environments/development.rb + spec/dummy/config/environments/production.rb + spec/dummy/config/environments/test.rb + spec/dummy/config/initializers/assets.rb + spec/dummy/config/initializers/content_security_policy.rb + spec/dummy/config/initializers/filter_parameter_logging.rb + spec/dummy/config/initializers/inflections.rb + spec/dummy/config/initializers/tanshuku.rb + spec/dummy/config/locales/en.yml + spec/dummy/config/puma.rb + spec/dummy/config/routes.rb + spec/dummy/config/storage.yml + spec/dummy/lib/assets/.keep + spec/dummy/log/.keep + spec/dummy/public/400.html + spec/dummy/public/404.html + spec/dummy/public/406-unsupported-browser.html + spec/dummy/public/422.html + spec/dummy/public/500.html + spec/dummy/public/apple-touch-icon-precomposed.png + spec/dummy/public/apple-touch-icon.png + spec/dummy/public/favicon.ico + spec/dummy/public/icon.svg + spec/generator/tanshuku/install_generator_spec.rb + spec/lib/tanshuku/configuration_spec.rb + spec/lib/tanshuku_spec.rb + spec/models/tanshuku/url_spec.rb + spec/requests/tanshuku/urls_controller_spec.rb + spec/spec_helper.rb + spec/support/spec_utilities.rb + spec/tools/collect_package_files_spec.rb + tanshuku.gemspec + tmp/.keep + tools/collect_package_files.rb + tools/reverse_dependencies.rb + ] + end + let(:all_candidate_files) { `git ls-files -z`.split("\x0") } + + example "collects sufficient and necessary files" do + expect(CollectPackageFiles.call).to match_array(expected_included_files) + expect(CollectPackageFiles.call & expected_excluded_files).to be_empty + expect(expected_included_files + expected_excluded_files).to match_array(all_candidate_files) + end +end diff --git a/tanshuku.gemspec b/tanshuku.gemspec index 15296ee..fb776e8 100644 --- a/tanshuku.gemspec +++ b/tanshuku.gemspec @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative "lib/tanshuku/version" +require_relative "tools/collect_package_files" Gem::Specification.new do |spec| spec.name = "tanshuku" @@ -24,15 +25,7 @@ Gem::Specification.new do |spec| spec.metadata["documentation_uri"] = "https://kg8m.github.io/tanshuku/" spec.metadata["rubygems_mfa_required"] = "true" - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = - Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| - (File.expand_path(f) == __FILE__) || - f.match?(%r{\A(?:\.|Gemfile|Rakefile\z|Steepfile\z|rbs_collection|(?:bin|sig/patch|spec|tmp|tools)/)}) - end - end + spec.files = CollectPackageFiles.call spec.require_paths = ["lib"] spec.add_dependency "addressable", ">= 2.4" diff --git a/tools/collect_package_files.rb b/tools/collect_package_files.rb new file mode 100644 index 0000000..6490b4f --- /dev/null +++ b/tools/collect_package_files.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module CollectPackageFiles + EXCLUDE_PATHS = %w[Rakefile Steepfile tanshuku.gemspec].freeze + EXCLUDE_PATTERN = %r{\A(?:\.|Gemfile|rbs_collection|(?:bin|sig/patch|spec|tmp|tools)/)} + + def self.call + `git ls-files -z`.split("\x0").reject do |f| + EXCLUDE_PATHS.include?(f) || f.match?(EXCLUDE_PATTERN) + end + end +end From f10fab095838351e48c927ce6e899cb51036a5bb Mon Sep 17 00:00:00 2001 From: kg8m Date: Sat, 28 Dec 2024 22:31:15 +0900 Subject: [PATCH 2/2] `lib/tasks/check_all.rb` and its corresponding RBS file are unnecessary for the package --- spec/tools/collect_package_files_spec.rb | 4 ++-- tools/collect_package_files.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/tools/collect_package_files_spec.rb b/spec/tools/collect_package_files_spec.rb index b112a24..0c5a5ef 100644 --- a/spec/tools/collect_package_files_spec.rb +++ b/spec/tools/collect_package_files_spec.rb @@ -17,7 +17,6 @@ lib/tanshuku/configuration.rb lib/tanshuku/engine.rb lib/tanshuku/version.rb - lib/tasks/check_all.rb sig/app/controllers/tanshuku/urls_controller.rbs sig/app/models/tanshuku/url.rbs sig/db/migrate/create_tanshuku_urls.rbs @@ -26,7 +25,6 @@ sig/lib/tanshuku/configuration.rbs sig/lib/tanshuku/engine.rbs sig/lib/tanshuku/version.rbs - sig/lib/tasks/check_all.rbs ] end let(:expected_excluded_files) do @@ -49,8 +47,10 @@ Rakefile Steepfile bin/rails + lib/tasks/check_all.rb rbs_collection.lock.yaml rbs_collection.yaml + sig/lib/tasks/check_all.rbs sig/patch/actionpack.rbs sig/patch/activerecord.rbs sig/patch/english.rbs diff --git a/tools/collect_package_files.rb b/tools/collect_package_files.rb index 6490b4f..8534ec6 100644 --- a/tools/collect_package_files.rb +++ b/tools/collect_package_files.rb @@ -2,7 +2,7 @@ module CollectPackageFiles EXCLUDE_PATHS = %w[Rakefile Steepfile tanshuku.gemspec].freeze - EXCLUDE_PATTERN = %r{\A(?:\.|Gemfile|rbs_collection|(?:bin|sig/patch|spec|tmp|tools)/)} + EXCLUDE_PATTERN = %r{\A(?:\.|Gemfile|rbs_collection|(?:bin|lib/tasks|sig/(?:lib/tasks|patch)|spec|tmp|tools)/)} def self.call `git ls-files -z`.split("\x0").reject do |f|