Skip to content

Commit aa8f788

Browse files
eileencodesrafaelfranca
authored andcommitted
Fix release task now that NPM is part of the build
Note: this commit looks super weird becuase git. I'm moving the entire NPM section to the part where we actually push the gems/npm package for the reasons below. That's not how the git diff looks though. When we release Rails we run `rake prep_release` which calls `update_versions`. This was updating the NPM version as well. But when we would later run `rake install` to test the installed gem `update_versions` gets called again which causes the install to fail because NPM sees the version is the same as the last run and refuses to continue. If you forget to stash this will then cause the push to RubyGems to fail because `update_versions` is called again and then NPM will not continue because it thinks the version hasn't been changed even though it has. The correct solution would be to not update the NPM verion if it matches the version already in the file but after an hour I could not find a simple way to use NPM to read the current version. Honestly that's not the best way to do it either because say you forget to update something else and then the script thinks it's already been updated. With that in mind I think the best solution is to not update the NPM version until right before we are going to push to NPM because then that won't cause the push to RubyGems to fail.
1 parent cbb6a26 commit aa8f788

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tasks/release.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,28 @@
4444
raise "Could not insert PRE in #{file}" unless $1
4545

4646
File.open(file, 'w') { |f| f.write ruby }
47+
end
48+
49+
task gem => %w(update_versions pkg) do
50+
cmd = ""
51+
cmd << "cd #{framework} && " unless framework == "rails"
52+
cmd << "bundle exec rake package && " unless framework == "rails"
53+
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
54+
sh cmd
55+
end
56+
57+
task :build => [:clean, gem]
58+
task :install => :build do
59+
sh "gem install --pre #{gem}"
60+
end
61+
62+
task :push => :build do
63+
sh "gem push #{gem}"
4764

65+
# When running the release task we usually run build first to check that the gem works properly.
66+
# NPM will refuse to publish or rebuild the gem if the version is changed when the Rails gem
67+
# versions are changed. This then causes the gem push to fail. Because of this we need to update
68+
# the version and publish at the same time.
4869
if File.exist?("#{framework}/package.json")
4970
Dir.chdir("#{framework}") do
5071
# This "npm-ifies" the current version
@@ -69,30 +90,13 @@
6990
# Check if npm is installed, and raise an error if not
7091
if sh 'which npm'
7192
sh "npm version #{version} --no-git-tag-version"
93+
sh "npm publish"
7294
else
7395
raise 'You must have npm installed to release Rails.'
7496
end
7597
end
7698
end
7799
end
78-
79-
task gem => %w(update_versions pkg) do
80-
cmd = ""
81-
cmd << "cd #{framework} && " unless framework == "rails"
82-
cmd << "bundle exec rake package && " unless framework == "rails"
83-
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
84-
sh cmd
85-
end
86-
87-
task :build => [:clean, gem]
88-
task :install => :build do
89-
sh "gem install --pre #{gem}"
90-
end
91-
92-
task :push => :build do
93-
sh "gem push #{gem}"
94-
sh "npm publish" if File.exist?("#{framework}/package.json")
95-
end
96100
end
97101
end
98102

0 commit comments

Comments
 (0)