git-version-bump 0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,170 @@
1
+ Maintain your program versions entirely within git. No local files
2
+ required! All versioning information is stored using git tags.
3
+
4
+ This gem contains a command-line tool and set of Rake tasks to increment
5
+ and display your version numbers via git tags, and some associated Ruby code to use
6
+ inside a gemspec or your program to retrieve the current version number, for
7
+ use in builds and at runtime.
8
+
9
+
10
+ # Usage
11
+
12
+ Most of your day-to-day usage of `git-version-bump` will be via the command
13
+ line. When you bump a version, a new tag will be created representing the newly
14
+ incremented version number at the current commit. If no tags currently
15
+ exist, the previous version will be taken to be `0.0.0` and then incremented
16
+ accordingly.
17
+
18
+
19
+ ## On the command line
20
+
21
+ Pretty damned trivial:
22
+
23
+ git version-bump <major|minor|patch|show>
24
+
25
+ You can also shorten the specifier to any unique substring:
26
+
27
+ git version-bump ma
28
+ git version-bump mi
29
+ git version-bump p
30
+ git version-bump s
31
+
32
+ I recommend adding an alias to your `~/.gitconfig` file, for less typing:
33
+
34
+ [alias]
35
+ vb = version-bump
36
+
37
+ You can also add your own release notes to your release tags, by using the
38
+ `-n` (or `--notes`, if you like typing) option:
39
+
40
+ git version-bump -n minor
41
+
42
+ This will open an editor, containing a list of the commits since the last
43
+ release tag, in which you can type your release notes. If you follow
44
+ standard git commit style (a "heading" line, then a blank line, followed by
45
+ free-form text) you're perfectly positioned to use
46
+ [github-release](http://theshed.hezmatt.org/github-release) to make
47
+ gorgeous-looking release announcements to Github.
48
+
49
+
50
+ ## In your `Rakefile`
51
+
52
+ If you'd like to have access to the version-bumping goodness via `rake`, add
53
+ the following line to your `Rakefile`:
54
+
55
+ require 'git-version-bump/rake-tasks'
56
+
57
+ You will now have the following rake tasks available:
58
+
59
+ rake version:bump:major # bump major version (x.y.z -> x+1.0.0)
60
+ rake version:bump:minor # bump minor version (x.y.z -> x.y+1.0)
61
+ rake version:bump:patch # bump patch version (x.y.z -> x.y.z+1)
62
+ rake version:bump:show # Print current version number
63
+
64
+ (Since `version:bump:major` is a lot of typing, there are also shortcuts:
65
+ `v:b:major`, `v:b:maj`, `v:b:minor`, `v:b:min`, `v:b:patch`, `v:b:pat`, and
66
+ `v:b:p`)
67
+
68
+
69
+ ## In your Ruby code
70
+
71
+ To get access to this version information in your code (such as in your
72
+ `gemspec`, or the definition of a `::VERSION` constant), you can `require
73
+ 'git-version-bump'` and use the following methods:
74
+
75
+ GVB.version # Return the entire version string
76
+ GVB.major_version # Return just the 'major' portion of the version
77
+ GVB.minor_version # Return just the 'minor' portion of the version
78
+ GVB.patch_version # Return just the 'patch' portion of the version
79
+ GVB.internal_revision # Return "internal revision" information, or nil
80
+ GVB.date # Return the date of the most recent commit, or
81
+ # today's date if the tree is dirty
82
+
83
+ The "internal revision" is set when the tree is dirty, or when the latest
84
+ git commit doesn't correspond with a tag. In that case, the internal
85
+ revision will describe, in the manner of `git describe`, the full details of
86
+ the version of the code in use. This information will be part of the
87
+ version string provided by `gvb_version`.
88
+
89
+ If any of these methods are called when there isn't a tag or other version
90
+ information available, the version will be assumed to be `0.0.0.1.ENOTAG`
91
+ with a date of `1970-01-01`.
92
+
93
+
94
+ ### In your gemspec
95
+
96
+ Typically, you want to encode your version and commit date into your
97
+ gemspec, like this:
98
+
99
+ Gem::Specification.new do |s|
100
+ s.version = GVB.version
101
+ s.date = GVB.date
102
+
103
+ ...
104
+ end
105
+
106
+ The beauty of this method is that whenever you run a `rake build`, you'll
107
+ get a gem which is *accurately* versioned for the current state of your
108
+ repository. No more wondering if the `foobar-1.2.3` gem installed on your
109
+ system was built from pristine sources, or with that experimental patch you
110
+ were trying out...
111
+
112
+
113
+ ### In your gem
114
+
115
+ If, like me, you're one of those people who likes to be able to easily see
116
+ what version of a library you're running, then you probably like to define a
117
+ `VERSION` constant somewhere in your gem's namespace. That, too, is simple
118
+ to do:
119
+
120
+ require 'git-version-bump'
121
+
122
+ class Foobar
123
+ VERSION = GVB.version
124
+ end
125
+
126
+ This will work correctly inside your git tree, and also in your installed
127
+ gem. Magical!
128
+
129
+ #### For projects using lite tags
130
+
131
+ If you are using GitHub releases for your project or some other method that
132
+ involves light tags (tags with no annotations), you might notice that these
133
+ tags are not detected by git-version-bump by default. If you want these
134
+ commits to be detected then use the following configuration:
135
+
136
+ require 'git-version-bump'
137
+
138
+ class Foobar
139
+ # First parameter is use_local_git, second is include_lite_tags
140
+ VERSION = GVB.version(false, true)
141
+ end
142
+
143
+
144
+ ## Overriding the version
145
+
146
+ In very rare circumstances, while running in a git repo, you may wish to explicitly set the version or date returned by `GVB.version` or `GVB.date`, respectively.
147
+ This can be done by setting the repo's `versionBump.versionOverride` or `versionBump.dateOverride` config values, like so:
148
+
149
+ ```bash
150
+ git config versionBump.versionOverride 1.2.3
151
+ git config versionBump.dateOverride 1970-01-01
152
+ ```
153
+
154
+ Note that whatever you set those values to is used without validity checking; if you set it to something weird, you'll get weird results.
155
+
156
+
157
+ # Contributing
158
+
159
+ Send your pull requests to the [Github
160
+ repo](https://github.com/mpalmer/git-version-bump), or send patches to
161
+ `theshed+git-version-bump@hezmatt.org`. Bug reports can be sent to the same
162
+ place, although I greatly prefer patches.
163
+
164
+
165
+ # Licence
166
+
167
+ Unless otherwise specified, all code in this repository is licenced under
168
+ the terms of the GNU Public Licence, version 3, as published by the Free
169
+ Software Foundation. The full terms of this licence can be found in the
170
+ file LICENCE.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rdoc/task'
7
+
8
+ Rake::RDocTask.new do |rd|
9
+ rd.main = "README.md"
10
+ rd.title = 'git-version-bump'
11
+ rd.rdoc_files.include("README.md", "lib/**/*.rb")
12
+ end
13
+
14
+ task :release do
15
+ sh "git push --follow-tags"
16
+ sh "git release"
17
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV[0].nil? or
4
+ ARGV[0].empty? or
5
+ (ARGV.length == 1 && (ARGV[0] == "-d" || ARGV[0] == "--dry-run")) or
6
+ ARGV[0] == '-h' or
7
+ ARGV[0] == '--help'
8
+ $stderr.puts <<-EOF.gsub(/^\t\t/, '')
9
+ Usage: git version-bump [-n|--notes] [-l|--lite-tags] [-d|--dry-run] <major|minor|patch|show>
10
+
11
+ 'major': x.y.z -> x+1.0.0
12
+ 'minor': x.y.z -> x.y+1.0
13
+ 'patch': x.y.z -> x.y.z+1
14
+
15
+ 'show': Display the current GVB version
16
+
17
+ -d, --dry-run: Calculate and return the bump value, but don't update git workspace or remote
18
+ -n, --notes: Prompt for "release notes" to add to the release tag
19
+ -l, --lite-tags: Include non-annotated git tags
20
+ EOF
21
+ end
22
+
23
+ release_notes = ARGV.delete('-n') || ARGV.delete('--notes')
24
+ dry_run = ARGV.delete('-d') || ARGV.delete('--dry-run')
25
+ lite_tags = ARGV.delete('-l') || ARGV.delete('--lite-tags')
26
+
27
+ if ARGV[0].nil? or ARGV[0].empty?
28
+ exit 1
29
+ elsif ARGV[0] == '-h' or ARGV[0] == '--help'
30
+ exit 0
31
+ end
32
+
33
+ begin
34
+ require 'git-version-bump'
35
+
36
+ result = case ARGV[0].downcase
37
+ when /^maj?o?r?$/
38
+ "#{GVB.major_version(true) + 1}.0.0"
39
+ when /^min?o?r?$/
40
+ "#{GVB.major_version(true)}.#{GVB.minor_version(true)+1}.0"
41
+ when /^pa?t?c?h?$/
42
+ "#{GVB.major_version(true)}.#{GVB.minor_version(true)}.#{GVB.patch_version(true)+1}"
43
+ when /^sh?o?w?$/
44
+ puts GVB.version(true)
45
+ exit 0
46
+ else
47
+ $stderr.puts "Unknown argument: #{ARGV[0]}. Try --help."
48
+ exit 1
49
+ end
50
+
51
+ if dry_run
52
+ puts result
53
+ else
54
+ unless GVB.tag_version result, release_notes, lite_tags
55
+ exit 1
56
+ end
57
+ puts "Version is now #{GVB.version(true)}."
58
+ end
59
+ rescue GVB::VersionUnobtainable => ex
60
+ $stderr.puts "Could not obtain version information. #{ex.message} (git available: #{GVB.git_available?.inspect})"
61
+ exit 1
62
+ rescue GVB::CommandFailure => ex
63
+ $stderr.puts "#{ex.message} (exit status: #{ex.exitstatus})"
64
+ $stderr.puts "command output was:"
65
+ $stderr.puts "----8<----"
66
+ $stderr.puts ex.output
67
+ $stderr.puts "---->8----"
68
+ exit 1
69
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'git-version-bump'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "git-version-bump"
7
+
8
+ s.version = GVB.version
9
+ s.date = GVB.date
10
+
11
+ s.platform = Gem::Platform::RUBY
12
+ s.required_ruby_version = ">= 2.1.0"
13
+
14
+ s.homepage = "https://github.com/mpalmer/git-version-bump"
15
+ s.summary = "Manage your app version entirely via git tags"
16
+ s.authors = ["Matt Palmer"]
17
+
18
+ s.extra_rdoc_files = ["README.md"]
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = ["git-version-bump"]
21
+
22
+ s.add_development_dependency 'github-release'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'rdoc'
26
+ end
@@ -0,0 +1,49 @@
1
+ require 'git-version-bump'
2
+
3
+ namespace :version do
4
+ namespace :bump do
5
+ desc "bump major version (x.y.z -> x+1.0.0)"
6
+ task :major do
7
+ GVB.tag_version "#{GVB.major_version + 1}.0.0"
8
+
9
+ puts "Version is now #{GVB.version}"
10
+ end
11
+
12
+ desc "bump minor version (x.y.z -> x.y+1.0)"
13
+ task :minor do
14
+ GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version+1}.0"
15
+
16
+ puts "Version is now #{GVB.version}"
17
+ end
18
+
19
+ desc "bump patch version (x.y.z -> x.y.z+1)"
20
+ task :patch do
21
+ GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version+1}"
22
+
23
+ puts "Version is now #{GVB.version}"
24
+ end
25
+
26
+ desc "Print current version"
27
+ task :show do
28
+ puts GVB.version
29
+ end
30
+ end
31
+ end
32
+
33
+ namespace :v do
34
+ namespace :b do
35
+ task :major => "version:bump:major"
36
+ task :maj => "version:bump:major"
37
+
38
+ task :minor => "version:bump:minor"
39
+ task :min => "version:bump:minor"
40
+
41
+ task :patch => "version:bump:patch"
42
+ task :pat => "version:bump:patch"
43
+ task :p => "version:bump:patch"
44
+
45
+ task :show => "version:bump:show"
46
+ task :sh => "version:bump:show"
47
+ task :s => "version:bump:show"
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ module GitVersionBump
2
+ def self.VERSION
3
+ GVB.version
4
+ end
5
+
6
+ def self.MAJOR_VERSION
7
+ GVB.major_version
8
+ end
9
+
10
+ def self.MINOR_VERSION
11
+ GVB.minor_version
12
+ end
13
+
14
+ def self.PATCH_VERSION
15
+ GVB.patch_version
16
+ end
17
+
18
+ def self.INTERNAL_REVISION
19
+ GVB.internal_revision
20
+ end
21
+
22
+ def self.DATE
23
+ GVB.date
24
+ end
25
+
26
+ def self.const_missing(c)
27
+ if self.respond_to?(c) && c =~ /\A[A-Z_]+\z/
28
+ public_send c
29
+ else
30
+ super
31
+ end
32
+ end
33
+ end