|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -# Order dependent. E.g. Action Mailbox depends on Active Record so it should be after. |
4 |
| -FRAMEWORKS = %w( |
5 |
| - activesupport |
6 |
| - activemodel |
7 |
| - activerecord |
8 |
| - actionview |
9 |
| - actionpack |
10 |
| - activejob |
11 |
| - actionmailer |
12 |
| - actioncable |
13 |
| - activestorage |
14 |
| - actionmailbox |
15 |
| - actiontext |
16 |
| - railties |
17 |
| -) |
18 |
| -FRAMEWORK_NAMES = Hash.new { |h, k| k.split(/(?<=active|action)/).map(&:capitalize).join(" ") } |
| 3 | +require "releaser" |
19 | 4 |
|
20 | 5 | root = File.expand_path("..", __dir__)
|
21 | 6 | version = File.read("#{root}/RAILS_VERSION").strip
|
22 |
| -tag = "v#{version}" |
23 |
| - |
24 |
| -directory "pkg" |
25 |
| - |
26 |
| -major, minor, tiny, pre = version.split(".", 4) |
27 |
| - |
28 |
| -# This "npm-ifies" the current version number |
29 |
| -# With npm, versions such as "5.0.0.rc1" or "5.0.0.beta1.1" are not compliant with its |
30 |
| -# versioning system, so they must be transformed to "5.0.0-rc1" and "5.0.0-beta1-1" respectively. |
31 |
| -# "5.0.0" --> "5.0.0" |
32 |
| -# "5.0.1" --> "5.0.100" |
33 |
| -# "5.0.0.1" --> "5.0.1" |
34 |
| -# "5.0.1.1" --> "5.0.101" |
35 |
| -# "5.0.0.rc1" --> "5.0.0-rc1" |
36 |
| -if pre |
37 |
| - pre_release = pre.match?(/rc|beta|alpha/) ? pre : nil |
38 |
| - npm_pre = pre.to_i |
39 |
| -else |
40 |
| - npm_pre = 0 |
41 |
| - pre_release = nil |
42 |
| -end |
43 |
| - |
44 |
| -npm_version = "#{major}.#{minor}.#{(tiny.to_i * 100) + npm_pre}#{pre_release ? "-#{pre_release}" : ""}" |
45 |
| -pre = pre ? pre.inspect : "nil" |
46 |
| - |
47 |
| -(FRAMEWORKS + ["rails"]).each do |framework| |
48 |
| - namespace framework do |
49 |
| - gem = "pkg/#{framework}-#{version}.gem" |
50 |
| - gemspec = "#{framework}.gemspec" |
51 |
| - |
52 |
| - task :clean do |
53 |
| - rm_f gem |
54 |
| - end |
55 |
| - |
56 |
| - task :update_versions do |
57 |
| - glob = root.dup |
58 |
| - if framework == "rails" |
59 |
| - glob << "/version.rb" |
60 |
| - else |
61 |
| - glob << "/#{framework}/lib/*" |
62 |
| - glob << "/gem_version.rb" |
63 |
| - end |
64 |
| - |
65 |
| - file = Dir[glob].first |
66 |
| - ruby = File.read(file) |
67 |
| - |
68 |
| - ruby.gsub!(/^(\s*)MAJOR(\s*)= .*?$/, "\\1MAJOR = #{major}") |
69 |
| - raise "Could not insert MAJOR in #{file}" unless $1 |
70 |
| - |
71 |
| - ruby.gsub!(/^(\s*)MINOR(\s*)= .*?$/, "\\1MINOR = #{minor}") |
72 |
| - raise "Could not insert MINOR in #{file}" unless $1 |
73 |
| - |
74 |
| - ruby.gsub!(/^(\s*)TINY(\s*)= .*?$/, "\\1TINY = #{tiny}") |
75 |
| - raise "Could not insert TINY in #{file}" unless $1 |
76 |
| - |
77 |
| - ruby.gsub!(/^(\s*)PRE(\s*)= .*?$/, "\\1PRE = #{pre}") |
78 |
| - raise "Could not insert PRE in #{file}" unless $1 |
79 |
| - |
80 |
| - File.open(file, "w") { |f| f.write ruby } |
81 |
| - |
82 |
| - require "json" |
83 |
| - if File.exist?("#{framework}/package.json") && JSON.parse(File.read("#{framework}/package.json"))["version"] != npm_version |
84 |
| - Dir.chdir("#{framework}") do |
85 |
| - if sh "which npm" |
86 |
| - sh "npm version #{npm_version} --no-git-tag-version" |
87 |
| - else |
88 |
| - raise "You must have npm installed to release Rails." |
89 |
| - end |
90 |
| - end |
91 |
| - end |
92 |
| - end |
93 |
| - |
94 |
| - task gem => %w(update_versions pkg) do |
95 |
| - cmd = "" |
96 |
| - cmd += "cd #{framework} && " unless framework == "rails" |
97 |
| - cmd += "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/" |
98 |
| - sh cmd |
99 |
| - end |
100 |
| - |
101 |
| - task build: [:clean, gem] |
102 |
| - task install: :build do |
103 |
| - sh "gem install --pre #{gem}" |
104 |
| - end |
105 |
| - |
106 |
| - task push: :build do |
107 |
| - otp = "" |
108 |
| - begin |
109 |
| - otp = " --otp " + `ykman oath accounts code -s rubygems.org`.chomp |
110 |
| - rescue |
111 |
| - # User doesn't have ykman |
112 |
| - end |
113 |
| - |
114 |
| - sh "gem push #{gem}#{otp}" |
115 |
| - |
116 |
| - if File.exist?("#{framework}/package.json") |
117 |
| - Dir.chdir("#{framework}") do |
118 |
| - npm_otp = "" |
119 |
| - begin |
120 |
| - npm_otp = " --otp " + `ykman oath accounts code -s npmjs.com`.chomp |
121 |
| - rescue |
122 |
| - # User doesn't have ykman |
123 |
| - end |
124 |
| - |
125 |
| - npm_tag = "" |
126 |
| - if /[a-z]/.match?(version) |
127 |
| - npm_tag = " --tag pre" |
128 |
| - else |
129 |
| - npm_tag = " --tag latest" |
130 |
| - end |
131 |
| - |
132 |
| - sh "npm publish#{npm_tag}#{npm_otp}" |
133 |
| - end |
134 |
| - end |
135 |
| - end |
136 |
| - end |
137 |
| -end |
138 |
| - |
139 |
| -namespace :changelog do |
140 |
| - task :header do |
141 |
| - (FRAMEWORKS + ["guides"]).each do |fw| |
142 |
| - require "date" |
143 |
| - fname = File.join fw, "CHANGELOG.md" |
144 |
| - current_contents = File.read(fname) |
145 |
| - |
146 |
| - header = "## Rails #{version} (#{Date.today.strftime('%B %d, %Y')}) ##\n\n" |
147 |
| - header += "* No changes.\n\n\n" if current_contents.start_with?("##") |
148 |
| - contents = header + current_contents |
149 |
| - File.write(fname, contents) |
150 |
| - end |
151 |
| - end |
152 |
| - |
153 |
| - task :release_summary, [:base_release, :release] do |_, args| |
154 |
| - release_regexp = args[:base_release] ? Regexp.escape(args[:base_release]) : /\d+\.\d+\.\d+/ |
155 |
| - |
156 |
| - puts args[:release] |
157 |
| - |
158 |
| - FRAMEWORKS.each do |fw| |
159 |
| - puts "## #{FRAMEWORK_NAMES[fw]}" |
160 |
| - fname = File.join fw, "CHANGELOG.md" |
161 |
| - contents = File.readlines fname |
162 |
| - contents.shift |
163 |
| - changes = [] |
164 |
| - until contents.first =~ /^## Rails #{release_regexp}.*$/ || |
165 |
| - contents.first =~ /^Please check.*for previous changes\.$/ || |
166 |
| - contents.empty? |
167 |
| - changes << contents.shift |
168 |
| - end |
169 |
| - |
170 |
| - puts changes.join |
171 |
| - puts |
172 |
| - end |
173 |
| - end |
174 |
| -end |
175 |
| - |
176 |
| -namespace :all do |
177 |
| - task build: FRAMEWORKS.map { |f| "#{f}:build" } + ["rails:build"] |
178 |
| - task update_versions: FRAMEWORKS.map { |f| "#{f}:update_versions" } + ["rails:update_versions"] |
179 |
| - task install: FRAMEWORKS.map { |f| "#{f}:install" } + ["rails:install"] |
180 |
| - task push: FRAMEWORKS.map { |f| "#{f}:push" } + ["rails:push"] |
181 |
| - |
182 |
| - task :ensure_clean_state do |
183 |
| - unless `git status -s | grep -v 'RAILS_VERSION\\|CHANGELOG\\|Gemfile.lock\\|package.json\\|version.rb\\|tasks/release.rb'`.strip.empty? |
184 |
| - abort "[ABORTING] `git status` reports a dirty tree. Make sure all changes are committed" |
185 |
| - end |
186 |
| - |
187 |
| - unless ENV["SKIP_TAG"] || `git tag | grep '^#{tag}$'`.strip.empty? |
188 |
| - abort "[ABORTING] `git tag` shows that #{tag} already exists. Has this version already\n"\ |
189 |
| - " been released? Git tagging can be skipped by setting SKIP_TAG=1" |
190 |
| - end |
191 |
| - end |
192 |
| - |
193 |
| - task :bundle do |
194 |
| - sh "bundle check" |
195 |
| - end |
196 |
| - |
197 |
| - task :commit do |
198 |
| - unless `git status -s`.strip.empty? |
199 |
| - File.open("pkg/commit_message.txt", "w") do |f| |
200 |
| - f.puts "# Preparing for #{version} release\n" |
201 |
| - f.puts |
202 |
| - f.puts "# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT" |
203 |
| - end |
204 |
| - |
205 |
| - sh "git add . && git commit --verbose --template=pkg/commit_message.txt" |
206 |
| - rm_f "pkg/commit_message.txt" |
207 |
| - end |
208 |
| - end |
209 |
| - |
210 |
| - task :tag do |
211 |
| - sh "git push" |
212 |
| - sh "git tag -s -m '#{tag} release' #{tag}" |
213 |
| - sh "git push --tags" |
214 |
| - end |
215 |
| - |
216 |
| - task prep_release: %w(ensure_clean_state changelog:header build bundle) |
217 |
| - |
218 |
| - task release: %w(prep_release commit tag push) |
219 |
| -end |
| 7 | +releaser = Releaser.new(root, version) |
220 | 8 |
|
221 | 9 | module Announcement
|
222 | 10 | class Version
|
@@ -244,7 +32,7 @@ def rc?
|
244 | 32 |
|
245 | 33 | task :announce do
|
246 | 34 | Dir.chdir("pkg/") do
|
247 |
| - versions = ENV["VERSIONS"] ? ENV["VERSIONS"].split(",") : [ version ] |
| 35 | + versions = ENV["VERSIONS"] ? ENV["VERSIONS"].split(",") : [ releaser.version ] |
248 | 36 | versions = versions.sort.map { |v| Announcement::Version.new(v) }
|
249 | 37 |
|
250 | 38 | raise "Only valid for patch releases" if versions.any?(&:major_or_security?)
|
|
0 commit comments