|
3 | 3 | # Increases the version. e.g., from 0.8.5 to 0.8.6.
|
4 | 4 | # If you want to bump the minor or major version numbers, do it manually
|
5 | 5 | # or edit lib/version.rb before running this file.
|
6 |
| -# |
7 |
| -# Optional arguments: |
8 |
| -# no-commit: Don't commit the file changes |
9 |
| -# no-push: Don't push the commits to github. no-commit implies no-push too. |
10 | 6 |
|
11 |
| -VERSION_FILE_PATH = File.expand_path('../../lib/version.rb', __FILE__) |
| 7 | +usage = <<-END |
| 8 | +
|
| 9 | + Arguments: |
| 10 | + <version>: The new version. Must have at least 2 parts. Examples: 0.9.8, 0.10, 0.9.7.3 |
| 11 | + no-commit: Don't commit the changes. |
| 12 | + push: Push the commits to github. If used by itself without the version argument, |
| 13 | + it's assumed that the commit and tags are ready to be pushed. |
| 14 | +
|
| 15 | + Example: |
| 16 | +
|
| 17 | + To update the version in one step, and then push the commits in a second step: |
12 | 18 |
|
13 |
| -puts '', "Updating #{VERSION_FILE_PATH}..." |
| 19 | + ruby script/version_bump.rb 0.9.7.3 |
| 20 | + ruby script/version_bump.rb push |
| 21 | +
|
| 22 | + To do everything in one step: |
| 23 | +
|
| 24 | + ruby script/version_bump.rb 0.9.8 push |
| 25 | +
|
| 26 | + END |
| 27 | + |
| 28 | +VERSION_FILE_PATH = File.expand_path('../../lib/version.rb', __FILE__) |
14 | 29 |
|
15 |
| -contents = '' |
16 |
| -tiny_version_bumped = false |
17 |
| -File.open(VERSION_FILE_PATH) do |f| |
18 |
| - line = f.read |
19 |
| - m = /TINY\s*=\s*([\d]+)/.match(line) |
20 |
| - tiny_version_bumped = true if m |
21 |
| - contents += m ? line.sub(m[0], m[0].sub(m[1], (m[1].to_i + 1).to_s)) : line |
| 30 | +if ARGV.length < 1 |
| 31 | + puts usage |
| 32 | + exit 1 |
22 | 33 | end
|
23 | 34 |
|
24 |
| -unless tiny_version_bumped |
25 |
| - puts "ERROR: couldn't update lib/version.rb. Is it missing the TINY constant?" |
| 35 | +new_version = ARGV[0].split('.') |
| 36 | +if new_version.length < 2 and !ARGV.include?('push') |
| 37 | + puts "First argument must be a version number with at least 2 parts. Examples: 0.9.8, 0.10, 0.9.7.3" |
26 | 38 | exit 1
|
27 | 39 | end
|
28 | 40 |
|
29 |
| -puts "Saving..." |
| 41 | +update_version_file = new_version.length >= 2 |
| 42 | + |
| 43 | +if update_version_file |
| 44 | + puts '', "New Version: #{new_version.join('.')}", "Updating #{VERSION_FILE_PATH}..." |
| 45 | + |
| 46 | + contents = '' |
| 47 | + tiny_version_bumped = false |
| 48 | + File.open(VERSION_FILE_PATH) do |f| |
| 49 | + contents = f.read |
| 50 | + ['MAJOR', 'MINOR', 'TINY', 'PRE'].each_with_index do |name, i| |
| 51 | + r = Regexp.new(name + '\s*=\s*(nil|[\d]+)') |
| 52 | + m = r.match(contents) |
| 53 | + v = new_version[i].to_i > 0 ? new_version[i] : (name == 'PRE' ? 'nil' : '0') |
| 54 | + contents.sub!(m[0], m[0].sub(m[1], v)) if m |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + puts "Saving..." |
30 | 59 |
|
31 |
| -File.open(VERSION_FILE_PATH, 'w+') do |f| |
32 |
| - f.write(contents) |
| 60 | + File.open(VERSION_FILE_PATH, 'w+') do |f| |
| 61 | + f.write(contents) |
| 62 | + end |
33 | 63 | end
|
34 | 64 |
|
35 | 65 | require File.expand_path('../../lib/version', __FILE__)
|
36 | 66 |
|
37 | 67 | version = Discourse::VERSION::STRING
|
38 | 68 | puts "New version is: #{version}"
|
39 | 69 |
|
40 |
| -puts ARGV |
41 |
| - |
42 |
| -unless ARGV.include?('no-commit') |
43 |
| - puts "Commiting..." |
| 70 | +unless ARGV.include?('no-commit') or !update_version_file |
| 71 | + puts "Committing..." |
44 | 72 |
|
45 | 73 | `git add lib/version.rb`
|
46 | 74 | `git commit -m "Version bump to v#{version}"`
|
47 | 75 | sha = `git rev-parse HEAD`.strip
|
| 76 | + `git tag -d latest-release` |
| 77 | + `git push origin :latest-release` |
48 | 78 | `git tag -a v#{version} -m "version #{version}" #{sha}`
|
| 79 | + `git tag -a latest-release -m "latest release" #{sha}` |
| 80 | +end |
49 | 81 |
|
50 |
| - unless ARGV.include?('no-push') |
51 |
| - puts "Pushing..." |
52 |
| - `git push origin master` |
53 |
| - `git push origin v#{version}` |
54 |
| - end |
| 82 | +if ARGV.include?('push') |
| 83 | + puts "Pushing..." |
| 84 | + |
| 85 | + `git push origin master` |
| 86 | + `git push origin v#{version}` |
| 87 | + `git push origin latest-release` |
55 | 88 | end
|
56 | 89 |
|
57 | 90 | puts "Done",''
|
0 commit comments