Automate your work with Rake

!macOS-11.1!ruby-2.7.2p137

Preface (Introduction)

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

Rakefile basics

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.

Git automation

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

Reference material

Chart type ruby-appendix-IV (rake)

Recommended Posts

Automate your work with Rake
Automate format with maven-formatter
@ClassRules doesn't work with PowerMockRunner
Tune your query with EXPLAIN
Make your own sampler with JMeter
Clean your code with Butter Knife
Shortcuts to streamline your Eclipse work
Work with Google Sheets from Java
Share it with your Instagram story!
When PyCall doesn't work with PyCall :: PythonNotFound
Decorate your Sinatra app with CSS
Check your internet connection with Alamofire