Class: GemHadar
- Inherits:
-
Object
- Object
- GemHadar
- Extended by:
- DSLKit::DSLAccessor
- Includes:
- Config, Rake::DSL, RbConfig, Term::ANSIColor, Tins::SecureWrite
- Defined in:
- lib/gem_hadar.rb,
lib/gem_hadar.rb,
lib/gem_hadar/version.rb
Defined Under Namespace
Modules: GitHub Classes: RvmConfig, Setup, TemplateCompiler
Constant Summary collapse
- VERSION =
GemHadar version
'1.23.0'- VERSION_ARRAY =
:nodoc:
VERSION.split('.').map(&:to_i)
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Class Method Summary collapse
-
.start_simplecov ⇒ Object
The start_simplecov method initializes SimpleCov and configures it to ignore coverage data from the directory containing the caller.
Instance Method Summary collapse
-
#ask?(prompt, pattern, default: nil) ⇒ MatchData?
The ask? method prompts the user with a message and reads their input It returns a MatchData object if the input matches the provided pattern.
-
#assert_valid_link(name, orig_url) ⇒ String
The assert_valid_link method verifies that the provided URL is valid by checking if it returns an HTTP OK status after following redirects, unless project is still ‘developing`.
- #build_task ⇒ Object
- #clean(*args) ⇒ Object
- #clobber(*args) ⇒ Object
- #compile_task ⇒ Object
-
#create_all_tasks ⇒ GemHadar
The create_all_tasks method sets up and registers all the Rake tasks for the gem project.
- #create_body ⇒ Object
- #default_task ⇒ Object
- #dependency(*args) ⇒ Object
- #development_dependency(*args) ⇒ Object
- #doc_task ⇒ Object
- #edit_temp_file(content) ⇒ Object
-
#fail(*args) ⇒ Object
The fail method formats and displays failure messages using red colored output.
-
#gem_files ⇒ Array<String>
The gem_files method returns an array of files that are included in the gem package.
- #gem_hadar_update_task ⇒ Object
- #gem_push_task ⇒ Object
- #gems_install_task(&block) ⇒ Object
-
#gemspec ⇒ Gem::Specification
The gemspec method creates and returns a new Gem::Specification object that defines the metadata and dependencies for the gem package.
- #gemspec_task ⇒ Object
- #git_remote ⇒ Object
-
#git_remotes ⇒ Array<String>
The git_remotes method retrieves the list of remote repositories configured for the current Git project.
- #git_remotes_task ⇒ Object
- #github_release_task ⇒ Object
-
#github_remote_url ⇒ URI?
The github_remote_url method retrieves and parses the GitHub remote URL from the local Git configuration.
- #has_to_be_set(name) ⇒ Object
- #ignore(*args) ⇒ Object
-
#initialize(&block) ⇒ GemHadar
constructor
A new instance of GemHadar.
- #install_library(&block) ⇒ Object
- #install_library_task ⇒ Object
- #master_prepare_task ⇒ Object
- #master_push_task ⇒ Object
- #package_ignore(*args) ⇒ Object
- #package_task ⇒ Object
- #push_task ⇒ Object
- #rcov_task ⇒ Object
- #require_path(path = nil) ⇒ Object
- #rvm(&block) ⇒ Object
- #rvm_task ⇒ Object
- #spec_task ⇒ Object
- #test_task ⇒ Object
- #version_bump_task ⇒ Object
- #version_diff_task ⇒ Object
- #version_log_diff(to_version: 'HEAD', from_version: nil) ⇒ Object
- #version_push_task ⇒ Object
- #version_show_task ⇒ Object
-
#version_tag(version) ⇒ String
The version_tag method prepends a ‘v’ prefix to the given version string.
- #version_tag_task ⇒ Object
- #version_task ⇒ Object
-
#versions ⇒ Array<String>
The versions method retrieves and processes the list of git tags that match semantic versioning patterns.
-
#warn(*msgs) ⇒ Object
The warn method displays warning messages using orange colored output.
-
#write_gemfile ⇒ Object
The write_gemfile method creates and writes the default Gemfile content if it doesn’t exist.
-
#write_ignore_file ⇒ Object
The write_ignore_file method writes the current ignore_files configuration to a .gitignore file in the project root directory.
- #yard_task ⇒ Object
Constructor Details
#initialize(&block) ⇒ GemHadar
44 45 46 47 48 |
# File 'lib/gem_hadar.rb', line 44 def initialize(&block) @dependencies = [] @development_dependencies = [] block and instance_eval(&block) end |
Class Method Details
.start_simplecov ⇒ Object
The start_simplecov method initializes SimpleCov and configures it to ignore coverage data from the directory containing the caller. This can be called from a test or spec helper.
1041 1042 1043 1044 1045 1046 1047 |
# File 'lib/gem_hadar.rb', line 1041 def start_simplecov defined? SimpleCov or return filter = "#{File.basename(File.dirname(caller.first))}/" SimpleCov.start do add_filter filter end end |
Instance Method Details
#ask?(prompt, pattern, default: nil) ⇒ MatchData?
The ask? method prompts the user with a message and reads their input It returns a MatchData object if the input matches the provided pattern.
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 |
# File 'lib/gem_hadar.rb', line 963 def ask?(prompt, pattern, default: nil) if prompt.include?('%{default}') if default.present? prompt = prompt % { default: ", default is #{default.inspect}" } else prompt = prompt % { default: '' } end end STDOUT.print prompt answer = STDIN.gets.chomp default.present? && answer.blank? and answer = default if answer =~ pattern $~ end end |
#assert_valid_link(name, orig_url) ⇒ String
The assert_valid_link method verifies that the provided URL is valid by checking if it returns an HTTP OK status after following redirects, unless project is still ‘developing`.
following redirects
855 856 857 858 859 860 861 862 863 864 865 |
# File 'lib/gem_hadar.rb', line 855 def assert_valid_link(name, orig_url) developing and return orig_url url = orig_url begin response = Net::HTTP.get_response(URI.parse(url)) url = response['location'] end while response.is_a?(Net::HTTPRedirection) response.is_a?(Net::HTTPOK) or fail "#{orig_url.inspect} for #{name} has to be a valid link" orig_url end |
#build_task ⇒ Object
199 200 201 202 |
# File 'lib/gem_hadar.rb', line 199 def build_task desc 'Build task (builds all packages for a release)' task :build => build_task_dependencies end |
#clean(*args) ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/gem_hadar.rb', line 211 def clean(*args) if args.empty? CLEAN else CLEAN.include(*args) end end |
#clobber(*args) ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/gem_hadar.rb', line 219 def clobber(*args) if args.empty? CLOBBER else CLOBBER.include(*args) end end |
#compile_task ⇒ Object
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/gem_hadar.rb', line 714 def compile_task for file in extensions dir = File.dirname(file) clean File.join(dir, 'Makefile'), File.join(dir, '*.{bundle,o,so}') end desc "Compile extensions: #{extensions * ', '}" task :compile do for file in extensions dir, file = File.split(file) cd dir do ruby file sh make end end end end |
#create_all_tasks ⇒ GemHadar
The create_all_tasks method sets up and registers all the Rake tasks for the gem project.
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/gem_hadar.rb', line 780 def create_all_tasks default_task build_task rvm_task version_task version_show_task version_diff_task gem_hadar_update_task gemspec_task gems_install_task doc_task if test_dir test_task rcov_task end spec_task package_task yard_task install_library_task version_bump_task version_tag_task push_task write_ignore_file write_gemfile if extensions.full? compile_task task :prepare_install => :compile else task :prepare_install end self end |
#create_body ⇒ Object
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/gem_hadar.rb', line 598 def create_body base_url = ENV['OLLAMA_URL'] if base_url.blank? && host = ENV['OLLAMA_HOST'].full? base_url = 'http://%s' % host end base_url.present? or return log_diff = version_log_diff(to_version: version) model = ENV.fetch('OLLAMA_MODEL', 'llama3.1') ollama = Ollama::Client.new(base_url:, read_timeout: 600, connect_timeout: 60) system = " You are a Ruby programmer generating changelog messages in markdown\n format for new releases, so users can see what has changed. Remember you\n are not a chatbot of any kind.\n EOT\n prompt = (<<~EOT) % { name:, version:, log_diff: }\n Output the content of a changelog for the new release of %{name} %{version}\n\n **Strictly** follow these guidelines:\n\n - Use bullet points in markdown format (`-`) to list significant changes.\n - Exclude trivial updates such as:\n * Version number increments\n * Dependency version bumps (unless they resolve critical issues)\n * Minor code style adjustments\n * Internal documentation tweaks\n - Include only verified and substantial changes that impact\n functionality, performance, or user experience.\n - If unsure about a change's significance, omit it from the output.\n - Avoid adding any comments or notes; keep the output purely factual.\n\n These are the log messages including patches for the new release:\n\n %{log_diff}\n EOT\n options = ENV['OLLAMA_OPTIONS'].full? { |o| JSON.parse(o) } || {}\n options |= { \"temperature\" => 0, \"top_p\" => 1, \"min_p\" => 0.1 }\n ollama.generate(model:, system:, prompt:, options:, stream: false, think: false).response\nend\n" |
#default_task ⇒ Object
192 193 194 195 |
# File 'lib/gem_hadar.rb', line 192 def default_task desc 'Default task' task :default => default_task_dependencies end |
#dependency(*args) ⇒ Object
243 244 245 |
# File 'lib/gem_hadar.rb', line 243 def dependency(*args) @dependencies << args end |
#development_dependency(*args) ⇒ Object
247 248 249 |
# File 'lib/gem_hadar.rb', line 247 def development_dependency(*args) @development_dependencies << args end |
#doc_task ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/gem_hadar.rb', line 400 def doc_task clean 'doc' desc "Creating documentation" task :doc do sh 'yard doc' cmd = 'yardoc' if readme cmd << " --readme '#{readme}'" end cmd << ' - ' << doc_files * ' ' sh cmd end end |
#edit_temp_file(content) ⇒ Object
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/gem_hadar.rb', line 637 def edit_temp_file(content) editor = ENV.fetch('EDITOR', `which vi`.chomp) unless File.exist?(editor) warn "Can't find EDITOR. => Returning." return end temp_file = Tempfile.new('changelog') temp_file.write(content) temp_file.close unless system("#{editor} #{temp_file.path}") warn "#{editor} returned #{$?.exitstatus} => Returning." return end File.read(temp_file.path) ensure temp_file&.close&.unlink end |
#fail(*args) ⇒ Object
The fail method formats and displays failure messages using red colored output.
929 930 931 932 933 934 |
# File 'lib/gem_hadar.rb', line 929 def fail(*args) args.map! do |a| a.respond_to?(:to_str) ? color(196) { a.to_str } : a end super(*args) end |
#gem_files ⇒ Array<String>
The gem_files method returns an array of files that are included in the gem package.
It calculates this by subtracting the files listed in package_ignore_files from the list of all files.
986 987 988 |
# File 'lib/gem_hadar.rb', line 986 def gem_files (files.to_a - package_ignore_files.to_a) end |
#gem_hadar_update_task ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/gem_hadar.rb', line 351 def gem_hadar_update_task namespace :gem_hadar do desc 'Update gem_hadar a different version' task :update do answer = ask?("Which gem_hadar version? ", /^((?:\d+.){2}(?:\d+))$/) unless answer warn "Invalid version specification!" exit 1 end gem_hadar_version = answer[0] filename = "#{name}.gemspec" old_data = File.read(filename) new_data = old_data.gsub( /(add_(?:development_)?dependency\(%q<gem_hadar>, \["~> )([\d.]+)("\])/ ) { "#$1#{gem_hadar_version}#$3" } if old_data == new_data warn "#{filename.inspect} already depends on gem_hadar "\ "#{gem_hadar_version} => Do nothing." else warn "Upgrading #{filename.inspect} to #{gem_hadar_version}." secure_write(filename) do |spec| spec.write new_data end end end end end |
#gem_push_task ⇒ Object
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/gem_hadar.rb', line 561 def gem_push_task namespace :gem do path = "pkg/#{name_version}.gem" desc "Push gem file #{File.basename(path)} to rubygems" if developing task :push => :build do puts "Skipping push to rubygems while developing mode is enabled." end else task :push => :build do if File.exist?(path) if ask?("Do you really want to push #{path.inspect} to rubygems? "\ "(yes/NO) ", /\Ayes\z/i) then key = ENV['GEM_HOST_API_KEY'].full? { |k| "--key #{k} " } sh "gem push #{key}#{path}" else exit 1 end else warn "Cannot push gem to rubygems: #{path.inspect} doesn't exist." exit 1 end end end end end |
#gems_install_task(&block) ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/gem_hadar.rb', line 251 def gems_install_task(&block) block ||= proc { sh 'bundle install' } desc 'Install all gems from the Gemfile' namespace :gems do task :install => :gemspec , &block end end |
#gemspec ⇒ Gem::Specification
The gemspec method creates and returns a new Gem::Specification object that defines the metadata and dependencies for the gem package.
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
# File 'lib/gem_hadar.rb', line 871 def gemspec Gem::Specification.new do |s| s.name = name s.version = ::Gem::Version.new(version) s. = s.email = email s.homepage = assert_valid_link(:homepage, homepage) s.summary = summary s.description = description gem_files.full? { |f| s.files = Array(f) } test_files.full? { |t| s.test_files = Array(t) } extensions.full? { |e| s.extensions = Array(e) } bindir.full? { |b| s.bindir = b } executables.full? { |e| s.executables = Array(e) } licenses.full? { |l| s.licenses = Array(licenses) } .full? { |m| s. = m } required_ruby_version.full? { |v| s.required_ruby_version = v } s.add_development_dependency('gem_hadar', "~> #{VERSION[/\A\d+\.\d+/, 0]}") for d in @development_dependencies s.add_development_dependency(*d) end for d in @dependencies if s.respond_to?(:add_runtime_dependency) s.add_runtime_dependency(*d) else s.add_dependency(*d) end end require_paths.full? { |r| s.require_paths = Array(r) } if title s. << '--title' << title else s. << '--title' << "#{name.camelize} - #{summary}" end if readme s. << '--main' << readme s.extra_rdoc_files << readme end doc_files.full? { |df| s.extra_rdoc_files.concat Array(df) } end end |
#gemspec_task ⇒ Object
379 380 381 382 383 384 385 386 |
# File 'lib/gem_hadar.rb', line 379 def gemspec_task desc 'Create a gemspec file' task :gemspec => :version do filename = "#{name}.gemspec" warn "Writing to #{filename.inspect} for #{version}" secure_write(filename, gemspec.to_ruby) end end |
#git_remote ⇒ Object
508 509 510 |
# File 'lib/gem_hadar.rb', line 508 def git_remote ENV.fetch('GIT_REMOTE', 'origin').split(/\s+/).first end |
#git_remotes ⇒ Array<String>
The git_remotes method retrieves the list of remote repositories configured for the current Git project.
It first attempts to read the remotes from the ENV environment variable, splitting it by whitespace. If this is not available, it falls back to querying the local Git repository using ‘git remote`.
950 951 952 953 954 |
# File 'lib/gem_hadar.rb', line 950 def git_remotes remotes = ENV['GIT_REMOTE'].full?(:split, /\s+/) remotes or remotes = `git remote`.lines.map(&:chomp) remotes end |
#git_remotes_task ⇒ Object
589 590 591 592 593 594 595 596 |
# File 'lib/gem_hadar.rb', line 589 def git_remotes_task task :git_remotes do puts git_remotes.map { |r| url = `git remote get-url #{r.inspect}`.chomp "#{r} #{url}" } end end |
#github_release_task ⇒ Object
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/gem_hadar.rb', line 657 def github_release_task namespace :github do unless github_api_token = ENV['GITHUB_API_TOKEN'].full? warn "GITHUB_API_TOKEN not set. => Skipping github release task." task :release return end desc "Create a new GitHub release for the current version with a changelog" task :release do yes = ask?( "Do you want to publish a release message on github? (y/n%{default}) ", /\Ay/i, default: ENV['GITHUB_RELEASE_ENABLED'] ) unless yes warn "Skipping publication of a github release message." next end if %r(\A/*(?<owner>[^/]+)/(?<repo>[^/.]+)) =~ github_remote_url&.path rc = GitHub::ReleaseCreator.new(owner:, repo:, token: github_api_token) tag_name = version_tag(version) target_commitish = `git show -s --format=%H #{tag_name.inspect}^{commit}`.chomp body = edit_temp_file(create_body) if body.present? begin response = rc.perform(tag_name:, target_commitish:, body:) puts "Release created successfully! See #{response.html_url}" rescue => e warn e. end else warn "Skipping creation of github release message." end else warn "Could not derive github remote url from git remotes. => Skipping github release task." end end end end |
#github_remote_url ⇒ URI?
The github_remote_url method retrieves and parses the GitHub remote URL from the local Git configuration.
It executes ‘git remote -v` to get all remote configurations, extracts the push URLs, processes them to construct valid URIs, and returns the first URI pointing to GitHub.com.
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'lib/gem_hadar.rb', line 1023 def github_remote_url if remotes = `git remote -v` remotes_urls = remotes.scan(/^(\S+)\s+(\S+)\s+\(push\)/) remotes_uris = remotes_urls.map do |name, url| if %r(\A(?<scheme>[^@]+)@(?<hostname>[A-Za-z0-9.]+):(?:\d*)(?<path>.*)) =~ url path = ?/ + path unless path.start_with? ?/ url = 'ssh://s@%s%s' % [ scheme, hostname, path ] # approximate correct URIs end URI.parse(url) end remotes_uris.find { |uri| uri.hostname == 'github.com' } end end |
#has_to_be_set(name) ⇒ Object
50 51 52 |
# File 'lib/gem_hadar.rb', line 50 def has_to_be_set(name) fail "#{self.class}: #{name} has to be set for gem" end |
#ignore(*args) ⇒ Object
227 228 229 230 231 232 233 |
# File 'lib/gem_hadar.rb', line 227 def ignore(*args) if args.empty? ignore_files else args.each { |a| ignore_files << a } end end |
#install_library(&block) ⇒ Object
204 205 206 207 208 209 |
# File 'lib/gem_hadar.rb', line 204 def install_library(&block) @install_library_block = -> do desc 'Install executable/library into site_ruby directories' task :install => :prepare_install, &block end end |
#install_library_task ⇒ Object
396 397 398 |
# File 'lib/gem_hadar.rb', line 396 def install_library_task @install_library_block.full?(:call) end |
#master_prepare_task ⇒ Object
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/gem_hadar.rb', line 512 def master_prepare_task namespace :master do desc "Prepare a remote git repository for this project" task :prepare do puts "Create a new remote git repository for #{name.inspect}" remote_name = ask?('Name (default: origin) ? ', /^.+$/). full?(:[], 0) || 'origin' dir = ask?("Directory (default: /git/#{name}.git)? ", /^.+$/). full?(:[], 0) || "/git/#{name}.git" ssh_account = ask?('SSH account (format: login@host)? ', /^[^@]+@[^@]+/). full?(:[], 0) || exit(1) sh "ssh #{ssh_account} 'git init --bare #{dir}'" sh "git remote add -m master #{remote_name} #{ssh_account}:#{dir}" end end end |
#master_push_task ⇒ Object
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/gem_hadar.rb', line 545 def master_push_task namespace :master do git_remotes.each do |gr| namespace gr.to_sym do desc "Push master to git remote #{gr}" task :push do sh "git push #{gr} master" end end end desc "Push master #{version} to all git remotes: #{git_remotes * ' '}" task :push => git_remotes.map { |gr| :"master:#{gr}:push" } end end |
#package_ignore(*args) ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/gem_hadar.rb', line 235 def package_ignore(*args) if args.empty? package_ignore_files else args.each { |a| package_ignore_files << a } end end |
#package_task ⇒ Object
388 389 390 391 392 393 394 |
# File 'lib/gem_hadar.rb', line 388 def package_task clean 'pkg' Gem::PackageTask.new(gemspec) do |pkg| pkg.need_tar = true pkg.package_files += gem_files end end |
#push_task ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/gem_hadar.rb', line 696 def push_task master_prepare_task version_push_task master_push_task gem_push_task git_remotes_task github_release_task task :modified do changed_files = `git status --porcelain`.gsub(/^\s*\S\s+/, '').lines unless changed_files.empty? warn "There are still modified files:\n#{changed_files * ''}" exit 1 end end desc "Push master and version #{version} all git remotes: #{git_remotes * ' '}" task :push => i[ modified build master:push version:push gem:push github:release ] end |
#rcov_task ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/gem_hadar.rb', line 436 def rcov_task if defined?(::Rcov) rt = ::Rcov::RcovTask.new(:run_rcov) do |t| t.libs << test_dir t.libs.concat require_paths.to_a t.libs.uniq! t.test_files = test_files t.verbose = true t.rcov_opts = %W[-x '\\b#{test_dir}\/' -x '\\bgems\/'] end desc 'Run the rcov code coverage tests' task :rcov => [ (:compile if extensions.full?), rt.name ].compact clobber 'coverage' else desc 'Run the rcov code coverage tests' task :rcov do warn "rcov doesn't work for some reason, have you tried 'gem install rcov'?" end end end |
#require_path(path = nil) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/gem_hadar.rb', line 88 def require_path(path = nil) if path self.require_paths = Set[path] else require_paths.first end end |
#rvm(&block) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/gem_hadar.rb', line 181 def rvm(&block) if block @rvm = RvmConfig.new(&block) elsif !@rvm @rvm = RvmConfig.new { } end @rvm end |
#rvm_task ⇒ Object
731 732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/gem_hadar.rb', line 731 def rvm_task desc 'Create .rvmrc file' task :rvm do secure_write('.rvmrc') do |output| output.write " rvm use \#{rvm.use}\n rvm gemset create \#{rvm.gemset}\n rvm gemset use \#{rvm.gemset}\n EOT\n end\n end\nend\n" |
#spec_task ⇒ Object
425 426 427 428 429 430 431 432 433 434 |
# File 'lib/gem_hadar.rb', line 425 def spec_task defined? ::RSpec::Core::RakeTask or return st = RSpec::Core::RakeTask.new(:run_specs) do |t| t.ruby_opts ||= '' t.ruby_opts << ' -I' << ([ spec_dir ] + require_paths.to_a).uniq * ':' t.pattern = spec_pattern t.verbose = true end task :spec => [ (:compile if extensions.full?), st.name ].compact end |
#test_task ⇒ Object
414 415 416 417 418 419 420 421 422 423 |
# File 'lib/gem_hadar.rb', line 414 def test_task tt = Rake::TestTask.new(:run_tests) do |t| t.libs << test_dir t.libs.concat require_paths.to_a t.test_files = test_files t.verbose = true end desc 'Run the tests' task :test => [ (:compile if extensions.full?), tt.name ].compact end |
#version_bump_task ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/gem_hadar.rb', line 457 def version_bump_task namespace :version do namespace :bump do desc 'Bump major version' task :major do version = File.read('VERSION').chomp.version version.bump(:major) secure_write('VERSION') { |v| v.puts version } end desc 'Bump minor version' task :minor do version = File.read('VERSION').chomp.version version.bump(:minor) secure_write('VERSION') { |v| v.puts version } end desc 'Bump build version' task :build do version = File.read('VERSION').chomp.version version.bump(:build) secure_write('VERSION') { |v| v.puts version } end end end end |
#version_diff_task ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/gem_hadar.rb', line 330 def version_diff_task namespace :version do desc "List all versions in order" task :list do system 'git fetch --tags' $?.success? or exit $?.exitstatus puts versions end desc "Displaying the diff from env var VERSION to the next version or HEAD" task :diff do = versions.map { version_tag(_1) } + %w[ HEAD ] found_version_tag = .index(version_tag(version)) found_version_tag.nil? and fail "cannot find version tag #{version_tag(version)}" start_version, end_version = [found_version_tag, 2] puts color(172) { "Showing diff from version %s to %s:" % [ start_version, end_version ] } puts `git diff --color=always #{start_version}..#{end_version}` end end end |
#version_log_diff(to_version: 'HEAD', from_version: nil) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/gem_hadar.rb', line 298 def version_log_diff(to_version: 'HEAD', from_version: nil) if to_version == 'HEAD' if from_version.blank? from_version = versions.last else unless versions.find { |v| v == from_version } fail "Could not find #{from_version.inspect}." end end `git log -p #{version_tag(from_version)}..HEAD` else unless versions.find { |v| v == to_version } fail "Could not find #{to_version.inspect}." end if from_version.blank? from_version = versions.each_cons(2).find do |previous_version, v| if v == to_version break previous_version end end unless from_version fail "Could not find version before #{to_version.inspect}." end else unless versions.find { |v| v == from_version } fail "Could not find #{from_version.inspect}." end end `git log -p #{version_tag(from_version)}..#{version_tag(to_version)}` end end |
#version_push_task ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/gem_hadar.rb', line 529 def version_push_task namespace :version do git_remotes.each do |gr| namespace gr.to_sym do desc "Push version #{version} to git remote #{gr}" task :push do sh "git push #{gr} v#{version}" end end end desc "Push version #{version} to all git remotes: #{git_remotes * ' '}" task :push => git_remotes.map { |gr| :"version:#{gr}:push" } end end |
#version_show_task ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/gem_hadar.rb', line 280 def version_show_task namespace :version do desc "Displaying the current version" task :show do require path_name dir = File.join('lib', path_name) version_file = File.join(dir, 'version.rb') m = Module.new m.instance_eval File.read(version_file) version_rb = m.const_get( [ path_module, 'VERSION' ] * '::' ) equal = version == version_rb ? '==' : '!=' puts "version.rb=#{version_rb} #{equal} VERSION=#{version}" end end end |
#version_tag(version) ⇒ String
The version_tag method prepends a ‘v’ prefix to the given version string.
1011 1012 1013 |
# File 'lib/gem_hadar.rb', line 1011 def version_tag(version) version.dup.prepend ?v end |
#version_tag_task ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/gem_hadar.rb', line 484 def version_tag_task namespace :version do desc "Tag this commit as version #{version}" task :tag do force = ENV['FORCE'].to_i == 1 begin sh "git tag -a -m 'Version #{version}' #{'-f' if force} #{version_tag(version)}" rescue RuntimeError if `git diff v#{version}..HEAD`.empty? puts "Version #{version} is already tagged, but it's no different" else if ask?("Different version tag #{version} already exists. Overwrite with "\ "force? (yes/NO) ", /\Ayes\z/i) force = true retry else exit 1 end end end end end end |
#version_task ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/gem_hadar.rb', line 259 def version_task desc m = "Writing version information for #{name}-#{version}" task :version do puts m mkdir_p dir = File.join('lib', path_name) secure_write(File.join(dir, 'version.rb')) do |v| v.puts " \#{module_type} \#{path_module}\n # \#{path_module} version\n VERSION = '\#{version}'\n VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:\n VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:\n VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:\n VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:\n end\n EOT\n version_epilogue.full? { |ve| v.puts ve }\n end\n end\nend\n" |
#versions ⇒ Array<String>
The versions method retrieves and processes the list of git tags that match semantic versioning patterns.
It executes ‘git tag` to get all available tags, filters them using a regular expression to identify valid version strings, removes any ’v’ prefix from each version string, trims whitespace, and sorts the resulting array based on semantic versioning order.
order according to semantic versioning rules.
1000 1001 1002 1003 1004 |
# File 'lib/gem_hadar.rb', line 1000 def versions @versions ||= `git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/).map(&:chomp).map { _1.sub(/\Av/, '') }.sort_by(&:version) end |
#warn(*msgs) ⇒ Object
The warn method displays warning messages using orange colored output.
920 921 922 923 |
# File 'lib/gem_hadar.rb', line 920 def warn(*msgs) msgs.map! { |m| color(208) { m } } super(*msgs, uplevel: 1) end |
#write_gemfile ⇒ Object
The write_gemfile method creates and writes the default Gemfile content if it doesn’t exist. If a custom Gemfile exists, it only displays a warning.
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/gem_hadar.rb', line 823 def write_gemfile default_gemfile =" # vim: set filetype=ruby et sw=2 ts=2:\n\n source 'https://rubygems.org'\n\n gemspec\n EOT\n current_gemfile = File.exist?('Gemfile') && File.read('Gemfile')\n case current_gemfile\n when false\n secure_write('Gemfile') do |output|\n output.write default_gemfile\n end\n when default_gemfile\n ;;\n else\n warn \"INFO: Current Gemfile differs from default Gemfile.\"\n end\nend\n" |
#write_ignore_file ⇒ Object
The write_ignore_file method writes the current ignore_files configuration to a .gitignore file in the project root directory.
815 816 817 818 819 |
# File 'lib/gem_hadar.rb', line 815 def write_ignore_file secure_write('.gitignore') do |output| output.puts(ignore.sort) end end |
#yard_task ⇒ Object
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 |
# File 'lib/gem_hadar.rb', line 744 def yard_task defined? YARD or return namespace :yard do my_yard_dir = Pathname.new(yard_dir) desc 'Create yard documentation (including private)' task :private do sh "yardoc -o #{my_yard_dir}" end desc 'View the yard documentation' task :view do index_file = my_yard_dir + 'index.html' File.exist?(index_file) sh "open #{index_file}" end desc 'Clean the yard documentation' task :clean do rm_rf my_yard_dir end desc 'List all undocumented classes/modules/methods' task :'list-undoc' do sh "yard stats --list-undoc" end end desc 'Create the yard documentation and view it' task :yard => i[ yard:private yard:view ] end |