Chapter 10. Automating workflows with commands

 

This chapter covers

  • A simple release command
  • Improving discoverability of a command with help messages
  • Chaining actions in a command
  • Using custom tasks in the release script
  • Custom parsing with commands

Sometimes executing one task isn’t enough; there are several things that need to happen. Rather than creating an external script file that can run sbt more than once, sbt provides a commands API that can be used to create workflows that go beyond doing one thing. Let’s start with an example.

Throughout the chapter, you’ll work on the release script for the preowned-kittens website. This script involves a lot of different components, and you’d like it to be as simple as release 1.0 for your developers. To protect your company from issuing bad releases, the script should also have safety measures baked in, such as these:

  • Ensuring all the tests run and pass
  • Ensuring there are no uncommitted changes
  • Creating and pushing a version control tag

10.1. Creating a simple command

Let’s start with creating the simplest release command you can. This command should run all your unit tests before publishing the project. For the release script, you’re going to keep the configuration separate from the main build of the project for two reasons:

10.2. Running tasks in parallel

10.3. Parsing input with commands

10.4. Creating useful help messages

10.5. Summary