versioneer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f1e3978f9d739b3a0e37ab2182cf0f692a8c1cb
4
+ data.tar.gz: 999abeeadab4361199558bfae40daf4db19cebe3
5
+ SHA512:
6
+ metadata.gz: 78b06f745b17f73ea085e2c9f33c2225c085a541fdd1f21e15f03222f0adac8e115a56d05144f67b5842cb1fc872bd8bfb6f0d462e2ac30d5fb87e6acbaa5467
7
+ data.tar.gz: 59161c3239ceb2090c2563488862934adf507a8242d566c07f4ada062b8e8dcd0cc634a489455a95dd567c87128ce26a3813daa9fde012ed1efd30bc218b635d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in versioneer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 BinaryBabel OSS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Versioneer
2
+
3
+ [![Build Status](https://travis-ci.org/binarybabel/gem-versioneer.svg?branch=master)](https://travis-ci.org/binarybabel/gem-versioneer)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/k3i9rbgy2q8xdl78/branch/master?svg=true)](https://ci.appveyor.com/project/babelop/gem-versioneer/branch/master)
5
+
6
+ __Dynamic project versioning (alpha/beta/rc) from commits since last Git Tag.__
7
+
8
+ Versioneer **determines a project's version** from the latest source-control tag, then **adjusts automatically** by adding/bumping prereleases based on changes made since the last tagged release.
9
+
10
+ Integration tested on **UNIX/MacOS and Windows**.
11
+
12
+ ## Overview
13
+
14
+ #### Non-production environments (default settings)
15
+
16
+ * No changes since last VCS Tag (Ex. v0.1.0)
17
+ - **Same as Tag** `0.1.0`
18
+ * Uncommitted changes
19
+ - **Minor Bump + Alpha** `0.2.alpha1`
20
+ * First commit
21
+ - **Minor Bump + Beta** `0.2.beta1`
22
+ * First commit with uncommitted changes
23
+ - **Minor Bump + Alpha2** `0.2.alpha2`
24
+
25
+ #### In production
26
+
27
+ * No changes since last VCS Tag (Ex. v0.1.0)
28
+ - **Same as Tag** `0.1.0`
29
+ * Uncommitted changes
30
+ - **Ignored in Production** `0.1.0`
31
+ * First commit past VCS Tag
32
+ - **Minor Bump + Release Candidate** `0.2.rc1`
33
+ - Optionally, patches can be used instead of "rc" in production:
34
+ - **Minor Bump + Patch** `0.1.1`
35
+
36
+ ## Usage
37
+
38
+ ### Ruby Project (Rails, Rack, etc.)
39
+
40
+ TODO
41
+
42
+ ### Command-Line
43
+
44
+ CLI usage defaults to "production" mode, unless otherwise given by ENV variable.
45
+
46
+ ```
47
+ $ git tag -am 'Release 0.1' v0.1
48
+
49
+ $ versioneer
50
+ 0.1
51
+
52
+ $ git commit --allow-empty -m 'Some changes.'
53
+
54
+ $versioneer
55
+ 0.2.rc1
56
+ ```
57
+
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/binarybabel/gem-versioneer.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/appveyor.yml ADDED
@@ -0,0 +1,17 @@
1
+ branches:
2
+ only:
3
+ - master
4
+
5
+ install:
6
+ - set PATH=C:\Ruby23\bin;%PATH%
7
+ - bundle install
8
+
9
+ build: off
10
+
11
+ before_test:
12
+ - ruby -v
13
+ - gem -v
14
+ - bundle -v
15
+
16
+ test_script:
17
+ - bundle exec rake
data/bin/versioneer ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'versioneer'
5
+ puts Versioneer::Git.new(Dir.getwd, {
6
+ environment: 'production'
7
+ }).to_s
@@ -0,0 +1,101 @@
1
+ module Versioneer
2
+ class Base
3
+ def initialize(file_within_repo, options=nil)
4
+ @file = file_within_repo
5
+ @directory = File.dirname(@file)
6
+ @environment = nil
7
+
8
+ @bump_segment = :minor
9
+ @prereleases = %w(alpha beta rc)
10
+ @release_pattern = /^v?([0-9\.]+$)/
11
+ @starting_release = Gem::Version.new('0.0')
12
+
13
+ if options.is_a? Hash
14
+ options.each do |k, v|
15
+ send("#{k}=", v)
16
+ end
17
+ end
18
+ end
19
+
20
+ attr_accessor :starting_release,
21
+ :bump_segment,
22
+ :prereleases
23
+
24
+ def environment
25
+ @environment || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV'] || 'development'
26
+ end
27
+
28
+ attr_writer :environment
29
+
30
+ def to_s
31
+ version.to_s
32
+ end
33
+
34
+ def version
35
+ prerelease = nil
36
+ c = commits_since_release
37
+
38
+ if environment == 'production'
39
+ if bump_segment == :minor and prereleases[2].nil? and c > 0
40
+ # Use commits as addition to patch level, instead of release candidate.
41
+ return self.class.bump(release.release, :patch, nil, c)
42
+ else
43
+ prerelease = prereleases[2].to_s + c.to_s if c > 0
44
+ end
45
+ elsif filesystem_dirty?
46
+ prerelease = prereleases[0].to_s + (c+1).to_s
47
+ elsif c > 0
48
+ prerelease = prereleases[1].to_s + c.to_s
49
+ end
50
+
51
+ if prerelease
52
+ self.class.bump(release, bump_segment, prerelease)
53
+ else
54
+ release
55
+ end
56
+ end
57
+
58
+ def release
59
+ starting_release
60
+ end
61
+
62
+ attr_reader :release_pattern
63
+
64
+ def release_pattern=(v)
65
+ v = Regexp.new(v) if v.is_a? String
66
+ @release_pattern = v
67
+ end
68
+
69
+ def commits_since_release
70
+ 0
71
+ end
72
+
73
+ def filesystem_dirty?
74
+ true
75
+ end
76
+
77
+ def self.bump(version, bump_segment, prerelease_suffix=nil, bump_count=1)
78
+ length = segment_to_i(bump_segment) + 1 unless bump_segment.nil?
79
+
80
+ if version.prerelease? or bump_segment.nil?
81
+ next_version = (version.release.segments + [prerelease_suffix]).compact.join('.')
82
+ else
83
+ next_version = version
84
+ bump_count.times do
85
+ segments = next_version.release.segments.slice(0, length)
86
+ while segments.size < length + 1 # Version.bump strips last segment
87
+ segments << 0
88
+ end
89
+ next_version = Gem::Version.new(segments.join('.')).bump
90
+ end
91
+ next_version = [next_version.to_s, prerelease_suffix].compact.join('.')
92
+ end
93
+
94
+ next_version
95
+ end
96
+
97
+ def self.segment_to_i(segment)
98
+ [:major, :minor, :patch].index(segment)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module Versioneer
2
+ GEM_VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,67 @@
1
+ require_relative 'helpers'
2
+
3
+ module Versioneer
4
+ class Git < Base
5
+ def initialize(file_within_repo, options=nil)
6
+ super
7
+ unless file_within_repo.is_a? Dir and Dir.join('.git').exist?
8
+ unless H.lines? `git ls-files #{file_within_repo} --error-unmatch #{H.cl_no_stderr}`
9
+ raise InvalidRepoError, 'Not a git repo.'
10
+ end
11
+ end
12
+ end
13
+
14
+ def release
15
+ if (ref = release_ref)
16
+ Gem::Version.new(ref.match(release_pattern)[1])
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def commits_since_release
23
+ offset = 0
24
+ unless (ref = release_ref)
25
+ unless (ref = first_ref)
26
+ return 0
27
+ end
28
+ offset = 1
29
+ end
30
+ H.num_of_lines(`git log #{ref}...HEAD --pretty=oneline #{H.cl_no_stderr}`) + offset
31
+ end
32
+
33
+ def filesystem_dirty?
34
+ H.lines? `git status -s`
35
+ end
36
+
37
+ protected
38
+
39
+ def release_ref
40
+ cmd = 'git describe --abbrev=0 --tags'
41
+ ref = `#{cmd} #{H.cl_no_stderr}`.chomp
42
+ return nil if ref.empty?
43
+ if ref.match(release_pattern)
44
+ ref
45
+ else
46
+ # Iterate through tags in date order for first match.
47
+ `git tag --sort=taggerdate`.split("\n").each do |tag|
48
+ tag.chomp!
49
+ if tag.match(release_pattern)
50
+ return tag
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def first_ref
57
+ cmd = 'git rev-list HEAD | tail -n 1'
58
+ ref = `#{cmd} #{H.cl_no_stderr}`.chomp
59
+ return nil if ref.empty?
60
+ ref
61
+ end
62
+
63
+ private
64
+
65
+ H = Helpers
66
+ end
67
+ end
@@ -0,0 +1,50 @@
1
+ module Versioneer
2
+ class Helpers
3
+ class << self
4
+
5
+ # Generic
6
+
7
+ def lines?(input)
8
+ num_of_lines(input) > 0
9
+ end
10
+
11
+ def num_of_lines(input)
12
+ return 0 unless input.is_a? String and not input.empty?
13
+ input.chomp.split("\n").size
14
+ end
15
+
16
+ # Platform Specific
17
+
18
+ def windows?
19
+ Gem.respond_to? :win_platform? and Gem.send(:win_platform?)
20
+ end
21
+
22
+ def platform
23
+ return :windows if windows?
24
+ :unix
25
+ end
26
+
27
+ def cl_no_stdout
28
+ {
29
+ unix: '>/dev/null',
30
+ windows: '>nul'
31
+ }.fetch(platform)
32
+ end
33
+
34
+ def cl_no_stderr
35
+ {
36
+ unix: '2>/dev/null',
37
+ windows: '2>nul'
38
+ }.fetch(platform)
39
+ end
40
+
41
+ def cl_silence
42
+ {
43
+ unix: '>/dev/null 2>&1',
44
+ windows: '>nul 2>&1'
45
+ }.fetch(platform)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ module Versioneer
2
+ class InvalidRepoError < ArgumentError
3
+
4
+ end
5
+ end
data/lib/versioneer.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'versioneer/gem_version'
2
+ require 'versioneer/invalid_repo_error'
3
+ require 'versioneer/base'
4
+ require 'versioneer/git'
5
+
6
+ module Versioneer
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'versioneer/gem_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'versioneer'
8
+ spec.version = Versioneer::GEM_VERSION
9
+ spec.authors = ['BinaryBabel OSS']
10
+ spec.email = ['oss@binarybabel.net']
11
+ spec.homepage = 'https://github.com/binarybabel/gem-versioneer'
12
+
13
+ spec.summary = 'Dynamic project versioning (alpha/beta/rc) based on commits since last Git tag.'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = ['versioneer']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.13'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'minitest', '~> 5.0'
26
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versioneer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BinaryBabel OSS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - oss@binarybabel.net
58
+ executables:
59
+ - versioneer
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - appveyor.yml
70
+ - bin/versioneer
71
+ - lib/versioneer.rb
72
+ - lib/versioneer/base.rb
73
+ - lib/versioneer/gem_version.rb
74
+ - lib/versioneer/git.rb
75
+ - lib/versioneer/helpers.rb
76
+ - lib/versioneer/invalid_repo_error.rb
77
+ - versioneer.gemspec
78
+ homepage: https://github.com/binarybabel/gem-versioneer
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Dynamic project versioning (alpha/beta/rc) based on commits since last Git
102
+ tag.
103
+ test_files: []