Skip to content

Commit

Permalink
Fix release task now that NPM is part of the build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileencodes authored and tenderlove committed Aug 10, 2016
1 parent 8f544bc commit b5e140b
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions tasks/release.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,28 @@
raise "Could not insert PRE in #{file}" unless $1 raise "Could not insert PRE in #{file}" unless $1


File.open(file, 'w') { |f| f.write ruby } File.open(file, 'w') { |f| f.write ruby }
end

task gem => %w(update_versions pkg) do
cmd = ""
cmd << "cd #{framework} && " unless framework == "rails"
cmd << "bundle exec rake package && " unless framework == "rails"
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
sh cmd
end

task :build => [:clean, gem]
task :install => :build do
sh "gem install --pre #{gem}"
end

task :push => :build do
sh "gem push #{gem}"


# When running the release task we usually run build first to check that the gem works properly.
# NPM will refuse to publish or rebuild the gem if the version is changed when the Rails gem
# versions are changed. This then causes the gem push to fail. Because of this we need to update
# the version and publish at the same time.
if File.exist?("#{framework}/package.json") if File.exist?("#{framework}/package.json")
Dir.chdir("#{framework}") do Dir.chdir("#{framework}") do
# This "npm-ifies" the current version # This "npm-ifies" the current version
Expand All @@ -69,30 +90,13 @@
# Check if npm is installed, and raise an error if not # Check if npm is installed, and raise an error if not
if sh 'which npm' if sh 'which npm'
sh "npm version #{version} --no-git-tag-version" sh "npm version #{version} --no-git-tag-version"
sh "npm publish"
else else
raise 'You must have npm installed to release Rails.' raise 'You must have npm installed to release Rails.'
end end
end end
end end
end end

task gem => %w(update_versions pkg) do
cmd = ""
cmd << "cd #{framework} && " unless framework == "rails"
cmd << "bundle exec rake package && " unless framework == "rails"
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
sh cmd
end

task :build => [:clean, gem]
task :install => :build do
sh "gem install --pre #{gem}"
end

task :push => :build do
sh "gem push #{gem}"
sh "npm publish" if File.exist?("#{framework}/package.json")
end
end end
end end


Expand Down

0 comments on commit b5e140b

Please sign in to comment.