autoversion 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +74 -18
- data/lib/autoversion/dsl.rb +47 -2
- data/lib/autoversion/version.rb +1 -1
- data/spec/cli_spec.rb +21 -17
- data/spec/fixtures/bare_repo.tar +0 -0
- data/spec/fixtures/versionfiles.rb +34 -0
- data/spec/gitter_spec.rb +5 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9840e84b0c9f9fc1b82e69b63d0fa2b48cab6800
|
4
|
+
data.tar.gz: e5409566fc64257e84ee79083192a91e2b2a3592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225a4c4e02dfdf088c2a771c3f5a71e9b81843d4fbdb55476d6eee938076c2984019118a706febb7c33b89d2cae4fd0f1747a4dc2466b4dff8e789a5e643c98c
|
7
|
+
data.tar.gz: 03bbc50a7bf7a42c3a67f20c55db1cde4ffdf3d52feec93a7e6360a0bd0e0edc0bba4e3399b30350920de75257e62ebc73119ce6109597cea573bdbd9ccd4b62
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,22 @@
|
|
1
|
+
### Status
|
2
|
+
[](https://travis-ci.org/jpettersson/autoversion)
|
3
|
+
|
1
4
|
Autoversion
|
2
5
|
===========
|
3
6
|
|
4
|
-
Autoversion is a command line tool that can automate [semantic versioning](http://semver.org)
|
5
|
-
integrates nicely with git to give you automatic & atomic commits of version increments.
|
7
|
+
Autoversion is a command line tool that can automate [semantic versioning](http://semver.org) during development. It
|
8
|
+
integrates nicely with git to give you automatic & atomic commits of version increments. Don't trust humans (not even yourself) to commit and tag proper versions, let autoversion do it for you.
|
6
9
|
|
7
|
-
Autoversion is
|
8
|
-
And yes, Autoversion uses Autoversion for versioning ;)
|
10
|
+
Autoversion is great for library development where proper version management is important. Also, Autoversion uses Autoversion for versioning ;)
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
```
|
15
|
+
gem install autoversion
|
16
|
+
```
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
12
20
|
|
13
21
|
**Read current version**
|
14
22
|
```Bash
|
@@ -20,31 +28,30 @@ $ autoversion
|
|
20
28
|
$ autoversion major
|
21
29
|
$ autoversion minor
|
22
30
|
$ autoversion patch
|
23
|
-
$ autoversion build 'named-version'
|
24
31
|
```
|
25
32
|
|
26
33
|
The Versionfile
|
27
34
|
--------------------
|
28
35
|
|
29
|
-
The Versionfile
|
30
|
-
|
31
|
-
**Example**
|
36
|
+
The project you want to version needs to have a file called 'Versionfile'. Autoversion will evaluate this file as a ruby script. Autoversion provides a small DSL to allow you to read and write versions to your files. Below is an example of the DSL usage:
|
32
37
|
|
33
38
|
```Ruby
|
34
39
|
|
35
|
-
# This block should return a valid Semantic object.
|
40
|
+
# This block should return a valid Semantic object.
|
41
|
+
# Example: Read a file and parse a verson from it.
|
36
42
|
read_version do
|
37
|
-
#
|
43
|
+
# Should return a string representation of a semantic version
|
38
44
|
end
|
39
45
|
|
40
|
-
# This block
|
41
|
-
|
42
|
-
|
46
|
+
# This block takes the current and next version (strings).
|
47
|
+
# Example: Rewriting a version file.
|
48
|
+
write_version do |currentVersion, nextVersion|
|
49
|
+
# Write the new version to a file
|
43
50
|
end
|
44
51
|
|
45
52
|
after :version do
|
46
53
|
# Run some command after any versioning action
|
47
|
-
# Example:
|
54
|
+
# Example: Run a package script, trigger CI, etc.
|
48
55
|
end
|
49
56
|
|
50
57
|
after :patch do
|
@@ -57,7 +64,6 @@ end
|
|
57
64
|
|
58
65
|
after :major do
|
59
66
|
# Run some command after release
|
60
|
-
# Example: Copy lib/ files from Exo.js to exojs-gem
|
61
67
|
end
|
62
68
|
|
63
69
|
```
|
@@ -117,9 +123,59 @@ after :version do |currentVersion|
|
|
117
123
|
end
|
118
124
|
```
|
119
125
|
|
120
|
-
**
|
126
|
+
**A bower module**
|
127
|
+
|
128
|
+
```Ruby
|
129
|
+
require 'json'
|
130
|
+
|
131
|
+
# Automatically create an atomic commit of the version file update
|
132
|
+
# and create a new tag.
|
133
|
+
automate_git :actions => [:commit, :tag]
|
134
|
+
|
135
|
+
file = './bower.json'
|
136
|
+
|
137
|
+
read_version do
|
138
|
+
doc = JSON.load File.read file
|
139
|
+
doc['version']
|
140
|
+
end
|
141
|
+
|
142
|
+
write_version do |currentVersion, nextVersion|
|
143
|
+
doc = JSON.load File.read file
|
144
|
+
doc['version'] = nextVersion.to_s
|
145
|
+
File.open(file, 'w') {|f| f.write JSON.pretty_generate(doc) }
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
**Advanced usage: Update several files using a pattern matcher**
|
150
|
+
|
151
|
+
You can also read & update versions using a pattern matcher. The following Versionfile is from a ruby gem that has several plugins (also packaged as gems) contained in the same git repo. The VERSION_PATTERN is used for both reading and writing the version. Note that the write_version method updates several files using a glob pattern.
|
121
152
|
|
122
153
|
```Ruby
|
154
|
+
|
155
|
+
# The matched files look like this:
|
156
|
+
|
157
|
+
# module YourProject
|
158
|
+
# VERSION = "0.0.2"
|
159
|
+
# end
|
160
|
+
|
161
|
+
VERSION_PATTERN = /^\s*VERSION = \"(.+)\"$/
|
162
|
+
|
163
|
+
matcher = proc do |line|
|
164
|
+
if m = VERSION_PATTERN.match(line)
|
165
|
+
m[1]
|
166
|
+
else
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
read_version do
|
172
|
+
parse_file "lib/your-project/version.rb", matcher
|
173
|
+
end
|
174
|
+
|
175
|
+
write_version do |oldVersion, newVersion|
|
176
|
+
update_files Dir.glob("**/version.rb"), matcher, oldVersion, newVersion
|
177
|
+
end
|
178
|
+
|
123
179
|
```
|
124
180
|
|
125
181
|
|
data/lib/autoversion/dsl.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Autoversion
|
2
2
|
class DSL
|
3
|
-
|
4
3
|
class MissingReadBlock < Exception
|
5
4
|
end
|
6
5
|
|
@@ -25,6 +24,52 @@ module Autoversion
|
|
25
24
|
}
|
26
25
|
end
|
27
26
|
|
27
|
+
# Parse the specified file with the provided matcher.
|
28
|
+
#
|
29
|
+
# The first returned match will be used as the version.
|
30
|
+
def parse_file path, matcher
|
31
|
+
File.open(path) do |f|
|
32
|
+
f.each do |line|
|
33
|
+
if m = matcher.call(line)
|
34
|
+
return m
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
raise "#{path}: found no matching lines."
|
40
|
+
end
|
41
|
+
|
42
|
+
# Update a file naively matching the specified matcher and replace any
|
43
|
+
# matching lines with the new version.
|
44
|
+
def update_file path, matcher, currentVersion, nextVersion
|
45
|
+
temp_path = "#{path}.autoversion"
|
46
|
+
|
47
|
+
begin
|
48
|
+
File.open(path) do |source|
|
49
|
+
File.open(temp_path, 'w') do |target|
|
50
|
+
source.each do |line|
|
51
|
+
if matcher.call(line)
|
52
|
+
target.write line.gsub currentVersion.to_s, nextVersion.to_s
|
53
|
+
else
|
54
|
+
target.write line
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
File.rename temp_path, path
|
61
|
+
ensure
|
62
|
+
File.unlink temp_path if File.file? temp_path
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Convenience function for update_file to apply to multiple files.
|
67
|
+
def update_files paths, matcher, currentVersion, nextVersion
|
68
|
+
paths.each do |path|
|
69
|
+
update_file path, matcher, currentVersion, nextVersion
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
28
73
|
def validate!
|
29
74
|
# A read_version block is required
|
30
75
|
raise MissingReadBlock unless @read_blk
|
@@ -85,4 +130,4 @@ module Autoversion
|
|
85
130
|
end
|
86
131
|
end
|
87
132
|
end
|
88
|
-
end
|
133
|
+
end
|
data/lib/autoversion/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -1,20 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'git'
|
3
|
+
require_relative 'fixtures/versionfiles'
|
3
4
|
|
4
5
|
describe Autoversion::CLI do
|
5
6
|
|
6
|
-
BASE_VERSIONFILE = <<-eos
|
7
|
-
read_version do
|
8
|
-
File.read File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt')
|
9
|
-
end
|
10
|
-
|
11
|
-
write_version do |currentVersion, nextVersion|
|
12
|
-
File.open(File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt'), 'w') do |file|
|
13
|
-
file.write currentVersion.to_s
|
14
|
-
end
|
15
|
-
end
|
16
|
-
eos
|
17
|
-
|
18
7
|
# Borrowing capture_io from minitest until I have
|
19
8
|
# time to move over to minitest fully.
|
20
9
|
def capture_io
|
@@ -57,14 +46,14 @@ describe Autoversion::CLI do
|
|
57
46
|
end
|
58
47
|
|
59
48
|
it "should be able to read a version" do
|
60
|
-
::Autoversion::CLI.version_file_contents = BASE_VERSIONFILE
|
49
|
+
::Autoversion::CLI.version_file_contents = Versionfiles::BASE_VERSIONFILE
|
61
50
|
|
62
51
|
out = capture_io{ Autoversion::CLI.start %w{} }.join ''
|
63
52
|
out.should == "\e[36m0.0.1\e[0m\n"
|
64
53
|
end
|
65
54
|
|
66
55
|
it "should be able to write versions" do
|
67
|
-
::Autoversion::CLI.version_file_contents = BASE_VERSIONFILE
|
56
|
+
::Autoversion::CLI.version_file_contents = Versionfiles::BASE_VERSIONFILE
|
68
57
|
|
69
58
|
out = capture_io{ Autoversion::CLI.start %w{patch -f} }.join ''
|
70
59
|
out.should == "\e[32mVersion changed to 0.0.2\e[0m\n"
|
@@ -76,22 +65,37 @@ describe Autoversion::CLI do
|
|
76
65
|
out.should == "\e[32mVersion changed to 1.0.0\e[0m\n"
|
77
66
|
end
|
78
67
|
|
68
|
+
it "should be able to read/write versions using a pattern matcher" do
|
69
|
+
::Autoversion::CLI.version_file_contents = Versionfiles::PATTERN_VERSIONFILE
|
70
|
+
out = capture_io{ Autoversion::CLI.start %w{patch -f} }.join ''
|
71
|
+
out.should == "\e[32mVersion changed to 0.0.2\e[0m\n"
|
72
|
+
|
73
|
+
plugin_file = `cd #{@path} && cat lib/your-project/plugins/your-plugin/version.rb`
|
74
|
+
ref_file = <<-eof
|
75
|
+
module YourProject
|
76
|
+
VERSION = "0.0.2"
|
77
|
+
end
|
78
|
+
eof
|
79
|
+
|
80
|
+
plugin_file.should == ref_file.chop
|
81
|
+
end
|
82
|
+
|
79
83
|
it "should be able to write, commit and tag patch" do
|
80
|
-
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
|
84
|
+
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + Versionfiles::BASE_VERSIONFILE
|
81
85
|
|
82
86
|
out = capture_io{ Autoversion::CLI.start %w{patch -f} }.join ''
|
83
87
|
out.should == "\e[32mVersion changed to 0.0.2\e[0m\n"
|
84
88
|
end
|
85
89
|
|
86
90
|
it "should be able to write, commit and tag minor" do
|
87
|
-
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
|
91
|
+
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + Versionfiles::BASE_VERSIONFILE
|
88
92
|
|
89
93
|
out = capture_io{ Autoversion::CLI.start %w{minor -f} }.join ''
|
90
94
|
out.should == "\e[32mVersion changed to 0.1.0\e[0m\n"
|
91
95
|
end
|
92
96
|
|
93
97
|
it "should be able to write, commit and tag major" do
|
94
|
-
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + BASE_VERSIONFILE
|
98
|
+
::Autoversion::CLI.version_file_contents = "automate_git\n\n" + Versionfiles::BASE_VERSIONFILE
|
95
99
|
|
96
100
|
out = capture_io{ Autoversion::CLI.start %w{major -f} }.join ''
|
97
101
|
out.should == "\e[32mVersion changed to 1.0.0\e[0m\n"
|
data/spec/fixtures/bare_repo.tar
CHANGED
Binary file
|
@@ -1,4 +1,37 @@
|
|
1
1
|
module Versionfiles
|
2
|
+
|
3
|
+
BASE_VERSIONFILE = <<-eos
|
4
|
+
read_version do
|
5
|
+
File.read File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt')
|
6
|
+
end
|
7
|
+
|
8
|
+
write_version do |currentVersion, nextVersion|
|
9
|
+
File.open(File.join(File.dirname(__FILE__), 'spec', 'tmp', 'cli', 'version.txt'), 'w') do |file|
|
10
|
+
file.write currentVersion.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
eos
|
14
|
+
|
15
|
+
PATTERN_VERSIONFILE = <<-eof
|
16
|
+
VERSION_PATTERN = /^\s*VERSION = \"(.+)\"$/
|
17
|
+
|
18
|
+
matcher = proc do |line|
|
19
|
+
if m = VERSION_PATTERN.match(line)
|
20
|
+
m[1]
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
read_version do
|
27
|
+
parse_file "spec/tmp/cli/lib/your-project/version.rb", matcher
|
28
|
+
end
|
29
|
+
|
30
|
+
write_version do |oldVersion, newVersion|
|
31
|
+
update_files Dir.glob("spec/tmp/cli/**/version.rb"), matcher, oldVersion, newVersion
|
32
|
+
end
|
33
|
+
eof
|
34
|
+
|
2
35
|
VALID_BASIC = <<-eof
|
3
36
|
read_version do
|
4
37
|
'1.2.3'
|
@@ -12,4 +45,5 @@ module Versionfiles
|
|
12
45
|
INVALID = <<-eof
|
13
46
|
|
14
47
|
eof
|
48
|
+
|
15
49
|
end
|
data/spec/gitter_spec.rb
CHANGED
@@ -13,6 +13,11 @@ describe Autoversion::Gitter do
|
|
13
13
|
system("mkdir #{@gitter_path}")
|
14
14
|
system("tar -xf spec/fixtures/bare_repo.tar --strip 1 -C #{@gitter_path}")
|
15
15
|
|
16
|
+
# Fix to make specs run on travis-ci which has no
|
17
|
+
# default git user config.
|
18
|
+
# system("cd #{@gitter_path} && git config user.email 'you@example.com'")
|
19
|
+
# system("cd #{@gitter_path} && git config user.name 'Your Name'")
|
20
|
+
|
16
21
|
system("echo 'test' > #{@gitter_path}/test.txt")
|
17
22
|
system("cd #{@gitter_path} && git add .")
|
18
23
|
system("cd #{@gitter_path} && git commit -m 'test'")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Pettersson
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- .rspec
|
78
|
+
- .travis.yml
|
78
79
|
- Gemfile
|
79
80
|
- Gemfile.lock
|
80
81
|
- LICENSE
|