Skip to content
This repository
Browse code

Merge branch 'release' -- some deps for creating versioned releases.

  • Loading branch information...
commit 99e9284bda111d568b47605b814d70b364b29260 2 parents 5d42320 + e32079e
Ben Hoskings authored March 31, 2013

Showing 1 changed file with 89 additions and 0 deletions. Show diff stats Hide diff stats

  1. 89  deps/release.rb
89  deps/release.rb
... ...
@@ -0,0 +1,89 @@
  1
+meta :release do
  2
+  def repo
  3
+    @repo ||= Babushka::GitRepo.new('.')
  4
+  end
  5
+  def release_tag
  6
+    version.to_s.sub(/^(?!v)/, 'v')
  7
+  end
  8
+  def git_log from, to
  9
+    log shell("git log --graph --date-order --pretty='format:%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset' #{from}..#{to}")
  10
+  end
  11
+  def latest_tag
  12
+    version = shell('git tag').lines.map(&:to_version).max
  13
+    "v#{version}"
  14
+  end
  15
+end
  16
+
  17
+dep 'release', :version, :version_file, :template => 'release' do
  18
+  requires 'release exists'.with(version, version_file)
  19
+  setup {
  20
+    if latest_tag > release_tag
  21
+      log_warn "There is already a newer release than #{release_tag} (#{latest_tag})."
  22
+    end
  23
+  }
  24
+  met? {
  25
+    shell("git ls-remote --tags origin").split("\n").grep(%r{refs/tags/#{release_tag}$}).any?
  26
+  }
  27
+  meet {
  28
+    log_block "Pushing #{release_tag} to origin" do
  29
+      shell! 'git push origin'
  30
+      shell! 'git push origin --tags'
  31
+    end
  32
+  }
  33
+end
  34
+
  35
+# This is the messy one.
  36
+dep 'release exists', :version, :version_file, :template => 'release' do
  37
+  version_file.default!('./lib/babushka.rb')
  38
+
  39
+  def update_version!
  40
+    sed_expression = %q{s/^(\s+VERSION\s+=\s+).*/\1'%s'/} % version
  41
+    shell! 'sed', '-i.bak', '-E', sed_expression, version_file
  42
+    shell! 'rm', "#{version_file}.bak"
  43
+  end
  44
+
  45
+  requires 'repo on master'
  46
+  requires_when_unmet 'repo clean', 'descendant of last release', 'build passing'
  47
+
  48
+  met? {
  49
+    repo.resolve(release_tag)
  50
+  }
  51
+  meet {
  52
+    git_log "#{latest_tag}", 'HEAD'
  53
+    confirm "Create #{release_tag} from #{latest_tag} + this changeset?" do
  54
+      log_block("Writing version to #{version_file}") { update_version! }
  55
+      log_shell "Committing", "git commit #{version_file} --message '#{release_tag} - ' --edit"
  56
+      log_shell "Tagging", "git tag '#{release_tag}'"
  57
+    end
  58
+  }
  59
+end
  60
+
  61
+dep 'repo on master', :template => 'release' do
  62
+  met? {
  63
+    repo.current_branch == 'master' || unmeetable!("Releases have to be made from master.")
  64
+  }
  65
+end
  66
+
  67
+dep 'repo clean', :template => 'release' do
  68
+  met? {
  69
+    repo.repo_shell("git diff") # Clear git's internal cache, which sometimes says the repo is dirty when it isn't.
  70
+    repo.clean? || unmeetable!("The remote repo has local changes.")
  71
+  }
  72
+end
  73
+
  74
+dep 'build passing' do
  75
+  met? {
  76
+    log_shell("Running specs", "bundle exec rspec --format documentation") ||
  77
+      unmeetable!("Can't make a release when the build is broken.")
  78
+  }
  79
+end
  80
+
  81
+dep 'descendant of last release', :template => 'release' do
  82
+  met? {
  83
+    if shell?("git rev-list HEAD | grep #{repo.resolve(latest_tag)}")
  84
+      log_ok "The most recent version (#{latest_tag} / #{repo.resolve(latest_tag)}) is a parent of HEAD."
  85
+    else
  86
+      unmeetable!("The most recent version (#{latest_tag} / #{repo.resolve(latest_tag)}) isn't a parent of HEAD.")
  87
+    end
  88
+  }
  89
+end

0 notes on commit 99e9284

Please sign in to comment.
Something went wrong with that request. Please try again.