Module: VV::Automate
- Defined in:
- lib/vv/utility/automate.rb
Overview
Automate runs standalone from the rest of the repo, so the code here intentionally avoids using helpers that VV adds to ruby classes.
Class Method Summary collapse
- .annoying_command(args, command: nil) ⇒ Object
- .build(name:, argv: nil) ⇒ Object
- .build_simple(name:) ⇒ Object
- .push(name:) ⇒ Object
- .run(command: nil, annoying_command: nil) ⇒ Object
- .version(path:, argv:) ⇒ Object
Class Method Details
.annoying_command(args, command: nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/vv/utility/automate.rb', line 116 def args, command: nil command ||= "rake" test_dir = File.join File.(Dir.pwd), "test" temp_test_dir = "temp_test_dir_#{Random.identifier 6}" = "Cannot find test directory `#{test_dir}`." fail unless test_dir.is_directory_path? fail "Unexpected arg count" if args.size > 2 helper_file = "test_helper.rb" file, line_number = args if line_number.nil? file, line_number = file.split(String.colon)[0..1] end File.rename_directory test_dir, temp_test_dir sleep 0.01 File.make_directory test_dir path = file.split(File.separator).last new_filename = temp_test_dir.file_join path helper_file = temp_test_dir.file_join helper_file File.copy_into new_filename, test_dir File.copy_into helper_file, test_dir if line_number line_number = line_number.to_i! i = j = line_number - 1 lines = File.vv_readlines test_dir.file_join(path) while i > 0 line = lines[i] break if line.start_with? " def " i -= 1 end while j < lines.count line = lines[j] break if line.start_with? " end" j += 1 end content = (lines[0..3] + lines[i..j] + lines[-2..-1] ).join("\n") content += "\n" File.write test_dir.file_join(path), content end full_command = \ [ command, "rm -r #{test_dir}", "mv #{temp_test_dir} #{test_dir}" ].join(" && ") exec full_command # The below shouldn't run in normal operation, since # exec will replace the current process ensure File.remove_directory test_dir File.rename_directory temp_test_dir, test_dir end |
.build(name:, argv: nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vv/utility/automate.rb', line 67 def build( name: , argv: nil ) simple = %w[ simple force ].include? argv.first return build_simple name: name if simple puts %x{ find lib/ | \\ xargs git ls-files --error-unmatch > /dev/null 2>&1 \\ || ( echo && \\ echo "Warning: A file in lib/ is not tracked by git" && \\ echo ) rm #{name}-*.gem gem uninstall --ignore-dependencies #{name} > /dev/null bundle gem build #{name}.gemspec gem install $(readlink -f #{name}-*.gem | sort | tail -n 1 ) --pre } end |
.build_simple(name:) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/vv/utility/automate.rb', line 86 def build_simple( name: ) puts %x{ rm #{name}-*.gem gem uninstall --ignore-dependencies #{name} > /dev/null gem build --force #{name}.gemspec gem install --force --local $(readlink -f #{name}-*.gem | sort | tail -n 1 ) --pre } end |
.push(name:) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/vv/utility/automate.rb', line 95 def push( name: ) puts %x{ TAG_VERSION=$(./bin/version) git push origin HEAD && \\ gem push $(readlink -f #{name}-*.gem | sort | tail -n 1) && \\ git push origin v${TAG_VERSION} } end |
.run(command: nil, annoying_command: nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vv/utility/automate.rb', line 104 def run command: nil, annoying_command: nil command ||= "rake" ||= command args = ARGV.to_a # breaking out of binding.pry is hard without exec exec command if args.empty? return (args, command: ) end |
.version(path:, argv:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vv/utility/automate.rb', line 9 def version path:, argv: args = argv.to_a lines = File.read(path).split("\n") raise "Unknown number of arguments" if args.size > 1 version = lines[1].split(" = ")[-1].gsub("'","") if args.size < 1 puts version exit end command = args[0] weird = version.split(".").size != 3 raise "Only handles basic versions" if weird major, minor, point = version.split(".").map(&:to_i) if command == "+" point += 1 elsif command == "++" point = 0 minor += 1 elsif command == "+++" point = 0 minor = 0 major += 1 elsif command.split(".").size == 3 major, minor, point = command.split(".") elsif command == "reset" system("git checkout -- #{path}") exit elsif command == "commit" = "Bump version to #{version}" system("git commit -S --only #{path} -m \"#{message}\"") exit elsif %w[ help --help h -h ].include? command puts puts "Available commands are:" puts puts "+ - point increment" puts "++ - minor increment" puts "+++ - major increment" puts puts "x.y.z - to set version explicitly" puts "reset - to revert to version in git" puts exit end new_version = [major, minor, point].join(".") lines[1] = " VERSION = '#{new_version}'" lines << "" File.write(path, lines.join("\n")) end |