This creates and pushes tags to your git repository, please use with caution.
AutoTagger is a gem that helps you automatically create a date-stamped tag for each stage of your deployment, and deploy from the last tag from the previous environment.
Let's say you have the following workflow:
- Run all test on a Continuous Integration (CI) server
- Deploy to a staging server
- Deploy to a production server
You can use the
autotag command to tag releases on your CI box, then use the capistrano tasks to auto-tag each release.
sudo gem install auto_tagger
You will be able to set the date format from autotag and from capistrano:
$ autotag demo --date-format=%Y-%m-%d-%H-%M-%S
You will be able to tell auto_tagger to only create tags, not fetch or push them from autotag and from capistrano:
$ autotag demo --offline $ autotag demo --fetch-refs=false --push-refs=false
You will be able to specify how it creates refs (either by tags or by refs) in both autotag and capistrano:
$ autotag demo --ref-prefix=autotags
The api for the autotag executable will change (but will remain almost 100% backwards compatible):
$ autotag help $ autotag version $ autotag create <stage> $ autotag create <stage> --working-directory=../foo
You will be able to clean up old tags
$ autotag clean <stage> --refs-to-keep=10
You will be able to specify custom commit messages
$ autotag clean ci --message="Another successful build :)"
The autotag executable
Installing the gem creates an executable file named autotag, which takes the stage, optionally the path to the git repo, and options:
$ autotag demo # => creates a tag like demo/200804041234 in the current directory $ autotag demo . # => same as above $ autotag demo /Users/me/foo # => cd's to /Users/me/foo before creating the tag
By default, running autotag does the following:
$ git fetch origin --tags $ git tag <stage>/<timestamp> $ git push origin --tags
AutoTagger comes with 2 capistrano tasks:
release_tagger:set_branchtries to set the branch to the last tag from the previous environment.
release_tagger:create_refruns autotag for the current stage
require 'auto_tagger/recipes' # The :autotagger_stages variable is required set :autotagger_stages, [:ci, :staging, :production] # The :working_directory variable is optional, and defaults to Dir.pwd # :working_directory can be an absolute or relative path set :working_directory, "../../" task :production do # In each of your environments that need auto-branch setting, you need to set :stage set :stage, :production end task :staging do # If you do not set stage, it will not auto-set your branch # set :stage, :staging end # You need to add the before/ater callbacks yourself before "deploy:update_code", "release_tagger:set_branch" after "deploy", "release_tagger:create_ref" after "deploy", "release_tagger:write_tag_to_shared" after "deploy", "release_tagger:print_latest_refs"
Cpistano-ext multistage support
If you use capistano-ext multistage, you can use auto_tagger.
set :autotagger_stages, [:ci, :staging, :production] set :stages, [:staging, :production] set :default_stage, :staging require 'capistrano/ext/multistage'
When you deploy, autotagger will auto-detect your current stage.
This task sets the git branch to the latest tag from the previous stage. Assume you have the following tags in your git repository:
And the following stages in your capistrano file:
set :autotagger_stages, [:ci, :staging, :production]
The deployments would look like this:
cap staging release_tagger:set_branch # => sets branch to ci/01 cap production release_tagger:set_branch # => sets branch to staging/01
You can override with with the -Shead and -Stag options
cap staging release_tagger:set_branch -Shead=true # => sets branch to master cap staging release_tagger:set_branch -Stag=staging/01 # => sets branch to staging/01
If you add
before "deploy:update_code", "release_tagger:set_branch", you can just deploy with:
cap staging deploy
and the branch will be set for you automatically.
This cap task creates a new tag, based on the latest tag from the previous environment.
If there is no tag from the previous stage, it creates a new tag from the latest commit in your working directory.
If you don't specify any
autotagger_stages, autotagger will create a tag that starts with "production".
This task reads the git version from the text file in shared:
cap staging release_tagger:read_tag_from_shared
This task takes the latest tag from each environment and prints it to the screen. You can add it to your deploy.rb like so:
after "deploy", "release_tagger:print_latest_refs"
Or call it directly, like:
cap production release_tagger:print_latest_refs
This will produce output like:
** AUTO TAGGER: release tag history is: ** ci ci/20090331045345 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message ** staging staging/20090331050908 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message ** production production/20090331050917 8031807feb5f4f99dd83257cdc07081fa6080cba some commit message
You must be able to ssh into your box via localhost (remote login). To make this easier, add your own key to your own account:
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
To ensure that this has worked, try this:
If it asks you for a password, you've done something wrong.
To run the specs, first make sure you have the required gems:
gem install bundler bundle install
To run the cucumber features, execute:
Special thanks to:
- Brian Takita for the original recipes
- Mike Dalessio for his git fu
- Chad Wooley for his feature ideas
- Tim Holahan for his QA
- Pat Nakajima for making auto_tagger a better ruby citizen
- Josh Susser for recommending the date format changes
Copyright (c) 2009 [Jeff Dean], released under the MIT license