Last active
August 29, 2015 14:02
-
-
Save gabrielrinaldi/0b622a3a39beb4e73c8d to your computer and use it in GitHub Desktop.
Build tagging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/bin/ruby | |
| # Check if version file exists | |
| check = %x( [ -e .version ] && echo 'found' || echo 'miss' ).delete!("\n") | |
| unless check.eql? 'found' | |
| abort('Cannot find version file. Aborting.') | |
| end | |
| # Get major and minor version from version file | |
| version = %x( head -n 1 .version ).delete!("\n") | |
| # Check if version is valid | |
| unless version && version[/(^[0-9]*\.[0-9]*)/] | |
| abort('Version is not valid. Aborting') | |
| end | |
| # Get number of commits as build number | |
| build = %x( git rev-list HEAD | wc -l | tr -d ' ' ).delete!("\n") | |
| # Initialize fix number | |
| fix = 0 | |
| # Check if this is the first tag | |
| unless %x( git tag ).eql? '' | |
| # Get last tag in repository | |
| last_tag = %x( git describe --tags $(git rev-list --tags --max-count=1) ).delete!("\n") | |
| # Parse version and build from last tag | |
| last_tag[/([0-9]*\.[0-9]*)\.([0-9]*)/] unless last_tag[/([0-9]*\.[0-9]*)\.([0-9]*)-([0-9]*)/] | |
| if !$3.nil? && $3.eql?(build) | |
| puts 'Version already tagged. Exiting.' | |
| exit | |
| end | |
| # Add fix number or bump if same version as last tag | |
| fix = $2.to_i + 1 if $1.eql? version | |
| end | |
| # Tag repository with new version | |
| new_version = "#{version}.#{fix}-#{build}" | |
| puts "New version: #{new_version}" | |
| %x( git tag #{new_version} ) | |
| %x( git push --tags ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment