Skip to content

Commit 0162656

Browse files
Prevent duplicate tags
1 parent 209dc9a commit 0162656

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Gemfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
source 'https://rubygems.org'
2-
gemspec
3-
4-
gem 'yard'
2+
gemspec

Rakefile

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# encoding: utf-8
2+
# ruby_lib Rakefile
23
require 'rubygems'
34
require 'rake'
45
require 'date'
6+
require 'posix/spawn'
57

68
# Defines gem name.
79
def repo_name; 'appium_lib' end # ruby_lib published as appium_lib
@@ -63,6 +65,11 @@ task :dev do
6365
sh 'gem install --no-rdoc --no-ri redcarpet'
6466
end
6567

68+
def tag_exists tag_name
69+
cmd = %Q(git branch -a --contains "#{tag_name}")
70+
POSIX::Spawn::Child.new(cmd).out.include? '* master'
71+
end
72+
6673
# Inspired by Gollum's Rakefile
6774
desc 'Build and release a new gem to rubygems.org'
6875
task :release => :gem do
@@ -71,16 +78,20 @@ task :release => :gem do
7178
exit!
7279
end
7380

81+
# Commit then pull before pushing.
82+
tag_name = "v#{version}"
83+
raise 'Tag already exists!' if tag_exists tag_name
84+
7485
# Commit then pull before pushing.
7586
sh "git commit --allow-empty -am 'Release #{version}'"
7687
sh 'git pull'
77-
sh "git tag v#{version}"
78-
# update notes and docs now that there's a new tag
88+
sh "git tag #{tag_name}"
89+
# update notes now that there's a new tag
7990
Rake::Task['notes'].execute
8091
Rake::Task['docs'].execute
8192
sh "git commit --allow-empty -am 'Update release notes'"
8293
sh 'git push origin master'
83-
sh "git push origin v#{version}"
94+
sh "git push origin #{tag_name}"
8495
sh "gem push #{repo_name}-#{version}.gem"
8596
end
8697

appium_lib.gemspec

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
3030
s.add_runtime_dependency 'toml', '~> 0.0.4'
3131

3232
s.add_development_dependency 'rake', '~> 10.0.4'
33+
s.add_development_dependency 'yard', '~> 0.8.7.3'
34+
s.add_development_dependency 'posix/spawn', '~> 0.3.6'
3335

3436
s.files = `git ls-files`.split "\n"
3537
end

0 commit comments

Comments
 (0)