Merge branch '21214-dav-virtual-projects'
[arvados.git] / sdk / ruby-google-api-client / rakelib / git.rake
1 namespace :git do
2   namespace :tag do
3     desc 'List tags from the Git repository'
4     task :list do
5       tags = `git tag -l`
6       tags.gsub!("\r", '')
7       tags = tags.split("\n").sort {|a, b| b <=> a }
8       puts tags.join("\n")
9     end
10
11     desc 'Create a new tag in the Git repository'
12     task :create do
13       changelog = File.open('CHANGELOG.md', 'r') { |file| file.read }
14       puts '-' * 80
15       puts changelog
16       puts '-' * 80
17       puts
18
19       v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
20       abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
21
22       git_status = `git status`
23       if git_status !~ /nothing to commit \(working directory clean\)/
24         abort "Working directory isn't clean."
25       end
26
27       tag = "#{PKG_NAME}-#{PKG_VERSION}"
28       msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
29
30       existing_tags = `git tag -l #{PKG_NAME}-*`.split('\n')
31       if existing_tags.include?(tag)
32         warn('Tag already exists, deleting...')
33         unless system "git tag -d #{tag}"
34           abort 'Tag deletion failed.'
35         end
36       end
37       puts "Creating git tag '#{tag}'..."
38       unless system "git tag -a -m \"#{msg}\" #{tag}"
39         abort 'Tag creation failed.'
40       end
41     end
42   end
43 end
44
45 task 'gem:release' => 'git:tag:create'