Module: Physique::Tasks::Versionizer
- Defined in:
- lib/physique/tasks/versionizer.rb
Overview
Versionizer does versioning ITS OWN WAY!
Defines ENV vars:
* BUILD_VERSION
* NUGET_VERSION
* FORMAL_VERSION
Publishes symbol :build_version
Class Method Summary collapse
- .build_number ⇒ Object
-
.current_branch ⇒ Object
Determine the current branch returns: branch name.
- .define_versions(semver) ⇒ Object
- .gitflow_special ⇒ Object
- .gitflow_version(version) ⇒ Object
-
.last_commit ⇒ Object
- load the commit data returns: [short-commit
-
String].
-
.new(*sym) ⇒ Object
adds a new task with the given symbol to the Rake/Albacore application You can use this like any other albacore method, such as build, in order to give it parameters or dependencies, but there is no configuration object that you can configure.
- .special_prefix ⇒ Object
Class Method Details
.build_number ⇒ Object
92 93 94 |
# File 'lib/physique/tasks/versionizer.rb', line 92 def self.build_number ENV['BUILD_NUMBER'] || '0' end |
.current_branch ⇒ Object
Determine the current branch returns: branch name
78 79 80 81 82 83 84 |
# File 'lib/physique/tasks/versionizer.rb', line 78 def self.current_branch begin `git rev-parse --abbrev-ref HEAD`.chomp rescue 'master' end end |
.define_versions(semver) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/physique/tasks/versionizer.rb', line 41 def self.define_versions(semver) build = build_number { # just a monotonic inc :semver => semver, :build_number => build, :current_branch => current_branch, # purely M.m.p format :formal_version => "#{semver.format('%M.%m.%p')}", # four-numbers version, useful if you're dealing with COM/Windows :long_version => "#{semver.format('%M.%m.%p')}.#{build}", # extensible number w/ git hash :build_version => "#{semver.format('%M.%m.%p%s')}.#{last_commit[0]}", # nuget (not full semver 2.0.0-rc.1 support) see http://nuget.codeplex.com/workitem/1796 :nuget_version => semver.format('%M.%m.%p%s') } end |
.gitflow_special ⇒ Object
96 97 98 99 100 101 |
# File 'lib/physique/tasks/versionizer.rb', line 96 def self.gitflow_special prefix = special_prefix return version.special if prefix == 'master' "#{prefix}#{build_number}" end |
.gitflow_version(version) ⇒ Object
86 87 88 89 90 |
# File 'lib/physique/tasks/versionizer.rb', line 86 def self.gitflow_version(version) return unless ENV.include?('BUILD_NUMBER') version.special = gitflow_special version end |
.last_commit ⇒ Object
load the commit data
- returns: [short-commit
-
String]
67 68 69 70 71 72 73 |
# File 'lib/physique/tasks/versionizer.rb', line 67 def self.last_commit begin `git rev-parse --short HEAD`.chomp[0,6] rescue (ENV['BUILD_VCS_NUMBER'] || '000000')[0,6] end end |
.new(*sym) ⇒ Object
adds a new task with the given symbol to the Rake/Albacore application You can use this like any other albacore method, such as build, in order to give it parameters or dependencies, but there is no configuration object that you can configure. Copy-n-paste this code if you want something of your own.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/physique/tasks/versionizer.rb', line 21 def self.new(*sym) version = gitflow_version(XSemVer::SemVer.find) version_data = define_versions(version) Albacore.subscribe :build_version do |data| ENV['BUILD_VERSION'] = data.build_version ENV['NUGET_VERSION'] = data.nuget_version ENV['FORMAL_VERSION'] = data.formal_version ENV['LONG_VERSION'] = data.long_version end Albacore.define_task(*sym) do Albacore.publish :build_version, OpenStruct.new(version_data) end Albacore.define_task :version do puts version_data.inspect end end |
.special_prefix ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/physique/tasks/versionizer.rb', line 103 def self.special_prefix # TODO: There is a better way to do this. branch_name = current_branch return 'release' if branch_name.start_with? 'release/' return 'hotfix' if branch_name.start_with? 'hotfix/' return 'feature' if branch_name.start_with? 'feature/' branch_name end |