Bake your releases

Working on various golang projects, I found myself frequently committing changes, generating a new binary and testing it out. I wanted to implement a semantic versioning scheme and some automation around deployment. I couldn't find any existing tools to do for me, what the Grunts, Gulps and Brunch's do for nodejs projects.

So I wrote one ... bake

bake is a minimal build, release and deploy tool. It wraps around the existing go build tool and simplifies versioning binaries using a version controlled file and git tags. Optionally, it can also upload the generated binary to Google Drive for archiving and further automation.

Let's consider a simple example, I wrote a cool new random quote generator in golang quotemeister and checked it into a github repo. I can start using bake to manage the versioning for my project, like so.

cd $GOPATH/src/quotemeister  
bake next  

This generates a new VERSION file in the project directory, starts it off with an initial version 0.1.0

Next bake will build the binary as .dist/quote-meister-$ARCH-$VERSION where $ARCH is the arch of your development machine and $VERSION is picked up from the version file. The version number is passed in as a string to the binary via build flags and can be used to embed the current version.

var (  
    // Flags
    VERSION string // populated via ldflags
)

In this case, the VERSION global is populated with the current version number (as a string) and can be used elsewhere in your code.

Then bake git adds the file to have it version controlled as well. If there are no other uncommitted changes in my local git repo, it will also commit this change and git push to remote.

bake will then check if you have an oauth token configured for Google Drive and if so, it will upload the generated binary to Google Drive for archive and further automation/deployment.

Apart from the build step and versioning step, all other steps can be selectively enabled/disabled via command line flags.

For example, to skip git push to remote

bake next -enable_git_push=false  

All control flags as of the current version 0.1.3 of bake, are

// Enable/Disable git commit for the version file.
-enable_git_commit
// Enable/Disable adding a new git tag with a new version.
-enable_git_tag
// Enable/Disable git push to remote.
-enable_git_push
// This is a combination of all above enable_git_flags and
// supersedes them, if false. If set to true (default),
// individual flags are checked in addition.
-enable_git_tasks
// Enable/Disable uploading generated binaries to Google Drive.
-enable_uploads

Using bake to manage releases is similar, with two additional commands.

To generate the next build numbered binary

bake next  

This will generate a new binary at the next build number. For example, if the current version is 0.3.3, this command will generate a new binary at 0.3.4

bake minor  

This will generate a new binary at the next minor version. For example, if the current version is 0.3.3, this command will generate a new binary at 0.4.0.

bake major  

This will generate a new binary at the next major version. For example, if the current version is 0.3.3, this command will generate a new binary at 1.0.0.

Note that the build number is reset with each major or minor version increment.

There are two additional commands for cases where you do not want to generate a new version.

bake rebuild  

This will simply, rebuild the binary at the current version. The distinction from a simple go build is that this will also pass in the current version via build flags.

bake reupload  

This will rebuild the binary at the current version as well as reupload it to Google Drive.

Although bake is minimal and there are lots of things that could be improved/added, I have been using bake successfully for almost all my golang projects and it has been sufficient and useful for my use cases.

Give it a spin on your next golang project and let me know how it works out for you. If you'd like to check the source or contribute, it's on github at github.com/rockstardevs/bake.