Thursday, July 18, 2013

Tagging Git projects with Ruby

It has been a while since I wrote any Ruby and I've never written much but today I needed to tag a bunch of projects in Git that I used to do through a Groovy script in Jenkins.  Since I might need to become a Rails dev in the near future I figured I would write this with Ruby.


1:  projects = [  
2:   'project1',  
3:   'project2'  
4:  ]  
5:    
6:  tag = ARGV[0]  
7:    
8:  puts "Tagging projects at #{tag}"  
9:    
10:  def tag_project(tag, project)  
11:   Dir.chdir(project) do  
12:   system "git pull"  
13:   system "git tag #{tag}"  
14:   system "git push --tags"  
15:   end  
16:  end  
17:    
18:  projects.each do |project|  
19:    
20:   if !File.exists? project  
21:   system "git clone git@github.com:fork/#{project}.git"  
22:   end  
23:   tag_project tag, project  
24:  end  

That's it!

No comments:

Post a Comment