|
6 | 6 |
|
7 | 7 | directory "pkg" |
8 | 8 |
|
| 9 | +# This "npm-ifies" the current version number |
| 10 | +# With npm, versions such as "5.0.0.rc1" or "5.0.0.beta1.1" are not compliant with its |
| 11 | +# versioning system, so they must be transformed to "5.0.0-rc1" and "5.0.0-beta1-1" respectively. |
| 12 | + |
| 13 | +# "5.0.1" --> "5.0.1" |
| 14 | +# "5.0.1.1" --> "5.0.1-1" * |
| 15 | +# "5.0.0.rc1" --> "5.0.0-rc1" |
| 16 | +# |
| 17 | +# * This makes it a prerelease. That's bad, but we haven't come up with |
| 18 | +# a better solution at the moment. |
| 19 | +npm_version = version.gsub(/\./).with_index { |s, i| i >= 2 ? "-" : s } |
| 20 | + |
9 | 21 | (FRAMEWORKS + ['rails']).each do |framework| |
10 | 22 | namespace framework do |
11 | 23 | gem = "pkg/#{framework}-#{version}.gem" |
|
43 | 55 | raise "Could not insert PRE in #{file}" unless $1 |
44 | 56 |
|
45 | 57 | File.open(file, 'w') { |f| f.write ruby } |
| 58 | + |
| 59 | + require "json" |
| 60 | + if File.exist?("#{framework}/package.json") && JSON.parse(File.read("#{framework}/package.json"))["version"] != npm_version |
| 61 | + Dir.chdir("#{framework}") do |
| 62 | + if sh "which npm" |
| 63 | + sh "npm version #{npm_version} --no-git-tag-version" |
| 64 | + else |
| 65 | + raise "You must have npm installed to release Rails." |
| 66 | + end |
| 67 | + end |
| 68 | + end |
46 | 69 | end |
47 | 70 |
|
48 | 71 | task gem => %w(update_versions pkg) do |
|
61 | 84 | task :push => :build do |
62 | 85 | sh "gem push #{gem}" |
63 | 86 |
|
64 | | - # When running the release task we usually run build first to check that the gem works properly. |
65 | | - # NPM will refuse to publish or rebuild the gem if the version is changed when the Rails gem |
66 | | - # versions are changed. This then causes the gem push to fail. Because of this we need to update |
67 | | - # the version and publish at the same time. |
68 | 87 | if File.exist?("#{framework}/package.json") |
69 | 88 | Dir.chdir("#{framework}") do |
70 | | - # This "npm-ifies" the current version |
71 | | - # With npm, versions such as "5.0.0.rc1" or "5.0.0.beta1.1" are not compliant with its |
72 | | - # versioning system, so they must be transformed to "5.0.0-rc1" and "5.0.0-beta1-1" respectively. |
73 | | - |
74 | | - # In essence, the code below runs through all "."s that appear in the version, |
75 | | - # and checks to see if their index in the version string is greater than or equal to 2, |
76 | | - # and if so, it will change the "." to a "-". |
77 | | - |
78 | | - # Sample version transformations: |
79 | | - # irb(main):001:0> version = "5.0.1.1" |
80 | | - # => "5.0.1.1" |
81 | | - # irb(main):002:0> version.gsub(/\./).with_index { |s, i| i >= 2 ? '-' : s } |
82 | | - # => "5.0.1-1" |
83 | | - # irb(main):003:0> version = "5.0.0.rc1" |
84 | | - # => "5.0.0.rc1" |
85 | | - # irb(main):004:0> version.gsub(/\./).with_index { |s, i| i >= 2 ? '-' : s } |
86 | | - # => "5.0.0-rc1" |
87 | | - version = version.gsub(/\./).with_index { |s, i| i >= 2 ? '-' : s } |
88 | | - |
89 | | - # Check if npm is installed, and raise an error if not |
90 | | - if sh 'which npm' |
91 | | - sh "npm version #{version} --no-git-tag-version" |
92 | | - sh "npm publish" |
93 | | - else |
94 | | - raise 'You must have npm installed to release Rails.' |
95 | | - end |
| 89 | + npm_tag = version =~ /[a-z]/ ? "pre" : "latest" |
| 90 | + sh "npm publish --tag #{npm_tag}" |
96 | 91 | end |
97 | 92 | end |
98 | 93 | end |
|
104 | 99 | (FRAMEWORKS + ['guides']).each do |fw| |
105 | 100 | require 'date' |
106 | 101 | fname = File.join fw, 'CHANGELOG.md' |
| 102 | + current_contents = File.read(fname) |
107 | 103 |
|
108 | | - header = "## Rails #{version} (#{Date.today.strftime('%B %d, %Y')}) ##\n\n* No changes.\n\n\n" |
109 | | - contents = header + File.read(fname) |
| 104 | + header = "## Rails #{version} (#{Date.today.strftime('%B %d, %Y')}) ##\n\n" |
| 105 | + header << "* No changes.\n\n\n" if current_contents =~ /\A##/ |
| 106 | + contents = header + current_contents |
110 | 107 | File.open(fname, 'wb') { |f| f.write contents } |
111 | 108 | end |
112 | 109 | end |
|
143 | 140 | task :push => FRAMEWORKS.map { |f| "#{f}:push" } + ['rails:push'] |
144 | 141 |
|
145 | 142 | task :ensure_clean_state do |
146 | | - unless `git status -s | grep -v 'RAILS_VERSION\\|CHANGELOG\\|Gemfile.lock'`.strip.empty? |
| 143 | + unless `git status -s | grep -v 'RAILS_VERSION\\|CHANGELOG\\|Gemfile.lock\\|package.json\\|version.rb'`.strip.empty? |
147 | 144 | abort "[ABORTING] `git status` reports a dirty tree. Make sure all changes are committed" |
148 | 145 | end |
149 | 146 |
|
|
158 | 155 | end |
159 | 156 |
|
160 | 157 | task :commit do |
161 | | - File.open('pkg/commit_message.txt', 'w') do |f| |
162 | | - f.puts "# Preparing for #{version} release\n" |
163 | | - f.puts |
164 | | - f.puts "# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT" |
165 | | - end |
| 158 | + unless `git status -s`.strip.empty? |
| 159 | + File.open('pkg/commit_message.txt', 'w') do |f| |
| 160 | + f.puts "# Preparing for #{version} release\n" |
| 161 | + f.puts |
| 162 | + f.puts "# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT" |
| 163 | + end |
166 | 164 |
|
167 | | - sh "git add . && git commit --verbose --template=pkg/commit_message.txt" |
168 | | - rm_f "pkg/commit_message.txt" |
| 165 | + sh "git add . && git commit --verbose --template=pkg/commit_message.txt" |
| 166 | + rm_f "pkg/commit_message.txt" |
| 167 | + end |
169 | 168 | end |
170 | 169 |
|
171 | 170 | task :tag do |
172 | 171 | sh "git tag -s -m '#{tag} release' #{tag}" |
173 | 172 | sh "git push --tags" |
174 | 173 | end |
175 | 174 |
|
176 | | - task :prep_release => %w(ensure_clean_state build) |
| 175 | + task :prep_release => %w(ensure_clean_state build bundle commit) |
177 | 176 |
|
178 | | - task :release => %w(ensure_clean_state build bundle commit tag push) |
| 177 | + task :release => %w(prep_release tag push) |
179 | 178 | end |
0 commit comments