Skip to content

Commit 47a9463

Browse files
justin808claude
andauthored
Improve release script OTP handling and retry logic (#2045)
## Summary - Add retry logic for gem publication with OTP failures - Add 5-second delay between gem publications to prevent OTP code reuse - Improve error messages with actionable guidance - Create ReleaseHelpers module to reduce code nesting ## Problem The release script was failing when publishing Ruby gems because OTP codes were being reused or expiring between NPM and RubyGems publications. The script would fail with "Your OTP code is incorrect" after successfully publishing NPM packages. ## Solution 1. **Retry logic**: Added up to 3 automatic retries for each gem publication with clear error messages 2. **OTP separation**: Added explicit 5-second delay between gem publications to prevent code reuse 3. **User guidance**: Added clear prompts reminding users to generate fresh OTP codes for each publication 4. **Code quality**: Created `ReleaseHelpers` module to reduce block nesting and improve maintainability ## Changes - Created `ReleaseHelpers.publish_gem_with_retry` helper method - Added retry logic for both `react_on_rails` and `react_on_rails_pro` gems - Added 5-second delay between gem publications - Improved error messages with actionable guidance - Maintained RuboCop compliance (no block nesting violations) ## Benefits - More robust release process that handles transient OTP failures - Clear user guidance on generating fresh OTP codes - Automatic retry on failure reduces manual intervention - Better separation between OTP-requiring operations ## Test Plan - [x] RuboCop passes - [x] Pre-commit hooks pass - [ ] Test next release to verify OTP handling improvements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7dfd90b commit 47a9463

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

rakelib/release.rake

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ class RaisingMessageHandler
1313
end
1414
end
1515

16+
# Helper module for release-specific tasks
17+
module ReleaseHelpers
18+
include ReactOnRails::TaskHelpers
19+
20+
# Publish a gem with retry logic for OTP failures
21+
def publish_gem_with_retry(dir, gem_name, max_retries: 3)
22+
puts "\nCarefully add your OTP for Rubygems when prompted."
23+
puts "NOTE: OTP codes expire quickly (typically 30 seconds). Generate a fresh code when prompted."
24+
25+
retry_count = 0
26+
success = false
27+
28+
while retry_count < max_retries && !success
29+
begin
30+
sh_in_dir(dir, "gem release")
31+
success = true
32+
rescue StandardError => e
33+
retry_count += 1
34+
if retry_count < max_retries
35+
puts "\n⚠️ #{gem_name} release failed (attempt #{retry_count}/#{max_retries})"
36+
puts "Common causes:"
37+
puts " - OTP code expired or already used"
38+
puts " - Network timeout"
39+
puts "\nGenerating a FRESH OTP code and retrying in 3 seconds..."
40+
sleep 3
41+
else
42+
puts "\n❌ Failed to publish #{gem_name} after #{max_retries} attempts"
43+
raise e
44+
end
45+
end
46+
end
47+
end
48+
module_function :publish_gem_with_retry
49+
end
50+
1651
# rubocop:disable Metrics/BlockLength
1752

1853
desc("Unified release script for all React on Rails packages and gems.
@@ -228,18 +263,21 @@ task :release, %i[version dry_run registry skip_push] do |_t, args|
228263
puts "Publishing PUBLIC Ruby gem..."
229264
puts "=" * 80
230265

231-
# Publish react_on_rails Ruby gem
232-
puts "\nCarefully add your OTP for Rubygems when prompted."
233-
sh_in_dir(gem_root, "gem release")
266+
# Publish react_on_rails Ruby gem with retry logic
267+
ReleaseHelpers.publish_gem_with_retry(gem_root, "react_on_rails")
268+
269+
# Add delay before next OTP operation to ensure clean separation
270+
puts "\n⏳ Waiting 5 seconds before next publication to ensure OTP separation..."
271+
sleep 5
234272

235273
puts "\n#{'=' * 80}"
236274
puts "Publishing PUBLIC Pro Ruby gem to RubyGems.org..."
237275
puts "=" * 80
238276

239-
# Publish react_on_rails_pro Ruby gem to RubyGems.org
277+
# Publish react_on_rails_pro Ruby gem to RubyGems.org with retry logic
240278
puts "\nPublishing react_on_rails_pro gem to RubyGems.org..."
241-
puts "Carefully add your OTP for Rubygems when prompted."
242-
sh_in_dir(pro_gem_root, "gem release")
279+
puts "NOTE: Generate a FRESH OTP code (different from the previous one)."
280+
ReleaseHelpers.publish_gem_with_retry(pro_gem_root, "react_on_rails_pro")
243281
end
244282
end
245283

0 commit comments

Comments
 (0)