There is rake
as a Ruby version of make and ant. This will be processed automatically according to the description in Rakefile
.
This time, I would like to make the work easier by creating a Rakefile
that automates the process up to Git's" add-commit-pull-push ".
rake
A typical Rakefile
is
Rakefile
task :default do
system 'rake -T'
exit
end
desc 'hello NAME'
task :hello do
name = ARGV[1]
puts "Hello #{name}!"
exit
end
When executed with this Rakefile
> rake
-> rake hello # hello NAME
> rake hello Wor
Hello Wor!
I was able to automate the work wonderfully.
Now automate the work up to "add ~ push" in Git.
First, automate the pull of Git. Using the function system
that invokes the system command,
Rakefile
desc 'git pull'
task :pull do
p comm = "git pull origin main"
system comm
exit
end
You can run it with the following command.
> rake pull
Next, the Rakefile
that automates the work up to" add ~ push "of Git, which is the main purpose of this time, is
Rakefile
desc 'git push'
task :push do
p comm = "git add -A"
system comm
p comm = "git commit -m \'hoge\'"
system comm
p comm = "git pull origin main"
system comm
p comm = "git push origin main"
system comm
exit
end
However, if nothing is done, a large number of "hoge" commit messages will be committed.
Allows you to change the commit message yourself.
Rakefile
require 'colorize'
desc 'git push'
task :push do
msg = ARGV[1]
p comm = "git add -A"
system comm
comm = "git commit -m \'" + msg + "\'"
puts comm.green
system comm
p comm = "git pull origin main"
system comm
p comm = "git push origin main"
system comm
exit
end
You can run it with the following command.
> rake push
Chart type ruby-appendix-IV (rake)
Recommended Posts