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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e19cd24caedde612005e57c536d6d23a3cf27c4
4
- data.tar.gz: 4abca7955e686be2d91b0946f33af46b050880aa
3
+ metadata.gz: 9840e84b0c9f9fc1b82e69b63d0fa2b48cab6800
4
+ data.tar.gz: e5409566fc64257e84ee79083192a91e2b2a3592
5
5
  SHA512:
6
- metadata.gz: 5af8dcd3a141bcf64ebe09e715771b1b0a860e2d2f87f53193c41585efd28b69f7995c9d68ee46bf2eb9e96a1d298a5edad3515a2aa3f48d92807fe0c87eae5c
7
- data.tar.gz: 762b5bc91b6f378dabbc364e58737e7a434b2ad6113b859f7ae003114266b1a939be479ca7d6308c621830269522734a724f72bc88680e8a5cb2eed1df35edc2
6
+ metadata.gz: 225a4c4e02dfdf088c2a771c3f5a71e9b81843d4fbdb55476d6eee938076c2984019118a706febb7c33b89d2cae4fd0f1747a4dc2466b4dff8e789a5e643c98c
7
+ data.tar.gz: 03bbc50a7bf7a42c3a67f20c55db1cde4ffdf3d52feec93a7e6360a0bd0e0edc0bba4e3399b30350920de75257e62ebc73119ce6109597cea573bdbd9ccd4b62
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+ script: bundle exec rspec spec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- autoversion (0.3.2)
4
+ autoversion (0.4.0)
5
5
  git (= 1.2.5)
6
6
  semantic (= 1.1.0)
7
7
  thor (= 0.17.0)
data/README.md CHANGED
@@ -1,14 +1,22 @@
1
+ ### Status
2
+ [![Build Status](https://travis-ci.org/jpettersson/autoversion.png)](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) in your application. It
5
- integrates nicely with git to give you automatic & atomic commits of version increments. It also supports hooks that can be run before and after a new version has been comitted.
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 not finished, but it's used enough to be public. Consider it an experiment.<br />
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
- Basics
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 is a ruby script which is used by Autoversion to read and write version.
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. Typically it will read a file and parse it.
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
- # Return a valid Semantic object
43
+ # Should return a string representation of a semantic version
38
44
  end
39
45
 
40
- # This block should take a Semantic object and persist it. Usually this means rewriting some version file.
41
- write_version do |semver|
42
- # Write a Semantic object
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: Export a .crx file, copy & name it for Blackberry
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
- **An npm module**
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Autoversion
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
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"
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.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