From a05970c051b957ebc990f52d40cfc2e4685ac601 Mon Sep 17 00:00:00 2001 From: Jaden Fix <163031992+jadenfix@users.noreply.github.com> Date: Mon, 12 Oct 2026 18:40:53 -0700 Subject: [PATCH] Package CLI sources without requiring Git metadata --- .github/workflows/api-http.yml | 1 + cli/gemhub.gemspec | 11 +++++------ scripts/check_gem_package.rb | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 scripts/check_gem_package.rb diff --git a/.github/workflows/api-http.yml b/.github/workflows/api-http.yml index 77d3445..c200fa0 100644 --- a/.github/workflows/api-http.yml +++ b/.github/workflows/api-http.yml @@ -12,4 +12,5 @@ jobs: ruby-version: '3.3' - run: gem install webrick --no-document - run: ruby -c services/api/simple_server.rb + - run: ruby scripts/check_gem_package.rb - run: python3 scripts/check_api_http.py diff --git a/cli/gemhub.gemspec b/cli/gemhub.gemspec index 07f9b84..cbc1a89 100644 --- a/cli/gemhub.gemspec +++ b/cli/gemhub.gemspec @@ -19,13 +19,12 @@ Gem::Specification.new do |spec| spec.metadata["source_code_uri"] = "https://github.com/your-org/gemhub" spec.metadata["changelog_uri"] = "https://github.com/your-org/gemhub/blob/main/CHANGELOG.md" - # 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. + # Container/source builds may not contain Git or a .git directory. Enumerate + # the package's own source, and include bin/ so gem installation exposes the CLI. spec.files = Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| - (File.expand_path(f) == __FILE__) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile]) - end + Dir.glob(["lib/**/*", "bin/*", "README*", "LICENSE*"]).select do |file| + File.file?(file) + end.sort end spec.bindir = "bin" spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) } diff --git a/scripts/check_gem_package.rb b/scripts/check_gem_package.rb new file mode 100644 index 0000000..cc01ace --- /dev/null +++ b/scripts/check_gem_package.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "fileutils" +require "tmpdir" +require "rubygems" + +root = File.expand_path("..", __dir__) +Dir.mktmpdir("gemhub-source-package") do |directory| + %w[gemhub.gemspec lib bin].each do |entry| + FileUtils.cp_r(File.join(root, "cli", entry), directory) + end + original_path = ENV["PATH"] + begin + ENV["PATH"] = directory # No external Git executable and no repository metadata. + spec = Gem::Specification.load(File.join(directory, "gemhub.gemspec")) + raise "Gemspec cannot load without Git" unless spec + raise "Missing CLI executable" unless spec.executables == ["gemhub"] + raise "Missing packaged executable" unless spec.files.include?("bin/gemhub") + raise "Missing implementation" unless spec.files.include?("lib/gemhub/version.rb") + raise "Unexpected repository files" unless spec.files.all? { |file| File.file?(File.join(directory, file)) } + puts "PASS: source gemspec loads without Git and packages executable plus implementation" + ensure + ENV["PATH"] = original_path + end +end