Run one rake task after another completes

You can use enhance to extend one task with other:

task :extra_behavior do
  # extra
end

Rake::Task["first:task"].enhance do
  Rake::Task[:extra_behavior].invoke
end
  • Reference
  • Reference

Passing a task as an argument to enhance causes it to run BEFORE the task you are "enhancing".

Rake::Task["task_A"].enhance(["task_B"])
# Runs task_B
# Runs task_A

Passing a task to enhance in a block causes it to run AFTER the task you are "enhancing".

Rake::Task["task_A"].enhance do
  Rake::Task["task_B"].execute
end
# Runs task_A
# Runs task_B

Reference: Rake Task enhance Method Explained